Skip to content

Commit 3c183cd

Browse files
authored
Merge pull request #19 from axieinfinity/release/v0.1.0
chore: merge from 'release/v0.1.0'
2 parents 288efb2 + b20e509 commit 3c183cd

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

script/BaseMigration.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { LibString } from "../lib/solady/src/utils/LibString.sol";
1010
import { console, LibSharedAddress, StdStyle, IScriptExtended, ScriptExtended } from "./extensions/ScriptExtended.s.sol";
1111
import { IArtifactFactory, ArtifactFactory } from "./ArtifactFactory.sol";
12-
import { OnchainDebugger } from "./OnchainDebugger.s.sol"; // cheat to load artifact to parent `out` directory
12+
import { OnchainDebugger } from "./OnchainDebugger.s.sol"; // cheat to load artifact to parent `out` directory
1313
import { IMigrationScript } from "./interfaces/IMigrationScript.sol";
1414
import { LibProxy } from "./libraries/LibProxy.sol";
1515
import { DefaultContract } from "./utils/DefaultContract.sol";

script/OnchainDebugger.s.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.19;
33

4+
import { StdStyle } from "forge-std/StdStyle.sol";
45
import { console2 as console } from "forge-std/console2.sol";
56
import { ScriptExtended } from "./extensions/ScriptExtended.s.sol";
67
import { BaseGeneralConfig } from "./BaseGeneralConfig.sol";
@@ -27,6 +28,14 @@ contract OnchainDebugger is ScriptExtended {
2728
{
2829
vm.prank(from);
2930
(bool success, bytes memory returnOrRevertData) = to.call{ value: value }(callData);
31+
if (!success) {
32+
string[] memory commandInput = new string[](3);
33+
commandInput[0] = "cast";
34+
commandInput[1] = "4byte-decode";
35+
commandInput[2] = vm.toString(returnOrRevertData);
36+
bytes memory decodedError = vm.ffi(commandInput);
37+
console.log(StdStyle.red(string(decodedError)));
38+
}
3039
success.handleRevert(msg.sig, returnOrRevertData);
3140
}
3241
}

script/configs/NetworkConfig.sol

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ abstract contract NetworkConfig is INetworkConfig {
8282
console.log(StdStyle.yellow("NetworkConfig: fork mode disabled, no active fork"));
8383
return NULL_FORK_ID;
8484
}
85-
if (chainId == block.chainid) {
86-
console.log(
87-
StdStyle.yellow(string.concat("NetworkConfig: ", chainAlias, " is already created and active at forkId:")),
88-
currentFork
89-
);
90-
return currentFork;
91-
}
85+
86+
if (chainId == block.chainid) return currentFork;
9287
if (!_isForkModeEnabled) return NULL_FORK_ID;
88+
if (_networkDataMap[_networkMap[chainId]].forkId != NULL_FORK_ID) {
89+
return _networkDataMap[_networkMap[chainId]].forkId;
90+
}
91+
9392
try vm.createFork(vm.rpcUrl(chainAlias)) returns (uint256 forkId) {
9493
console.log(StdStyle.blue(string.concat("NetworkConfig: ", chainAlias, " fork created with forkId:")), forkId);
9594
return forkId;

script/extensions/ScriptExtended.s.sol

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
1717
IGeneralConfig public constant CONFIG = IGeneralConfig(LibSharedAddress.CONFIG);
1818

1919
modifier logFn(string memory fnName) {
20-
console.log("> ", StdStyle.blue(fnName), "...");
20+
_logFn(fnName);
2121
_;
2222
}
2323

2424
modifier onlyOn(TNetwork networkType) {
25-
require(network() == networkType, string.concat("ScriptExtended: Only allowed on ", CONFIG.getAlias(networkType)));
25+
_requireOn(networkType);
26+
_;
27+
}
28+
29+
modifier onNetwork(TNetwork networkType) {
30+
TNetwork currentNetwork = _before(networkType);
2631
_;
32+
_after(currentNetwork);
2733
}
2834

2935
function setUp() public virtual {
@@ -86,4 +92,22 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
8692
assertTrue(success, "ScriptExtended: Failed to create runtime bytecode.");
8793
vm.etch(where, runtimeBytecode);
8894
}
95+
96+
function _logFn(string memory fnName) private view {
97+
console.log("> ", StdStyle.blue(fnName), "...");
98+
}
99+
100+
function _requireOn(TNetwork networkType) private view {
101+
require(network() == networkType, string.concat("ScriptExtended: Only allowed on ", CONFIG.getAlias(networkType)));
102+
}
103+
104+
function _before(TNetwork networkType) private returns (TNetwork currentNetwork) {
105+
currentNetwork = network();
106+
CONFIG.createFork(networkType);
107+
CONFIG.switchTo(networkType);
108+
}
109+
110+
function _after(TNetwork currentNetwork) private {
111+
CONFIG.switchTo(currentNetwork);
112+
}
89113
}

0 commit comments

Comments
 (0)