Skip to content

Commit

Permalink
test: validate contract and admin key in hollow account finalized as …
Browse files Browse the repository at this point in the history
…contract

Signed-off-by: Nadezhda Popova <[email protected]>
  • Loading branch information
nadezhdapopovaa committed Jan 6, 2025
1 parent 31f983b commit e7a23d2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/contract-admin-id/contractAdminId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { expect } = require('chai');
const { ethers } = require('hardhat');
const utils = require('../system-contracts/hedera-token-service/utils');
const Constants = require('../constants');

describe('Admin Key and Contract ID Validation', function () {
let signers;
let sdkClient;
let hollowWallet;

before(async function () {
signers = await ethers.getSigners();
sdkClient = await utils.createSDKClient();
hollowWallet = ethers.Wallet.createRandom().connect(ethers.provider);

await (
await signers[0].sendTransaction({
to: hollowWallet.address,
value: ethers.parseEther('100'),
gasLimit: 1_000_000,
})
).wait();
});

it('should ensure that the admin key matches the contract ID after deploying the contract with the hollow account', async function () {
const factory = await ethers.getContractFactory(
Constants.Contract.Base,
hollowWallet
);
const contract = await factory.deploy();
const info = await utils.getContractInfo(contract.target, sdkClient);

const adminkey = info.adminKey.num;
const contractId = info.contractId.num;

expect(adminkey.equals(contractId)).to.be.true;
});
});
9 changes: 9 additions & 0 deletions test/system-contracts/hedera-token-service/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
TokenUpdateTransaction,
TokenAssociateTransaction,
AccountBalanceQuery,
ContractInfoQuery,
} = require('@hashgraph/sdk');
const Constants = require('../../constants');

Expand Down Expand Up @@ -716,6 +717,14 @@ class Utils {
return await query.execute(client);
}

static async getContractInfo(evmAddress, client) {
const query = new ContractInfoQuery().setContractId(
ContractId.fromEvmAddress(0, 0, evmAddress)
);

return await query.execute(client);
}

static getSignerCompressedPublicKey(
index = 0,
asBuffer = true,
Expand Down

0 comments on commit e7a23d2

Please sign in to comment.