Skip to content

Commit 60c6a1b

Browse files
authored
Merge pull request #43 from axieinfinity/feature/network
feat: log fork state when switch fork
2 parents 52ad574 + 28c66e6 commit 60c6a1b

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

script/configs/NetworkConfig.sol

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ abstract contract NetworkConfig is INetworkConfig {
1919

2020
constructor(string memory deploymentRoot) {
2121
_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();
2723
}
2824

2925
function getDeploymentRoot() public virtual returns (string memory) {
@@ -85,15 +81,15 @@ abstract contract NetworkConfig is INetworkConfig {
8581

8682
if (chainId == block.chainid) return currentFork;
8783
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;
9186

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) {
9389
console.log(StdStyle.blue(string.concat("NetworkConfig: ", chainAlias, " fork created with forkId:")), forkId);
9490
return forkId;
9591
} 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);
9793
return NULL_FORK_ID;
9894
}
9995
}
@@ -104,6 +100,7 @@ abstract contract NetworkConfig is INetworkConfig {
104100
require(forkId != NULL_FORK_ID, "Network Config: Unexists fork!");
105101
vm.selectFork(forkId);
106102
require(_networkDataMap[network].chainId == block.chainid, "NetworkConfig: Switch chain failed");
103+
_logCurrentForkInfo();
107104
}
108105

109106
function getPrivateKeyEnvLabel(TNetwork network) public view virtual returns (string memory privateKeyEnvLabel) {
@@ -118,4 +115,25 @@ abstract contract NetworkConfig is INetworkConfig {
118115
function getNetworkByChainId(uint256 chainId) public view virtual returns (TNetwork network) {
119116
network = _networkMap[chainId];
120117
}
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+
}
121139
}

0 commit comments

Comments
 (0)