Skip to content

Commit b757bf3

Browse files
committed
unit test for ignition deployment module GifCore (#364)
1 parent 3f6ae4e commit b757bf3

File tree

3 files changed

+91
-8
lines changed

3 files changed

+91
-8
lines changed

hardhat.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const config: HardhatUserConfig = {
1616
}
1717
}
1818
},
19+
"paths": {
20+
"tests": "./test_hardhat",
21+
},
1922
solidity: {
2023
version: "0.8.20",
2124
settings: {

ignition/modules/GifCore.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ export default buildModule("GifCore", (m) => {
138138
});
139139

140140
return {
141-
dip,
142-
registryAdmin,
143-
registry,
144-
releaseManager,
145-
stakingManager,
146-
stakingStore,
147-
stakingReader,
148-
tokenRegistry,
141+
dipContract: dip,
142+
registryAdminContract: registryAdmin,
143+
registryContract: registry,
144+
releaseManagerContract: releaseManager,
145+
stakingManagerContract: stakingManager,
146+
stakingStoreContract: stakingStore,
147+
stakingReaderContract: stakingReader,
148+
tokenRegistryContract: tokenRegistry,
149149
};
150150
});

test_hardhat/deployment.test.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { expect } from "chai";
2+
import hre, { ignition } from "hardhat";
3+
import GifCore from "../ignition/modules/GifCore";
4+
import { Registry, StakingManager, StakingReader, TokenRegistry } from "../typechain-types";
5+
6+
describe("Ignition deployment", function () {
7+
it("deploys all contracts", async function () {
8+
const {
9+
dipContract,
10+
registryAdminContract,
11+
registryContract,
12+
releaseManagerContract,
13+
stakingManagerContract,
14+
stakingStoreContract,
15+
stakingReaderContract,
16+
tokenRegistryContract,
17+
} = await ignition.deploy(GifCore);
18+
19+
expect(await dipContract.getAddress()).to.be.properAddress;
20+
expect(await registryAdminContract.getAddress()).to.be.properAddress;
21+
expect(await registryContract.getAddress()).to.be.properAddress;
22+
expect(await releaseManagerContract.getAddress()).to.be.properAddress;
23+
expect(await stakingManagerContract.getAddress()).to.be.properAddress;
24+
expect(await stakingStoreContract.getAddress()).to.be.properAddress;
25+
expect(await stakingReaderContract.getAddress()).to.be.properAddress;
26+
expect(await tokenRegistryContract.getAddress()).to.be.properAddress;
27+
28+
// check that the dip token address is set correctly in the token registry
29+
const tokenRegistry = tokenRegistryContract as unknown as TokenRegistry;
30+
expect(await tokenRegistry.getDipTokenAddress()).to.equal(await dipContract.getAddress());
31+
32+
const stakingManager = stakingManagerContract as unknown as StakingManager;
33+
const stakingAddress = await stakingManager.getStaking();
34+
35+
// check that staking reader has the correct addresses of registry and staking
36+
const stakingReader = stakingReaderContract as unknown as StakingReader;
37+
expect(await stakingReader.getRegistry()).to.equal(await registryContract.getAddress());
38+
expect(await stakingReader.getStaking()).to.equal(stakingAddress);
39+
40+
// check that the registry has the correct number of objects (4 - protocol, global registry, registry, staking)
41+
const registry = registryContract as unknown as Registry;
42+
expect(await registry.getObjectCount()).to.equal(4, "registry should have 4 objects");
43+
44+
45+
const protocolNftId = "1101";
46+
const globalRegistryNftId = "2101";
47+
48+
// check that the registry has the correct nftid (2nd nft)
49+
const registryNftId = calculateNftID(2);
50+
expect(await registry["getNftId()"]()).to.equal(registryNftId, "registry nftid invalid");
51+
expect(await registry.getProtocolNftId()).to.equal(protocolNftId, "protocol nftid invalid");
52+
await expectParentNftId(registry, registryNftId, globalRegistryNftId);
53+
54+
// check that the staking contract has the correct registry and nftid (3rd nft)
55+
const staking = await hre.ethers.getContractAt("Staking", stakingAddress);
56+
expect(await staking.getRegistry()).to.equal(await registryContract.getAddress());
57+
const stakingNftId = calculateNftID(3);
58+
expect(await staking.getNftId()).to.equal(stakingNftId, "staking nftid invalid");
59+
expectParentNftId(registry, stakingNftId, registryNftId);
60+
61+
// check that the registry contains an entry for the global registry (nft id 2101) with address 0x and its parent is the protocol nft id
62+
const { objectAddress, parentNftId } = await registry["getObjectInfo(uint96)"](globalRegistryNftId);
63+
expect(objectAddress).to.equal("0x0000000000000000000000000000000000000000");
64+
expect(parentNftId).to.equal(protocolNftId);
65+
66+
// check that the parent nft id of the protocol nft id is 0
67+
await expectParentNftId(registry, protocolNftId, "0");
68+
});
69+
});
70+
71+
function calculateNftID(nftNum: number): string {
72+
const chainId = hre.network.config.chainId || 1;
73+
const chainIdLength = chainId.toString().length.toString().padStart(2, "0");
74+
return `${nftNum}${chainId}${chainIdLength}`;
75+
}
76+
77+
async function expectParentNftId(registry: Registry, nftId: string, expectedParentNftId: string) {
78+
const { parentNftId: registryParentNftId } = await registry["getObjectInfo(uint96)"](nftId);
79+
expect(registryParentNftId).to.equal(expectedParentNftId, "parent nftid invalid");
80+
}

0 commit comments

Comments
 (0)