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 (#1142)

* test: validate contract and admin key in hollow account finalized as contract

Signed-off-by: Nadezhda Popova <nadezhda.popova@limechain.tech>

* fixup! test: validate contract and admin key in hollow account finalized as contract

Signed-off-by: Nadezhda Popova <nadezhda.popova@limechain.tech>

* test: validate contract and admin key after deploying a contract  without finalizing a hollow account

Signed-off-by: Nadezhda Popova <nadezhda.popova@limechain.tech>

* fixup! test: validate contract and admin key after deploying a contract  without finalizing a hollow account

Signed-off-by: Nadezhda Popova <nadezhda.popova@limechain.tech>

* fixup! fixup! test: validate contract and admin key after deploying a contract  without finalizing a hollow account

Signed-off-by: Nadezhda Popova <nadezhda.popova@limechain.tech>

---------

Signed-off-by: Nadezhda Popova <nadezhda.popova@limechain.tech>
  • Loading branch information
nadezhdapopovaa authored Jan 17, 2025
1 parent 1714458 commit 74c78d1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/contract-admin-id/contractAdminId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*-
*
* Hedera Smart Contracts
*
* 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.
* 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');
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;
});

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;
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 74c78d1

Please sign in to comment.