@@ -19,11 +19,7 @@ abstract contract NetworkConfig is INetworkConfig {
19
19
20
20
constructor (string memory deploymentRoot ) {
21
21
_deploymentRoot = deploymentRoot;
22
- console.log (
23
- string .concat ("Block Number: " , vm.toString (block .number )),
24
- "| " ,
25
- string .concat ("Timestamp: " , vm.toString (block .timestamp ))
26
- );
22
+ _logCurrentForkInfo ();
27
23
}
28
24
29
25
function getDeploymentRoot () public virtual returns (string memory ) {
@@ -85,15 +81,15 @@ abstract contract NetworkConfig is INetworkConfig {
85
81
86
82
if (chainId == block .chainid ) return currentFork;
87
83
if (! _isForkModeEnabled) return NULL_FORK_ID;
88
- if (_networkDataMap[_networkMap[chainId]].forkId != NULL_FORK_ID) {
89
- return _networkDataMap[_networkMap[chainId]].forkId;
90
- }
84
+ uint256 id = _networkDataMap[_networkMap[chainId]].forkId;
85
+ if (id != NULL_FORK_ID) return id;
91
86
92
- try vm.createFork (vm.rpcUrl (chainAlias)) returns (uint256 forkId ) {
87
+ string memory rpcUrl = vm.rpcUrl (chainAlias);
88
+ try vm.createFork (rpcUrl) returns (uint256 forkId ) {
93
89
console.log (StdStyle.blue (string .concat ("NetworkConfig: " , chainAlias, " fork created with forkId: " )), forkId);
94
90
return forkId;
95
91
} catch {
96
- console.log (StdStyle.red ("NetworkConfig: Cannot create fork with url: " ), vm. rpcUrl (chainAlias) );
92
+ console.log (StdStyle.red ("NetworkConfig: Cannot create fork with url: " ), rpcUrl);
97
93
return NULL_FORK_ID;
98
94
}
99
95
}
@@ -104,6 +100,7 @@ abstract contract NetworkConfig is INetworkConfig {
104
100
require (forkId != NULL_FORK_ID, "Network Config: Unexists fork! " );
105
101
vm.selectFork (forkId);
106
102
require (_networkDataMap[network].chainId == block .chainid , "NetworkConfig: Switch chain failed " );
103
+ _logCurrentForkInfo ();
107
104
}
108
105
109
106
function getPrivateKeyEnvLabel (TNetwork network ) public view virtual returns (string memory privateKeyEnvLabel ) {
@@ -118,4 +115,25 @@ abstract contract NetworkConfig is INetworkConfig {
118
115
function getNetworkByChainId (uint256 chainId ) public view virtual returns (TNetwork network ) {
119
116
network = _networkMap[chainId];
120
117
}
118
+
119
+ function _logCurrentForkInfo () internal view {
120
+ console.log (
121
+ StdStyle.yellow (
122
+ string .concat (
123
+ "Block Number: " ,
124
+ vm.toString (block .number ),
125
+ " | " ,
126
+ "Timestamp: " ,
127
+ vm.toString (block .timestamp ),
128
+ " | " ,
129
+ "Gas Price: " ,
130
+ vm.toString (tx .gasprice ),
131
+ " | " ,
132
+ "Block Gas Limit: " ,
133
+ vm.toString (block .gaslimit ),
134
+ "\n "
135
+ )
136
+ )
137
+ );
138
+ }
121
139
}
0 commit comments