From e7a23d281be23c12e5134dccda8d833a45654d0e Mon Sep 17 00:00:00 2001 From: Nadezhda Popova Date: Mon, 6 Jan 2025 18:46:30 +0200 Subject: [PATCH 1/5] test: validate contract and admin key in hollow account finalized as contract Signed-off-by: Nadezhda Popova --- test/contract-admin-id/contractAdminId.js | 38 +++++++++++++++++++ .../hedera-token-service/utils.js | 9 +++++ 2 files changed, 47 insertions(+) create mode 100644 test/contract-admin-id/contractAdminId.js diff --git a/test/contract-admin-id/contractAdminId.js b/test/contract-admin-id/contractAdminId.js new file mode 100644 index 000000000..517cc6e70 --- /dev/null +++ b/test/contract-admin-id/contractAdminId.js @@ -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; + }); +}); diff --git a/test/system-contracts/hedera-token-service/utils.js b/test/system-contracts/hedera-token-service/utils.js index 415472d52..e20b11a6b 100644 --- a/test/system-contracts/hedera-token-service/utils.js +++ b/test/system-contracts/hedera-token-service/utils.js @@ -33,6 +33,7 @@ const { TokenUpdateTransaction, TokenAssociateTransaction, AccountBalanceQuery, + ContractInfoQuery, } = require('@hashgraph/sdk'); const Constants = require('../../constants'); @@ -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, From 2aca0d35a2a3f913f61ceeea97d5e4890141166f Mon Sep 17 00:00:00 2001 From: Nadezhda Popova Date: Mon, 6 Jan 2025 19:00:28 +0200 Subject: [PATCH 2/5] fixup! test: validate contract and admin key in hollow account finalized as contract Signed-off-by: Nadezhda Popova --- test/contract-admin-id/contractAdminId.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/contract-admin-id/contractAdminId.js b/test/contract-admin-id/contractAdminId.js index 517cc6e70..a287cd17a 100644 --- a/test/contract-admin-id/contractAdminId.js +++ b/test/contract-admin-id/contractAdminId.js @@ -1,3 +1,23 @@ +/*- + * + * Hedera Smart Contracts + * + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + const { expect } = require('chai'); const { ethers } = require('hardhat'); const utils = require('../system-contracts/hedera-token-service/utils'); From 8ca1db06db0cb4109a2a031a427d245fe03229eb Mon Sep 17 00:00:00 2001 From: Nadezhda Popova Date: Thu, 16 Jan 2025 14:59:36 +0200 Subject: [PATCH 3/5] test: validate contract and admin key after deploying a contract without finalizing a hollow account Signed-off-by: Nadezhda Popova --- test/contract-admin-id/contractAdminId.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/contract-admin-id/contractAdminId.js b/test/contract-admin-id/contractAdminId.js index a287cd17a..67c2f17cf 100644 --- a/test/contract-admin-id/contractAdminId.js +++ b/test/contract-admin-id/contractAdminId.js @@ -55,4 +55,15 @@ describe('Admin Key and Contract ID Validation', function () { expect(adminkey.equals(contractId)).to.be.true; }); + + it('should ensure that the admin key matches the contract ID after deploying a contract without finalizing a hollow address', async function () { + const factory = await ethers.getContractFactory(Constants.Contract.Base); + 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; + }); }); From 5c61085927c3f4005fccb414aeef37e23af8bcae Mon Sep 17 00:00:00 2001 From: Nadezhda Popova Date: Thu, 16 Jan 2025 17:23:08 +0200 Subject: [PATCH 4/5] fixup! test: validate contract and admin key after deploying a contract without finalizing a hollow account Signed-off-by: Nadezhda Popova --- test/contract-admin-id/contractAdminId.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/contract-admin-id/contractAdminId.js b/test/contract-admin-id/contractAdminId.js index 67c2f17cf..a7e44a3b5 100644 --- a/test/contract-admin-id/contractAdminId.js +++ b/test/contract-admin-id/contractAdminId.js @@ -2,7 +2,7 @@ * * Hedera Smart Contracts * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2025 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ describe('Admin Key and Contract ID Validation', function () { expect(adminkey.equals(contractId)).to.be.true; }); - it('should ensure that the admin key matches the contract ID after deploying a contract without finalizing a hollow address', async function () { + it('should ensure that the admin key matches the contract ID after deploying a contract', async function () { const factory = await ethers.getContractFactory(Constants.Contract.Base); const contract = await factory.deploy(); const info = await utils.getContractInfo(contract.target, sdkClient); From 626ee160833c90e28285a3fcdfac097de2d7b140 Mon Sep 17 00:00:00 2001 From: Nadezhda Popova Date: Thu, 16 Jan 2025 18:02:53 +0200 Subject: [PATCH 5/5] fixup! fixup! test: validate contract and admin key after deploying a contract without finalizing a hollow account Signed-off-by: Nadezhda Popova --- test/contract-admin-id/contractAdminId.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/contract-admin-id/contractAdminId.js b/test/contract-admin-id/contractAdminId.js index a7e44a3b5..2062dd9ce 100644 --- a/test/contract-admin-id/contractAdminId.js +++ b/test/contract-admin-id/contractAdminId.js @@ -59,6 +59,9 @@ describe('Admin Key and Contract ID Validation', function () { it('should ensure that the admin key matches the contract ID after deploying a contract', async function () { const factory = await ethers.getContractFactory(Constants.Contract.Base); const contract = await factory.deploy(); + + await contract.waitForDeployment(); + const info = await utils.getContractInfo(contract.target, sdkClient); const adminkey = info.adminKey.num;