Skip to content

Commit

Permalink
feat: add cheat broadcast function
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Mar 12, 2024
1 parent b862a0a commit 79cab10
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import { IMigrationScript } from "./interfaces/IMigrationScript.sol";
import { LibProxy } from "./libraries/LibProxy.sol";
import { DefaultContract } from "./utils/DefaultContract.sol";
import { TContract } from "./types/Types.sol";
import { LibErrorHandler } from "../lib/contract-libs/src/LibErrorHandler.sol";

abstract contract BaseMigration is ScriptExtended {
using StdStyle for *;
using LibString for bytes32;
using LibErrorHandler for bool;
using LibProxy for address payable;

IArtifactFactory public constant ARTIFACT_FACTORY = IArtifactFactory(LibSharedAddress.ARTIFACT_FACTORY);
Expand Down Expand Up @@ -304,6 +306,28 @@ abstract contract BaseMigration is ScriptExtended {
}
}

function _cheatBroadcast(address from, address to, bytes memory callData) internal virtual {
string[] memory commandInputs = new string[](3);
commandInputs[0] = "cast";
commandInputs[1] = "4byte-decode";
commandInputs[2] = vm.toString(callData);
string memory decodedCallData = string(vm.ffi(commandInputs));

console.log("\n");
console.log("--------------------------- Call Detail ---------------------------");
console.log("To:".cyan(), vm.getLabel(to));
console.log(
"Raw Calldata Data (Please double check using `cast pretty-calldata {raw_bytes}`):\n".cyan(),
string.concat(" - ", vm.toString(callData))
);
console.log("Cast Decoded Call Data:".cyan(), decodedCallData);
console.log("--------------------------------------------------------------------");

vm.prank(from);
(bool success, bytes memory returnOrRevertData) = to.call(callData);
success.handleRevert(bytes4(callData), returnOrRevertData);
}

function _cheatUpgrade(address owner, ProxyAdmin wProxyAdmin, ITransparentUpgradeableProxy iProxy, address logic)
internal
virtual
Expand Down

0 comments on commit 79cab10

Please sign in to comment.