Skip to content

Commit 6ed5ae9

Browse files
committed
fix(tests): contract-keyed airdrop sender for HIP904 Batch1
Signed-off-by: ValentinVPK <valentin.krumov@limechain.tech>
1 parent d89bb3e commit 6ed5ae9

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ defaults:
3030
shell: bash
3131

3232
jobs:
33-
HRC:
34-
name: HRC Test Suite
33+
HIP904Batch1:
34+
name: HIP904 Contract Test Suite Batch 1
3535
uses: ./.github/workflows/test-workflow.yml
3636
with:
37-
testfilter: HRC
37+
testfilter: HIP904Batch1

test/token-service/hrc-904/AirdropContract.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('HIP904Batch1 AirdropContract Test Suite', function () {
1616
let nftTokenAddress;
1717
let signers;
1818
let owner;
19+
let emptySender;
1920
let accounts;
2021
let contractAddresses;
2122
let walletIHRC904AccountFacade;
@@ -32,14 +33,27 @@ describe('HIP904Batch1 AirdropContract Test Suite', function () {
3233
erc721Contract = await utils.deployContract(
3334
Constants.Contract.ERC721Contract,
3435
);
35-
owner = signers[0].address;
3636
accounts = signers.slice(1, 3).map((s) => s.address);
3737

3838
contractAddresses = [
3939
await airdropContract.getAddress(),
4040
await tokenCreateContract.getAddress(),
4141
];
42-
await hapi.updateAccountKeys(contractAddresses);
42+
43+
// Relay model: no account re-keying. The Airdrop contract debits the sender
44+
// and leaves isApproval false, so the sender's key has to include the
45+
// contract — which a hardhat signer cannot have while it still sends
46+
// EthereumTransactions. The airdrop sender is therefore a contract-keyed
47+
// account that only ever acts as a subject (signers[0] still sends every
48+
// transaction), and it is the treasury of every token created below, so it
49+
// holds the supply without any seeding transfer.
50+
owner = (await hapi.createAccountWithContractIdKey(contractAddresses))
51+
.address;
52+
// A second contract-keyed account, associated but holding nothing, so the
53+
// insufficient-balance test fails on the balance rather than on
54+
// authorization or a missing association.
55+
emptySender = (await hapi.createAccountWithContractIdKey(contractAddresses))
56+
.address;
4357

4458
tokenAddress = await utils.setupToken(
4559
tokenCreateContract,
@@ -53,6 +67,13 @@ describe('HIP904Batch1 AirdropContract Test Suite', function () {
5367
contractAddresses,
5468
hapi,
5569
);
70+
await (
71+
await tokenCreateContract.associateTokenPublic(
72+
emptySender,
73+
tokenAddress,
74+
Constants.GAS_LIMIT_1_000_000,
75+
)
76+
).wait();
5677
});
5778

5879
after(function () {
@@ -76,7 +97,7 @@ describe('HIP904Batch1 AirdropContract Test Suite', function () {
7697

7798
const tx = await airdropContract.tokenAirdrop(
7899
tokenAddress,
79-
signers[0].address,
100+
owner,
80101
receiver,
81102
ftAmount,
82103
Constants.GAS_LIMIT_2_000_000,
@@ -303,7 +324,7 @@ describe('HIP904Batch1 AirdropContract Test Suite', function () {
303324

304325
const tx = await airdropContract.tokenAirdrop(
305326
tokenAddress,
306-
signers[2].address,
327+
emptySender,
307328
receiver,
308329
ftAmount,
309330
Constants.GAS_LIMIT_2_000_000,
@@ -350,7 +371,7 @@ describe('HIP904Batch1 AirdropContract Test Suite', function () {
350371

351372
const tx = await airdropContract.tokenAirdrop(
352373
tokenAddress,
353-
signers[0].address,
374+
owner,
354375
receiver,
355376
invalidAmount,
356377
Constants.GAS_LIMIT_2_000_000,
@@ -439,7 +460,7 @@ describe('HIP904Batch1 AirdropContract Test Suite', function () {
439460

440461
const tx = await airdropContract.tokenAirdrop(
441462
tokenAddress,
442-
signers[0].address,
463+
owner,
443464
receiver.address,
444465
ftAmount,
445466
{

test/token-service/utils.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,17 @@ class Utils {
657657
* Reads a system contract's response code out of a transaction's mirror node
658658
* action tree.
659659
*
660-
* The action addressed to the system contract is identified by entity id
661-
* (`recipient`) OR by EVM address (`to`) — the entity-id form alone stopped
662-
* matching on consensus v0.77 / mirror v0.161. If neither shape is present,
663-
* fall back to the innermost action, which is where a facade/redirect call
664-
* leaves its response code, and say so in the log: the expected codes the
665-
* callers assert on (22 / 178 / 196 / 354 / 367) are precise enough that a
666-
* wrong pick fails the assertion rather than passing silently.
660+
* Two shapes are both normal, depending on how the precompile was reached:
661+
* - through a contract: the tree has a child action addressed to the system
662+
* contract, matched here by entity id (`recipient`) or EVM address (`to`).
663+
* - directly through a token/account facade (IHRC719, IHRC904, IHRC906): on
664+
* consensus v0.77 there is no child action for the system contract at all.
665+
* The single depth-0 action — whose recipient is the token itself, or null
666+
* for an account facade — carries the response code.
667+
* So fall through to the innermost action carrying result_data. For the
668+
* contract case that is the same system-contract action the match found, and
669+
* the exact codes callers assert on (22 / 178 / 196 / 354 / 367) mean a wrong
670+
* pick fails the assertion rather than passing silently.
667671
*
668672
* @param {string} txHash - The transaction hash to query.
669673
* @param {string} entityId - System contract entity id, e.g. '0.0.359'.
@@ -699,9 +703,6 @@ class Utils {
699703
`No action carrying result_data for ${txHash}; actions=${JSON.stringify(actions)}`,
700704
);
701705
}
702-
console.log(
703-
`[actions] no ${entityId} action for ${txHash}; falling back to depth ${innermost.call_depth} recipient=${innermost.recipient} to=${innermost.to}`,
704-
);
705706
return BigInt(innermost.result_data).toString();
706707
}
707708

0 commit comments

Comments
 (0)