Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions test/contract-admin-id/contractAdminId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*-
*
* Hedera Smart Contracts
*
* Copyright (C) 2024 Hedera Hashgraph, LLC
nadezhdapopovaa marked this conversation as resolved.
Show resolved Hide resolved
*
* 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');
quiet-node marked this conversation as resolved.
Show resolved Hide resolved
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;
});
nadezhdapopovaa marked this conversation as resolved.
Show resolved Hide resolved

it('should ensure that the admin key matches the contract ID after deploying a contract without finalizing a hollow address', async function () {
nadezhdapopovaa marked this conversation as resolved.
Show resolved Hide resolved
const factory = await ethers.getContractFactory(Constants.Contract.Base);
const contract = await factory.deploy();
const info = await utils.getContractInfo(contract.target, sdkClient);
nadezhdapopovaa marked this conversation as resolved.
Show resolved Hide resolved

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
Loading