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