Skip to content

Commit

Permalink
Merge pull request #19 from axieinfinity/release/v0.1.0
Browse files Browse the repository at this point in the history
chore: merge from 'release/v0.1.0'
  • Loading branch information
TuDo1403 authored Dec 18, 2023
2 parents 288efb2 + b20e509 commit 3c183cd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { LibString } from "../lib/solady/src/utils/LibString.sol";
import { console, LibSharedAddress, StdStyle, IScriptExtended, ScriptExtended } from "./extensions/ScriptExtended.s.sol";
import { IArtifactFactory, ArtifactFactory } from "./ArtifactFactory.sol";
import { OnchainDebugger } from "./OnchainDebugger.s.sol"; // cheat to load artifact to parent `out` directory
import { OnchainDebugger } from "./OnchainDebugger.s.sol"; // cheat to load artifact to parent `out` directory
import { IMigrationScript } from "./interfaces/IMigrationScript.sol";
import { LibProxy } from "./libraries/LibProxy.sol";
import { DefaultContract } from "./utils/DefaultContract.sol";
Expand Down
9 changes: 9 additions & 0 deletions script/OnchainDebugger.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { StdStyle } from "forge-std/StdStyle.sol";
import { console2 as console } from "forge-std/console2.sol";
import { ScriptExtended } from "./extensions/ScriptExtended.s.sol";
import { BaseGeneralConfig } from "./BaseGeneralConfig.sol";
Expand All @@ -27,6 +28,14 @@ contract OnchainDebugger is ScriptExtended {
{
vm.prank(from);
(bool success, bytes memory returnOrRevertData) = to.call{ value: value }(callData);
if (!success) {
string[] memory commandInput = new string[](3);
commandInput[0] = "cast";
commandInput[1] = "4byte-decode";
commandInput[2] = vm.toString(returnOrRevertData);
bytes memory decodedError = vm.ffi(commandInput);
console.log(StdStyle.red(string(decodedError)));
}
success.handleRevert(msg.sig, returnOrRevertData);
}
}
13 changes: 6 additions & 7 deletions script/configs/NetworkConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ abstract contract NetworkConfig is INetworkConfig {
console.log(StdStyle.yellow("NetworkConfig: fork mode disabled, no active fork"));
return NULL_FORK_ID;
}
if (chainId == block.chainid) {
console.log(
StdStyle.yellow(string.concat("NetworkConfig: ", chainAlias, " is already created and active at forkId:")),
currentFork
);
return currentFork;
}

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;
}

try vm.createFork(vm.rpcUrl(chainAlias)) returns (uint256 forkId) {
console.log(StdStyle.blue(string.concat("NetworkConfig: ", chainAlias, " fork created with forkId:")), forkId);
return forkId;
Expand Down
28 changes: 26 additions & 2 deletions script/extensions/ScriptExtended.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
IGeneralConfig public constant CONFIG = IGeneralConfig(LibSharedAddress.CONFIG);

modifier logFn(string memory fnName) {
console.log("> ", StdStyle.blue(fnName), "...");
_logFn(fnName);
_;
}

modifier onlyOn(TNetwork networkType) {
require(network() == networkType, string.concat("ScriptExtended: Only allowed on ", CONFIG.getAlias(networkType)));
_requireOn(networkType);
_;
}

modifier onNetwork(TNetwork networkType) {
TNetwork currentNetwork = _before(networkType);
_;
_after(currentNetwork);
}

function setUp() public virtual {
Expand Down Expand Up @@ -86,4 +92,22 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
assertTrue(success, "ScriptExtended: Failed to create runtime bytecode.");
vm.etch(where, runtimeBytecode);
}

function _logFn(string memory fnName) private view {
console.log("> ", StdStyle.blue(fnName), "...");
}

function _requireOn(TNetwork networkType) private view {
require(network() == networkType, string.concat("ScriptExtended: Only allowed on ", CONFIG.getAlias(networkType)));
}

function _before(TNetwork networkType) private returns (TNetwork currentNetwork) {
currentNetwork = network();
CONFIG.createFork(networkType);
CONFIG.switchTo(networkType);
}

function _after(TNetwork currentNetwork) private {
CONFIG.switchTo(currentNetwork);
}
}

0 comments on commit 3c183cd

Please sign in to comment.