Skip to content

Commit

Permalink
Merge pull request #43 from axieinfinity/feature/network
Browse files Browse the repository at this point in the history
feat: log fork state when switch fork
  • Loading branch information
TuDo1403 authored Dec 28, 2023
2 parents 52ad574 + 28c66e6 commit 60c6a1b
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions script/configs/NetworkConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ abstract contract NetworkConfig is INetworkConfig {

constructor(string memory deploymentRoot) {
_deploymentRoot = deploymentRoot;
console.log(
string.concat("Block Number: ", vm.toString(block.number)),
"|",
string.concat("Timestamp: ", vm.toString(block.timestamp))
);
_logCurrentForkInfo();
}

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

if (chainId == block.chainid) return currentFork;
if (!_isForkModeEnabled) return NULL_FORK_ID;
if (_networkDataMap[_networkMap[chainId]].forkId != NULL_FORK_ID) {
return _networkDataMap[_networkMap[chainId]].forkId;
}
uint256 id = _networkDataMap[_networkMap[chainId]].forkId;
if (id != NULL_FORK_ID) return id;

try vm.createFork(vm.rpcUrl(chainAlias)) returns (uint256 forkId) {
string memory rpcUrl = vm.rpcUrl(chainAlias);
try vm.createFork(rpcUrl) returns (uint256 forkId) {
console.log(StdStyle.blue(string.concat("NetworkConfig: ", chainAlias, " fork created with forkId:")), forkId);
return forkId;
} catch {
console.log(StdStyle.red("NetworkConfig: Cannot create fork with url:"), vm.rpcUrl(chainAlias));
console.log(StdStyle.red("NetworkConfig: Cannot create fork with url:"), rpcUrl);
return NULL_FORK_ID;
}
}
Expand All @@ -104,6 +100,7 @@ abstract contract NetworkConfig is INetworkConfig {
require(forkId != NULL_FORK_ID, "Network Config: Unexists fork!");
vm.selectFork(forkId);
require(_networkDataMap[network].chainId == block.chainid, "NetworkConfig: Switch chain failed");
_logCurrentForkInfo();
}

function getPrivateKeyEnvLabel(TNetwork network) public view virtual returns (string memory privateKeyEnvLabel) {
Expand All @@ -118,4 +115,25 @@ abstract contract NetworkConfig is INetworkConfig {
function getNetworkByChainId(uint256 chainId) public view virtual returns (TNetwork network) {
network = _networkMap[chainId];
}

function _logCurrentForkInfo() internal view {
console.log(
StdStyle.yellow(
string.concat(
"Block Number: ",
vm.toString(block.number),
" | ",
"Timestamp: ",
vm.toString(block.timestamp),
" | ",
"Gas Price: ",
vm.toString(tx.gasprice),
" | ",
"Block Gas Limit: ",
vm.toString(block.gaslimit),
"\n"
)
)
);
}
}

0 comments on commit 60c6a1b

Please sign in to comment.