@@ -3,32 +3,13 @@ pragma solidity >=0.6.2 <0.9.0;
33
44pragma experimental ABIEncoderV2;
55
6+ import "./StdChains.sol " ;
67import "./StdStorage.sol " ;
78import "./Vm.sol " ;
89
9- abstract contract StdCheatsSafe {
10+ abstract contract StdCheatsSafe is StdChains {
1011 VmSafe private constant vm = VmSafe (address (uint160 (uint256 (keccak256 ("hevm cheat code " )))));
1112
12- /// @dev To hide constructor warnings across solc versions due to different constructor visibility requirements and
13- /// syntaxes, we put the constructor in a private method and assign an unused return value to a variable. This
14- /// forces the method to run during construction, but without declaring an explicit constructor.
15- uint256 private CONSTRUCTOR = _constructor ();
16-
17- struct Chain {
18- // The chain name, using underscores as the separator to match `foundry.toml` conventions.
19- string name;
20- // The chain's Chain ID.
21- uint256 chainId;
22- // A default RPC endpoint for this chain.
23- // NOTE: This default RPC URL is included for convenience to facilitate quick tests and
24- // experimentation. Do not use this RPC URL for production test suites, CI, or other heavy
25- // usage as you will be throttled and this is a disservice to others who need this endpoint.
26- string rpcUrl;
27- }
28-
29- // Maps from a chain's name (matching what's in the `foundry.toml` file) to chain data.
30- mapping (string => Chain) internal stdChains;
31-
3213 // Data structures to parse Transaction objects from the broadcast artifact
3314 // that conform to EIP1559. The Raw structs is what is parsed from the JSON
3415 // and then converted to the one that is used by the user for better UX.
@@ -206,35 +187,7 @@ abstract contract StdCheatsSafe {
206187 string value;
207188 }
208189
209- function _constructor () private returns (uint256 ) {
210- // Initialize `stdChains` with the defaults.
211- stdChains["anvil " ] = Chain ("Anvil " , 31337 , "http://127.0.0.1:8545 " );
212- stdChains["hardhat " ] = Chain ("Hardhat " , 31337 , "http://127.0.0.1:8545 " );
213- stdChains["mainnet " ] = Chain ("Mainnet " , 1 , "https://mainnet.infura.io/v3/6770454bc6ea42c58aac12978531b93f " );
214- stdChains["goerli " ] = Chain ("Goerli " , 5 , "https://goerli.infura.io/v3/6770454bc6ea42c58aac12978531b93f " );
215- stdChains["sepolia " ] = Chain ("Sepolia " , 11155111 , "https://rpc.sepolia.dev " );
216- stdChains["optimism " ] = Chain ("Optimism " , 10 , "https://mainnet.optimism.io " );
217- stdChains["optimism_goerli " ] = Chain ("Optimism Goerli " , 420 , "https://goerli.optimism.io " );
218- stdChains["arbitrum_one " ] = Chain ("Arbitrum One " , 42161 , "https://arb1.arbitrum.io/rpc " );
219- stdChains["arbitrum_one_goerli " ] = Chain ("Arbitrum One Goerli " , 421613 , "https://goerli-rollup.arbitrum.io/rpc " );
220- stdChains["arbitrum_nova " ] = Chain ("Arbitrum Nova " , 42170 , "https://nova.arbitrum.io/rpc " );
221- stdChains["polygon " ] = Chain ("Polygon " , 137 , "https://polygon-rpc.com " );
222- stdChains["polygon_mumbai " ] = Chain ("Polygon Mumbai " , 80001 , "https://rpc-mumbai.matic.today " );
223- stdChains["avalanche " ] = Chain ("Avalanche " , 43114 , "https://api.avax.network/ext/bc/C/rpc " );
224- stdChains["avalanche_fuji " ] = Chain ("Avalanche Fuji " , 43113 , "https://api.avax-test.network/ext/bc/C/rpc " );
225- stdChains["bnb_smart_chain " ] = Chain ("BNB Smart Chain " , 56 , "https://bsc-dataseed1.binance.org " );
226- stdChains["bnb_smart_chain_testnet " ] = Chain ("BNB Smart Chain Testnet " , 97 , "https://data-seed-prebsc-1-s1.binance.org:8545 " );// forgefmt: disable-line
227- stdChains["gnosis_chain " ] = Chain ("Gnosis Chain " , 100 , "https://rpc.gnosischain.com " );
228-
229- // Loop over RPC URLs in the config file to replace the default RPC URLs
230- Vm.Rpc[] memory rpcs = vm.rpcUrlStructs ();
231- for (uint256 i = 0 ; i < rpcs.length ; i++ ) {
232- stdChains[rpcs[i].name].rpcUrl = rpcs[i].url;
233- }
234- return 0 ;
235- }
236-
237- function assumeNoPrecompiles (address addr ) internal view virtual {
190+ function assumeNoPrecompiles (address addr ) internal virtual {
238191 // Assembly required since `block.chainid` was introduced in 0.8.0.
239192 uint256 chainId;
240193 assembly {
@@ -243,21 +196,21 @@ abstract contract StdCheatsSafe {
243196 assumeNoPrecompiles (addr, chainId);
244197 }
245198
246- function assumeNoPrecompiles (address addr , uint256 chainId ) internal view virtual {
199+ function assumeNoPrecompiles (address addr , uint256 chainId ) internal virtual {
247200 // Note: For some chains like Optimism these are technically predeploys (i.e. bytecode placed at a specific
248201 // address), but the same rationale for excluding them applies so we include those too.
249202
250203 // These should be present on all EVM-compatible chains.
251204 vm.assume (addr < address (0x1 ) || addr > address (0x9 ));
252205
253206 // forgefmt: disable-start
254- if (chainId == stdChains[ "optimism " ] .chainId || chainId == stdChains[ "optimism_goerli " ] .chainId) {
207+ if (chainId == getChain ( "optimism " ) .chainId || chainId == getChain ( "optimism_goerli " ) .chainId) {
255208 // https://github.com/ethereum-optimism/optimism/blob/eaa371a0184b56b7ca6d9eb9cb0a2b78b2ccd864/op-bindings/predeploys/addresses.go#L6-L21
256209 vm.assume (addr < address (0x4200000000000000000000000000000000000000 ) || addr > address (0x4200000000000000000000000000000000000800 ));
257- } else if (chainId == stdChains[ "arbitrum_one " ] .chainId || chainId == stdChains[ "arbitrum_one_goerli " ] .chainId) {
210+ } else if (chainId == getChain ( "arbitrum_one " ) .chainId || chainId == getChain ( "arbitrum_one_goerli " ) .chainId) {
258211 // https://developer.arbitrum.io/useful-addresses#arbitrum-precompiles-l2-same-on-all-arb-chains
259212 vm.assume (addr < address (0x0000000000000000000000000000000000000064 ) || addr > address (0x0000000000000000000000000000000000000068 ));
260- } else if (chainId == stdChains[ "avalanche " ] .chainId || chainId == stdChains[ "avalanche_fuji " ] .chainId) {
213+ } else if (chainId == getChain ( "avalanche " ) .chainId || chainId == getChain ( "avalanche_fuji " ) .chainId) {
261214 // https://github.com/ava-labs/subnet-evm/blob/47c03fd007ecaa6de2c52ea081596e0a88401f58/precompile/params.go#L18-L59
262215 vm.assume (addr < address (0x0100000000000000000000000000000000000000 ) || addr > address (0x01000000000000000000000000000000000000ff ));
263216 vm.assume (addr < address (0x0200000000000000000000000000000000000000 ) || addr > address (0x02000000000000000000000000000000000000FF ));
0 commit comments