Skip to content

Commit

Permalink
chore: fix minor bugs & pause uneccessary trace
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Oct 10, 2024
1 parent 1328dee commit 566902b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
18 changes: 11 additions & 7 deletions generate-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ if [[ -z "$name" || -z "$args" || -z "$value" || -z "$nonce" || -z "$deployer" |
exit 1
fi

source_name=$(basename $absolute_path)
# Remove .json or .sol extension
source_name=${source_name%.*}

# Generate the artifact
abi=$(forge inspect $name abi)
devdoc=$(forge inspect $name devdoc)
userdoc=$(forge inspect $name userdoc)
metadata=$(forge inspect $name metadata)
storage_layout=$(forge inspect $name storageLayout)
bytecode=$(forge inspect $name bytecode)
deployed_bytecode=$(forge inspect $name deployedBytecode)
abi=$(forge inspect $source_name abi)
devdoc=$(forge inspect $source_name devdoc)
userdoc=$(forge inspect $source_name userdoc)
metadata=$(forge inspect $source_name metadata)
storage_layout=$(forge inspect $source_name storageLayout)
bytecode=$(forge inspect $source_name bytecode)
deployed_bytecode=$(forge inspect $source_name deployedBytecode)

# Create the JSON object
json_content=$(
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ if [[ ! $extra_argument == *"sender"* ]] && [[ ! $extra_argument == *"trezor"* ]
if [[ $(eval "echo \$$account_label") == *"op://"* ]]; then
echo "\033[32mFound 'op://' in ${account_label}\033[0m"
op_command="op run --env-file="./.env" --"
elif [[ $(eval "echo \$$account_label") == *""* ]]; then
elif [[ -z $(eval "echo \$$account_label") ]]; then
echo "\033[33mWARNING: Not found private key in ${account_label}\033[0m"
fi
else
Expand Down
16 changes: 16 additions & 0 deletions script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ abstract contract BaseMigration is ScriptExtended {
) internal virtual { }

function _beforeRunningScript() internal virtual override {
vm.pauseTracing();
vm.recordLogs();
vm.startStateDiffRecording();
vm.resumeTracing();
}

function _afterRunningScript() internal virtual override {
vm.pauseTracing();
Vm.Log[] memory recordedLogs = vm.getRecordedLogs();
Vm.AccountAccess[] memory stateDiffs = vm.stopAndReturnStateDiff();
vm.resumeTracing();

LibInitializeGuard.validate({ logs: recordedLogs, stateDiffs: stateDiffs });
}
Expand All @@ -76,6 +80,18 @@ abstract contract BaseMigration is ScriptExtended {
vme.logSenderInfo();
}

function switchBack(TNetwork prvNetwork, uint256 prvForkId) public virtual override {
super.switchBack(prvNetwork, prvForkId);
// Should rebuild the shared arguments since different chain may have different shared arguments
_storeRawSharedArguments();
// Should rebuild runtime config since different chain may have different runtime config
vme.buildRuntimeConfig();
// Should rebuild the contract data since different chain may have different contract data
vme.setUpDefaultContracts();
// Log Sender Info of current network
vme.logSenderInfo();
}

function loadContractOrDeploy(
TContract contractType
) public virtual returns (address payable contractAddr) {
Expand Down
3 changes: 0 additions & 3 deletions script/libraries/LibArtifact.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { StdStyle } from "../../dependencies/forge-std-1.9.3/src/StdStyle.sol";
import { Vm } from "../../dependencies/forge-std-1.9.3/src/Vm.sol";
import { console } from "../../dependencies/forge-std-1.9.3/src/console.sol";

import { JSONParserLib } from "../../dependencies/solady-0.0.228/src/utils/JSONParserLib.sol";
import { LibString } from "../../dependencies/solady-0.0.228/src/utils/LibString.sol";
import { IGeneralConfig } from "../interfaces/IGeneralConfig.sol";
import { IRuntimeConfig } from "../interfaces/configs/IRuntimeConfig.sol";
Expand All @@ -32,8 +31,6 @@ library LibArtifact {
using stdJson for string;
using LibString for string;
using LibString for address;
using JSONParserLib for string;
using JSONParserLib for JSONParserLib.Item;

Vm private constant vm = Vm(LibSharedAddress.VM);
IGeneralConfig private constant vme = IGeneralConfig(LibSharedAddress.VME);
Expand Down
8 changes: 7 additions & 1 deletion script/libraries/LibInitializeGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ library LibInitializeGuard {
* @param stateDiffs The state diffs of the transactions.
*/
function validate(Vm.Log[] memory logs, Vm.AccountAccess[] memory stateDiffs) internal {
vm.pauseGasMetering();
Cache storage $ = _getCacheStorage();

_recordUpgradesAndInitializations({ $cache: $, logs: logs });
Expand Down Expand Up @@ -116,6 +117,7 @@ library LibInitializeGuard {

_validateLogicsVersion({ $cache: $ });
_validateProxiesVersion({ $cache: $ });
vm.resumeTracing();
}

/**
Expand Down Expand Up @@ -341,8 +343,12 @@ library LibInitializeGuard {
) internal pure returns (string memory contractName) {
uint256 length = bytes(path).length;
// Remove ".sol"
contractName = path;
if (path.endsWith(".sol")) contractName = path.slice(0, length - 4);
return string(contractName);
string[] memory parts = contractName.split(":");
if (parts.length != 0) contractName = parts[parts.length - 1];
parts = contractName.split("/");
if (parts.length != 0) contractName = parts[parts.length - 1];
}

/**
Expand Down

0 comments on commit 566902b

Please sign in to comment.