@@ -13,7 +13,12 @@ contract SimpleContract {
1313 }
1414}
1515
16- contract ChainwebPluginTest is ChainwebTest (2 , 0 ) {
16+ contract ChainwebContractTest is Test {
17+ Chainweb public chainweb;
18+ function setUp () public {
19+ chainweb = new Chainweb (2 , block .chainid , 0 , "" );
20+ chainweb.setupChainsForTest ();
21+ }
1722 function test_readChainwebConfig_anvil () public {
1823 ChainwebConfigReader reader = new ChainwebConfigReader ();
1924 ChainwebConfig memory config = reader.readChainwebConfig ("anvil " );
@@ -35,33 +40,6 @@ contract ChainwebPluginTest is ChainwebTest(2, 0) {
3540 assertTrue (bytes (config.externalHostUrl).length > 0 , "externalHostUrl should be string " );
3641 }
3742
38- function test_deployChainWebChainIdContract () public {
39- uint256 [] memory chainIds = chainweb.getChainIds ();
40- uint256 chainId = chainIds[0 ];
41- chainweb.switchChain (chainId);
42-
43- // Confirm initial value
44- uint256 activeChainId = chainweb.getActiveChainId ();
45- assertEq (activeChainId, chainId);
46-
47- // Now deploy a new chainweb chain id contract with a different value
48- //uint256 newChainId = 9999;
49- chainweb.deployChainWebChainIdContract (chainId);
50-
51- // Check that code exists at the precompile address
52- address precompile = chainweb.CHAIN_ID_PRECOMPILE ();
53- uint256 codeSize;
54- assembly {
55- codeSize := extcodesize (precompile)
56- }
57- assertGt (codeSize, 0 , "No code at CHAIN_ID_PRECOMPILE " );
58-
59- // Use vm.load to read storage slot 0
60- bytes32 stored;
61- stored = vm.load (precompile, bytes32 (uint256 (0 )));
62- assertEq (uint256 (stored), chainId, "Storage slot 0 does not match chainId " );
63- }
64-
6543 function test_setupChainsForScript () public {
6644 Chainweb newChainweb = new Chainweb (2 , block .chainid , 0 , "" );
6745 newChainweb.setupChainsForScript ();
@@ -88,15 +66,12 @@ contract ChainwebPluginTest is ChainwebTest(2, 0) {
8866 assertEq (customChainweb.getHostUrl (), customUrl);
8967 }
9068
91- function test_ActiveChainId () public {
69+ function test_getChainIds () public view {
70+ //Chainweb chainweb = new Chainweb(2, block.chainid, 0, "");
9271 uint256 [] memory chainIds = chainweb.getChainIds ();
93- console.log ("chains.length " , chainIds.length );
9472 for (uint256 i = 0 ; i < chainIds.length ; i++ ) {
95- console.log ("i: " , i);
96- chainweb.switchChain (chainIds[i]);
97- uint256 activeChainId = chainweb.getActiveChainId ();
98- assertEq (activeChainId, chainIds[i]);
99- console.log ("Active chain ID: " , activeChainId);
73+ assertEq (chainIds[i], i);
74+ console.log ("Chain ID: " , chainIds[i]);
10075 }
10176 }
10277
@@ -112,15 +87,47 @@ contract ChainwebPluginTest is ChainwebTest(2, 0) {
11287 }
11388 }
11489
115- function test_getChainIds () public view {
116- //Chainweb chainweb = new Chainweb(2, block.chainid, 0, "");
90+ function test_ActiveChainId () public {
11791 uint256 [] memory chainIds = chainweb.getChainIds ();
92+ console.log ("chains.length " , chainIds.length );
11893 for (uint256 i = 0 ; i < chainIds.length ; i++ ) {
119- assertEq (chainIds[i], i);
120- console.log ("Chain ID: " , chainIds[i]);
94+ console.log ("i: " , i);
95+ chainweb.switchChain (chainIds[i]);
96+ uint256 activeChainId = chainweb.getActiveChainId ();
97+ assertEq (activeChainId, chainIds[i]);
98+ console.log ("Active chain ID: " , activeChainId);
99+ }
100+ }
101+
102+ function test_deployChainWebChainIdContract () public {
103+ uint256 [] memory chainIds = chainweb.getChainIds ();
104+ uint256 chainId = chainIds[0 ];
105+ chainweb.switchChain (chainId);
106+
107+ // Confirm initial value
108+ uint256 activeChainId = chainweb.getActiveChainId ();
109+ assertEq (activeChainId, chainId);
110+
111+ // Now deploy a new chainweb chain id contract with a different value
112+ //uint256 newChainId = 9999;
113+ chainweb.deployChainWebChainIdContract (chainId);
114+
115+ // Check that code exists at the precompile address
116+ address precompile = chainweb.CHAIN_ID_PRECOMPILE ();
117+ uint256 codeSize;
118+ assembly {
119+ codeSize := extcodesize (precompile)
121120 }
121+ assertGt (codeSize, 0 , "No code at CHAIN_ID_PRECOMPILE " );
122+
123+ // Use vm.load to read storage slot 0
124+ bytes32 stored;
125+ stored = vm.load (precompile, bytes32 (uint256 (0 )));
126+ assertEq (uint256 (stored), chainId, "Storage slot 0 does not match chainId " );
122127 }
128+ }
123129
130+ contract ChainwebPluginTest is ChainwebTest (2 , 0 ) {
124131 function test_nonce () public {
125132 address deployer = vm.createWallet ("deployer " ).addr;
126133 uint256 nonce = vm.getNonce (deployer);
0 commit comments