Skip to content

Commit

Permalink
feat: added test coverage of Airdrop.sol with requested fixes from pr…
Browse files Browse the repository at this point in the history
…evious PR

Signed-off-by: Simeon Nakov <[email protected]>
  • Loading branch information
simzzz committed Jan 17, 2025
1 parent 74c78d1 commit 0835531
Show file tree
Hide file tree
Showing 19 changed files with 2,219 additions and 773 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@
"internalType": "address[]",
"name": "receivers",
"type": "address[]"
},
{
"internalType": "int64[]",
"name": "serials",
"type": "int64[]"
}
],
"name": "nftAirdropDistribute",
Expand Down
4 changes: 4 additions & 0 deletions contracts/system-contracts/hedera-token-service/IHRC904.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ interface IHRC904 is IHTSStructs {
/// @notice - As a pending airdrop requiring claim if they have no available auto-association slots
/// @notice Immediate airdrops are irreversible, pending airdrops can be canceled
/// @notice All transfer fees and auto-renewal rent costs are charged to the transaction submitter
/// @notice The tokenTransfers array is limited to a maximum of 10 elements by default, managed by tokens.maxAllowedAirdropTransfersPerTx configuration
/// @param tokenTransfers Array of token transfer lists containing token addresses and recipient details
/// @return responseCode The response code for the status of the request. SUCCESS is 22.
function airdropTokens(TokenTransferList[] memory tokenTransfers) external returns (int64 responseCode);

/// @notice Cancels pending airdrops that have not yet been claimed
/// @notice The pendingAirdrops array is limited to a maximum of 10 elements by default, managed by tokens.maxAllowedPendingAirdropsToCancel configuration
/// @param pendingAirdrops Array of pending airdrops to cancel
/// @return responseCode The response code for the status of the request. SUCCESS is 22.
function cancelAirdrops(PendingAirdrop[] memory pendingAirdrops) external returns (int64 responseCode);

/// @notice Claims pending airdrops that were sent to the calling account
/// @notice The pendingAirdrops array is limited to a maximum of 10 elements by default, managed by tokens.maxAllowedPendingAirdropsToClaim configuration
/// @param pendingAirdrops Array of pending airdrops to claim
/// @return responseCode The response code for the status of the request. SUCCESS is 22.
function claimAirdrops(PendingAirdrop[] memory pendingAirdrops) external returns (int64 responseCode);
Expand All @@ -30,6 +33,7 @@ interface IHRC904 is IHTSStructs {
/// @notice This transfer does not charge any custom fees or royalties defined for the tokens
/// @notice For fungible tokens, the requesting account's balance will become 0 and the treasury balance will increase by that amount
/// @notice For non-fungible tokens, the requesting account will no longer hold the rejected serial numbers and they will be transferred to the treasury
/// @notice The ftAddresses and nftIDs arrays are limited to a combined maximum of 10 elements by default, managed by ledger.tokenRejects.maxLen configuration
/// @param rejectingAddress The address rejecting the tokens
/// @param ftAddresses Array of fungible token addresses to reject
/// @param nftIDs Array of NFT IDs to reject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,14 @@ contract Airdrop is HederaTokenService {
// @param sender The address sending the NFTs
// @param receivers Array of addresses to receive the NFTs
// @return responseCode The response code from the airdrop operation (22 = success)
function nftAirdropDistribute(address token, address sender, address[] memory receivers) public payable returns (int64 responseCode) {
function nftAirdropDistribute(address token, address sender, address[] memory receivers, int64[] memory serials) public payable returns (int64 responseCode) {
uint256 length = receivers.length;
IHederaTokenService.TokenTransferList[] memory tokenTransfers = new IHederaTokenService.TokenTransferList[](1);
IHederaTokenService.TokenTransferList memory airdrop;
airdrop.token = token;
IHederaTokenService.NftTransfer[] memory nftTransfers = new IHederaTokenService.NftTransfer[](length);
int64 serial = 1;
for (uint i = 0; i < length; i++) {
nftTransfers[i] = prepareNftTransfer(sender, receivers[i], serial);
serial++;
nftTransfers[i] = prepareNftTransfer(sender, receivers[i], serials[i]);
}
airdrop.nftTransfers = nftTransfers;
tokenTransfers[0] = airdrop;
Expand Down
9 changes: 9 additions & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,14 @@ const Contract = {
CancunOpcodes: 'CancunOpcodes',
KZGPointEvaluation: 'KZGPointEvaluation',
StateRegistry: 'StateRegistry',
Airdrop: 'Airdrop',
};

const CALL_EXCEPTION = 'CALL_EXCEPTION';
const CONTRACT_REVERT_EXECUTED_CODE = 3;
const GAS_LIMIT_1_000_000 = { gasLimit: 1_000_000 };
const GAS_LIMIT_2_000_000 = { gasLimit: 2_000_000 };
const GAS_LIMIT_5_000_000 = { gasLimit: 5_000_000 };
const GAS_LIMIT_10_000_000 = { gasLimit: 10_000_000 };
const GAS_LIMIT_800000 = { gasLimit: 800000 };
const GAS_LIMIT_8000000 = { gasLimit: 8000000 };
Expand All @@ -222,6 +225,8 @@ const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const WEEK = 7 * DAY;
const GWEI = 1e9;
const HTS_SYSTEM_CONTRACT_ADDRESS = '0.0.359';
const HAS_SYSTEM_CONTRACT_ADDRESS = '0.0.362';

module.exports = {
Events,
Expand All @@ -230,6 +235,8 @@ module.exports = {
CALL_EXCEPTION,
CONTRACT_REVERT_EXECUTED_CODE,
GAS_LIMIT_1_000_000,
GAS_LIMIT_2_000_000,
GAS_LIMIT_5_000_000,
GAS_LIMIT_10_000_000,
GAS_LIMIT_800000,
GAS_LIMIT_8000000,
Expand All @@ -244,4 +251,6 @@ module.exports = {
WEEK,
WEI,
GWEI,
HTS_SYSTEM_CONTRACT_ADDRESS,
HAS_SYSTEM_CONTRACT_ADDRESS,
};
38 changes: 27 additions & 11 deletions test/hip-583/HIP583.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ describe('HIP583 Test Suite', function () {

before(async function () {
signers = await ethers.getSigners();
tokenCreateContract = await utils.deployTokenCreateContract();
tokenTransferContract = await utils.deployTokenTransferContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
tokenTransferContract = await utils.deployContract(
Constants.Contract.TokenTransferContract
);
await utils.updateAccountKeysViaHapi([
await tokenCreateContract.getAddress(),
await tokenTransferContract.getAddress(),
]);
erc20Contract = await utils.deployERC20Contract();
erc721Contract = await utils.deployERC721Contract();
erc20Contract = await utils.deployContract(
Constants.Contract.ERC20Contract
);
erc721Contract = await utils.deployContract(
Constants.Contract.ERC721Contract
);
tokenAddress =
await utils.createFungibleTokenWithSECP256K1AdminKeyWithoutKYC(
tokenCreateContract,
Expand Down Expand Up @@ -587,7 +595,7 @@ describe('HIP583 Test Suite - Contract Transfer TX', function () {
)
).wait();

erc20Mock = await utils.deployERC20Mock();
erc20Mock = await utils.deployContract(Constants.Contract.ERC20Contract);
await erc20Mock.mint(await contractTransferTx.getAddress(), 1000);
});

Expand Down Expand Up @@ -664,7 +672,7 @@ describe('HIP583 Test Suite - Contract Transfer TX', function () {
)
).wait();

erc721Mock = await utils.deployERC721Mock();
erc721Mock = await utils.deployContract(Constants.Contract.ERC20Contract);
await erc721Mock.mint(await contractTransferTx.getAddress(), tokenId);
});

Expand Down Expand Up @@ -756,16 +764,24 @@ describe('HIP583 Test Suite - Ethereum Transfer TX via system-contracts', functi

before(async function () {
signers = await ethers.getSigners();
tokenCreateContract = await utils.deployTokenCreateContract();
tokenQueryContract = await utils.deployTokenQueryContract();
tokenTransferContract = await utils.deployTokenTransferContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
tokenQueryContract = await utils.deployContract(
Constants.Contract.TokenQueryContract
);
tokenTransferContract = await utils.deployContract(
Constants.Contract.TokenTransferContract
);
await utils.updateAccountKeysViaHapi([
await tokenCreateContract.getAddress(),
await tokenQueryContract.getAddress(),
await tokenTransferContract.getAddress(),
]);
erc20Contract = await utils.deployERC20Contract();
erc721Contract = await utils.deployERC721Contract();
erc20Contract = await utils.deployContract(Constants.Path.HIP583_ERC20Mock);
erc721Contract = await utils.deployContract(
Constants.Contract.ERC721Contract
);
});

const bootstrapHollowAccount = async function (
Expand Down
8 changes: 6 additions & 2 deletions test/openzeppelin/proxy-upgrade/proxyUpgradeContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ describe('Proxy Upgrade Contracts Test Suite', function () {
let exchangeTokenBalance;

before(async function () {
tokenCreateContract = await utils.deployTokenCreateContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
await utils.updateAccountKeysViaHapi([
await tokenCreateContract.getAddress(),
]);
Expand All @@ -53,7 +55,9 @@ describe('Proxy Upgrade Contracts Test Suite', function () {
await tokenCreateContract.getAddress(),
]);

erc20Contract = await utils.deployERC20Contract();
erc20Contract = await utils.deployContract(
Constants.Contract.ERC20Contract
);
proxyContract = await deployDEXProxyContract(tokenAddress);
proxyAddress = await proxyContract.getAddress();

Expand Down
16 changes: 12 additions & 4 deletions test/system-contracts/hedera-token-service/atomic-hts/atomicHTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ describe('AtomicHTS - HIP#551: Batch Transactions Test Suite', () => {
signers = await ethers.getSigners();
accountA = signers[0].address;
accountB = signers[1].address;
tokenCreateContract = await utils.deployTokenCreateContract();
tokenTransferContract = await utils.deployTokenTransferContract();
tokenManagmentContract = await utils.deployTokenManagementContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
tokenTransferContract = await utils.deployContract(
Constants.Contract.TokenTransferContract
);
tokenManagmentContract = await utils.deployContract(
Constants.Contract.TokenManagementContract
);

const atomicContractFactory = await ethers.getContractFactory(
Constants.Contract.AtomicHTS
Expand Down Expand Up @@ -73,7 +79,9 @@ describe('AtomicHTS - HIP#551: Batch Transactions Test Suite', () => {
await tokenTransferContract.getAddress(),
]);

erc20Contract = await utils.deployERC20Contract();
erc20Contract = await utils.deployContract(
Constants.Contract.ERC20Contract
);

await utils.associateToken(
tokenCreateContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ describe('ERC20Contract Test Suite', function () {

before(async function () {
signers = await ethers.getSigners();
tokenCreateContract = await utils.deployTokenCreateContract();
tokenTransferContract = await utils.deployTokenTransferContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
tokenTransferContract = await utils.deployContract(
Constants.Contract.TokenTransferContract
);
await utils.updateAccountKeysViaHapi([
await tokenCreateContract.getAddress(),
await tokenTransferContract.getAddress(),
]);
erc20Contract = await utils.deployERC20Contract();
erc20Contract = await utils.deployContract(
Constants.Contract.ERC20Contract
);
tokenAddress = await utils.createFungibleToken(
tokenCreateContract,
signers[0].address
Expand Down
8 changes: 6 additions & 2 deletions test/system-contracts/hedera-token-service/erc-20/IERC20.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ describe('IERC20 Test Suite', function () {

before(async function () {
signers = await ethers.getSigners();
tokenCreateContract = await utils.deployTokenCreateContract();
tokenTransferContract = await utils.deployTokenTransferContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
tokenTransferContract = await utils.deployContract(
Constants.Contract.TokenTransferContract
);
await utils.updateAccountKeysViaHapi([
await tokenCreateContract.getAddress(),
await tokenTransferContract.getAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ describe('ERC721Contract Test Suite', function () {

before(async function () {
signers = await ethers.getSigners();
tokenCreateContract = await utils.deployTokenCreateContract();
tokenTransferContract = await utils.deployTokenTransferContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
tokenTransferContract = await utils.deployContract(
Constants.Contract.TokenTransferContract
);
await utils.updateAccountKeysViaHapi([
await tokenCreateContract.getAddress(),
await tokenTransferContract.getAddress(),
]);
erc721Contract = await utils.deployERC721Contract();
erc721Contract = await utils.deployContract(
Constants.Contract.ERC721Contract
);
tokenAddress = await utils.createNonFungibleToken(
tokenCreateContract,
signers[0].address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ describe('@HRC-719 Test Suite', function () {

before(async function () {
signers = await ethers.getSigners();
tokenCreateContract = await utils.deployTokenCreateContract();
tokenCreateContract = await utils.deployContract(
Constants.Contract.TokenCreateContract
);
await utils.updateAccountKeysViaHapi([
await tokenCreateContract.getAddress(),
]);

hrc719Contract = await utils.deployHRC719Contract();
hrc719Contract = await utils.deployContract(
Constants.Contract.HRC719Contract
);

IHRC719 = new ethers.Interface(
(await hre.artifacts.readArtifact('IHRC719')).abi
Expand Down
Loading

0 comments on commit 0835531

Please sign in to comment.