Skip to content

Commit 514daf6

Browse files
authored
fix(tests): re-key token admin to KeyList{signer0,contracts} so mgmt admin-ops authorize under v2 (#140)
* fix(tests): re-key token admin to KeyList{signer0,contracts} so mgmt admin-ops authorize under v2 Signed-off-by: ValentinVPK <valentin.krumov@limechain.tech> * fix(tests): set explicit gas limit on HBAR-custom-fee NFT transfers Signed-off-by: ValentinVPK <valentin.krumov@limechain.tech> --------- Signed-off-by: ValentinVPK <valentin.krumov@limechain.tech>
1 parent 0e0a7f1 commit 514daf6

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

test/token-service/hapi.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class Hapi {
6969
async updateTokenKeys(
7070
tokenAddress,
7171
contractAddresses,
72-
// eslint-disable-next-line no-unused-vars -- kept for positional-arg compatibility with existing callers; the admin key is intentionally never re-keyed to a contract (a contract cannot sign to accept it, per HIP-540)
7372
setAdmin = true,
7473
setPause = true,
7574
setKyc = true,
@@ -89,21 +88,35 @@ class Hapi {
8988
// Under the v2 smart-contract security model, a contract may only use a token
9089
// key if that key IS a contract id (a `KeyList` of contract ids works — any
9190
// member is authorized). Hand the operational keys to the contracts directly.
92-
// NOTE: the admin key is intentionally NOT re-keyed here. Per HIP-540 the new
93-
// admin key must sign the update, and a contract cannot sign a HAPI
94-
// transaction, so admin can never be handed to a contract this way. It stays
95-
// with the operator; admin-gated ops through a contract (delete /
96-
// updateTokenInfo / updateExpiry / updateTokenKeys) are handled separately.
9791
const keyList = new KeyList(
9892
contractAddresses.map((address) =>
9993
ContractId.fromEvmAddress(0, 0, address),
10094
),
10195
1,
10296
);
10397

98+
// The admin key additionally includes signer0's public key. Per HIP-540 a
99+
// change to the admin key must be signed by the NEW admin key; a contract
100+
// cannot sign a HAPI transaction, so a contracts-only admin could never be
101+
// accepted. Because this KeyList is threshold-1 and signer0 is a member,
102+
// signer0's signature satisfies both the old admin (signer0) and the new one,
103+
// so the rotation is accepted — and any listed contract is then an authorized
104+
// admin for ops made through it (delete / updateTokenInfo / updateExpiry /
105+
// updateTokenKeys).
106+
const adminKeyList = new KeyList(
107+
[
108+
pkSigners[0].publicKey,
109+
...contractAddresses.map((address) =>
110+
ContractId.fromEvmAddress(0, 0, address),
111+
),
112+
],
113+
1,
114+
);
115+
104116
const tx = new TokenUpdateTransaction().setTokenId(
105117
TokenId.fromSolidityAddress(tokenAddress),
106118
);
119+
if (setAdmin) tx.setAdminKey(adminKeyList);
107120
if (setPause) tx.setPauseKey(keyList);
108121
if (setKyc) tx.setKycKey(keyList);
109122
if (setFreeze) tx.setFreezeKey(keyList);

test/token-service/token-managment/tokenManagmentContract.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,7 @@ describe('TokenManagmentContract Test Suite', function () {
25432543
signers[1].address,
25442544
signers[3].address,
25452545
nftTx,
2546+
Constants.GAS_LIMIT_1_000_000,
25462547
);
25472548
await transferNftToSigner3.wait();
25482549

@@ -2638,6 +2639,7 @@ describe('TokenManagmentContract Test Suite', function () {
26382639
signers[1].address,
26392640
signers[3].address,
26402641
nftTx,
2642+
Constants.GAS_LIMIT_1_000_000,
26412643
);
26422644
await transferNftToSigner3.wait();
26432645

@@ -2723,6 +2725,7 @@ describe('TokenManagmentContract Test Suite', function () {
27232725
signers[1].address,
27242726
signers[3].address,
27252727
nftTx,
2728+
Constants.GAS_LIMIT_1_000_000,
27262729
);
27272730
await transferNftToSigner3.wait();
27282731

0 commit comments

Comments
 (0)