Skip to content

Commit

Permalink
feat: Adds tests that verify IHRC904 airdropToken targeted to an EOA …
Browse files Browse the repository at this point in the history
…are functional when called by a contract (#1185)

* feat: added test coverage of Airdrop.sol with requested fixes from previous PR

Signed-off-by: Simeon Nakov <[email protected]>

* feat: requested changes for Airdrop tokens test coverage

Signed-off-by: Simeon Nakov <[email protected]>

* feat: recompiled contract

Signed-off-by: Simeon Nakov <[email protected]>

* skipped tests temporarily

Signed-off-by: Simeon Nakov <[email protected]>

* requested changes from PR

Signed-off-by: Simeon Nakov <[email protected]>

* fix conflicts

Signed-off-by: Simeon Nakov <[email protected]>

---------

Signed-off-by: Simeon Nakov <[email protected]>
  • Loading branch information
simzzz authored Feb 4, 2025
1 parent 96941f6 commit 6e09c81
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 40 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 @@ -168,17 +168,16 @@ contract Airdrop is HederaTokenService {
// @param token The NFT token address
// @param sender The address sending the NFTs
// @param receivers Array of addresses to receive the NFTs
// @param serials Array of serial numbers to assign to each receiver
// @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
4 changes: 4 additions & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ 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 @@ -229,6 +230,7 @@ const DAY = 24 * HOUR;
const WEEK = 7 * DAY;
const GWEI = 1e9;
const HTS_SYSTEM_CONTRACT_ID = '0.0.359';
const HAS_SYSTEM_CONTRACT_ID = '0.0.362';

module.exports = {
Events,
Expand All @@ -238,6 +240,7 @@ module.exports = {
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 @@ -253,5 +256,6 @@ module.exports = {
WEI,
GWEI,
HTS_SYSTEM_CONTRACT_ID,
HAS_SYSTEM_CONTRACT_ID,
ONE_HBAR,
};
Loading

0 comments on commit 6e09c81

Please sign in to comment.