Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge from 'release/v0.1.0' #19

Merged
merged 5 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading