@@ -3,6 +3,24 @@ pragma solidity >=0.7.0 <0.9.0;
33
44import "../src/Test.sol " ;
55
6+ contract StdChainsMock is Test {
7+ function exposed_getChain (string memory chainAlias ) public returns (Chain memory ) {
8+ return getChain (chainAlias);
9+ }
10+
11+ function exposed_getChain (uint256 chainId ) public returns (Chain memory ) {
12+ return getChain (chainId);
13+ }
14+
15+ function exposed_setChain (string memory chainAlias , ChainData memory chainData ) public {
16+ setChain (chainAlias, chainData);
17+ }
18+
19+ function exposed_setFallbackToDefaultRpcUrls (bool useDefault ) public {
20+ setFallbackToDefaultRpcUrls (useDefault);
21+ }
22+ }
23+
624contract StdChainsTest is Test {
725 function testChainRpcInitialization () public {
826 // RPCs specified in `foundry.toml` should be updated.
@@ -50,29 +68,41 @@ contract StdChainsTest is Test {
5068 // }
5169
5270 function testChainNoDefault () public {
71+ // We deploy a mock to properly test the revert.
72+ StdChainsMock stdChainsMock = new StdChainsMock ();
73+
5374 vm.expectRevert ("StdChains getChain(string): Chain with alias \" does_not_exist \" not found. " );
54- getChain ("does_not_exist " );
75+ stdChainsMock. exposed_getChain ("does_not_exist " );
5576 }
5677
5778 function testSetChainFirstFails () public {
79+ // We deploy a mock to properly test the revert.
80+ StdChainsMock stdChainsMock = new StdChainsMock ();
81+
5882 vm.expectRevert ("StdChains setChain(string,ChainData): Chain ID 31337 already used by \" anvil \" . " );
59- setChain ("anvil2 " , ChainData ("Anvil " , 31337 , "URL " ));
83+ stdChainsMock. exposed_setChain ("anvil2 " , ChainData ("Anvil " , 31337 , "URL " ));
6084 }
6185
6286 function testChainBubbleUp () public {
63- setChain ("needs_undefined_env_var " , ChainData ("" , 123456789 , "" ));
87+ // We deploy a mock to properly test the revert.
88+ StdChainsMock stdChainsMock = new StdChainsMock ();
89+
90+ stdChainsMock.exposed_setChain ("needs_undefined_env_var " , ChainData ("" , 123456789 , "" ));
6491 vm.expectRevert (
6592 "Failed to resolve env var `UNDEFINED_RPC_URL_PLACEHOLDER` in `${UNDEFINED_RPC_URL_PLACEHOLDER}`: environment variable not found "
6693 );
67- getChain ("needs_undefined_env_var " );
94+ stdChainsMock. exposed_getChain ("needs_undefined_env_var " );
6895 }
6996
7097 function testCannotSetChain_ChainIdExists () public {
71- setChain ("custom_chain " , ChainData ("Custom Chain " , 123456789 , "https://custom.chain/ " ));
98+ // We deploy a mock to properly test the revert.
99+ StdChainsMock stdChainsMock = new StdChainsMock ();
100+
101+ stdChainsMock.exposed_setChain ("custom_chain " , ChainData ("Custom Chain " , 123456789 , "https://custom.chain/ " ));
72102
73103 vm.expectRevert ('StdChains setChain(string,ChainData): Chain ID 123456789 already used by "custom_chain". ' );
74104
75- setChain ("another_custom_chain " , ChainData ("" , 123456789 , "" ));
105+ stdChainsMock. exposed_setChain ("another_custom_chain " , ChainData ("" , 123456789 , "" ));
76106 }
77107
78108 function testSetChain () public {
@@ -102,42 +132,64 @@ contract StdChainsTest is Test {
102132 }
103133
104134 function testSetNoEmptyAlias () public {
135+ // We deploy a mock to properly test the revert.
136+ StdChainsMock stdChainsMock = new StdChainsMock ();
137+
105138 vm.expectRevert ("StdChains setChain(string,ChainData): Chain alias cannot be the empty string. " );
106- setChain ("" , ChainData ("" , 123456789 , "" ));
139+ stdChainsMock. exposed_setChain ("" , ChainData ("" , 123456789 , "" ));
107140 }
108141
109142 function testSetNoChainId0 () public {
143+ // We deploy a mock to properly test the revert.
144+ StdChainsMock stdChainsMock = new StdChainsMock ();
145+
110146 vm.expectRevert ("StdChains setChain(string,ChainData): Chain ID cannot be 0. " );
111- setChain ("alias " , ChainData ("" , 0 , "" ));
147+ stdChainsMock. exposed_setChain ("alias " , ChainData ("" , 0 , "" ));
112148 }
113149
114150 function testGetNoChainId0 () public {
151+ // We deploy a mock to properly test the revert.
152+ StdChainsMock stdChainsMock = new StdChainsMock ();
153+
115154 vm.expectRevert ("StdChains getChain(uint256): Chain ID cannot be 0. " );
116- getChain (0 );
155+ stdChainsMock. exposed_getChain (0 );
117156 }
118157
119158 function testGetNoEmptyAlias () public {
159+ // We deploy a mock to properly test the revert.
160+ StdChainsMock stdChainsMock = new StdChainsMock ();
161+
120162 vm.expectRevert ("StdChains getChain(string): Chain alias cannot be the empty string. " );
121- getChain ("" );
163+ stdChainsMock. exposed_getChain ("" );
122164 }
123165
124166 function testChainIdNotFound () public {
167+ // We deploy a mock to properly test the revert.
168+ StdChainsMock stdChainsMock = new StdChainsMock ();
169+
125170 vm.expectRevert ("StdChains getChain(string): Chain with alias \" no_such_alias \" not found. " );
126- getChain ("no_such_alias " );
171+ stdChainsMock. exposed_getChain ("no_such_alias " );
127172 }
128173
129174 function testChainAliasNotFound () public {
175+ // We deploy a mock to properly test the revert.
176+ StdChainsMock stdChainsMock = new StdChainsMock ();
177+
130178 vm.expectRevert ("StdChains getChain(uint256): Chain with ID 321 not found. " );
131- getChain (321 );
179+
180+ stdChainsMock.exposed_getChain (321 );
132181 }
133182
134183 function testSetChain_ExistingOne () public {
184+ // We deploy a mock to properly test the revert.
185+ StdChainsMock stdChainsMock = new StdChainsMock ();
186+
135187 setChain ("custom_chain " , ChainData ("Custom Chain " , 123456789 , "https://custom.chain/ " ));
136188 assertEq (getChain (123456789 ).chainId, 123456789 );
137189
138190 setChain ("custom_chain " , ChainData ("Modified Chain " , 999999999 , "https://modified.chain/ " ));
139191 vm.expectRevert ("StdChains getChain(uint256): Chain with ID 123456789 not found. " );
140- getChain (123456789 );
192+ stdChainsMock. exposed_getChain (123456789 );
141193
142194 Chain memory modifiedChain = getChain (999999999 );
143195 assertEq (modifiedChain.name, "Modified Chain " );
@@ -146,15 +198,18 @@ contract StdChainsTest is Test {
146198 }
147199
148200 function testDontUseDefaultRpcUrl () public {
201+ // We deploy a mock to properly test the revert.
202+ StdChainsMock stdChainsMock = new StdChainsMock ();
203+
149204 // Should error if default RPCs flag is set to false.
150- setFallbackToDefaultRpcUrls (false );
205+ stdChainsMock. exposed_setFallbackToDefaultRpcUrls (false );
151206 vm.expectRevert (
152207 "Failed to get environment variable `ANVIL_RPC_URL` as type `string`: environment variable not found "
153208 );
154- getChain (31337 );
209+ stdChainsMock. exposed_getChain (31337 );
155210 vm.expectRevert (
156211 "Failed to get environment variable `SEPOLIA_RPC_URL` as type `string`: environment variable not found "
157212 );
158- getChain ("sepolia " );
213+ stdChainsMock. exposed_getChain ("sepolia " );
159214 }
160215}
0 commit comments