Skip to content

Commit

Permalink
feat: add debug script
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed Oct 17, 2023
1 parent e0d7c31 commit ab3f829
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .debug.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Fork block number to debug
BLOCK=0x0
# Caller
FROM=0x0000000000000000000000000000000000000000
# Callee
TO=0x0000000000000000000000000000000000000000
# Sent Value
VALUE=0x27cdb0997a65b2de99
# Call Data
CALLDATA=0x0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ docs/
# Dotenv file
.env
.vscode
.debug.env

node_modules/
yarn-error.log
Expand Down
39 changes: 39 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Source (or "dot") the .env file to load environment variables
if [ -f .env ]; then
source .debug.env
else
echo "Error: .debug.env file not found."
fi

verify_arg=""
extra_argument=""
op_command=""

for arg in "$@"; do
case $arg in
--trezor)
op_command=""
extra_argument+=trezor@
;;
--broadcast)
op_command="op run --env-file="./.env" --"
;;
--log)
set -- "${@/#--log/}"
extra_argument+=log@
;;
*) ;;
esac
done

# Remove the @ character from the end of extra_argument
extra_argument="${extra_argument%%@}"

echo Debug Tx...
echo From: ${FROM}
echo To: ${TO}
echo Value: ${VALUE}
echo Calldata:
cast pretty-calldata ${CALLDATA}
calldata=$(cast calldata 'debug(uint256,address,address,uint256,bytes)', ${BLOCK} ${FROM} ${TO} ${VALUE} ${CALLDATA})
${op_command} forge script ${verify_arg} --legacy ${@} script/Debug.s.sol --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
18 changes: 18 additions & 0 deletions script/Debug.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { RNSDeploy } from "./RNSDeploy.s.sol";
import { ErrorHandler } from "@rns-contracts/libraries/ErrorHandler.sol";

contract Debug is RNSDeploy {
using ErrorHandler for *;

function debug(uint256 forkBlock, address from, address to, uint256 value, bytes calldata callData) external {
if (forkBlock != 0) {
vm.rollFork(forkBlock);
}
vm.prank(from);
(bool success, bytes memory returnOrRevertData) = to.call{ value: value }(callData);
success.handleRevert(returnOrRevertData);
}
}

0 comments on commit ab3f829

Please sign in to comment.