Skip to content

Commit

Permalink
test(cast): cast send custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
rplusq committed Sep 25, 2024
1 parent b53158d commit 62e596f
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,76 @@ casttest!(block_number_hash, |_prj, cmd| {
assert_eq!(s.trim().parse::<u64>().unwrap(), 1, "{s}")
});

// ... existing code ...

casttest!(send_custom_error, async |prj, cmd| {
// Start anvil
let (_api, handle) = anvil::spawn(NodeConfig::test()).await;
let endpoint = handle.http_endpoint();

prj.add_source(
"SimpleStorage",
r#"
contract SimpleStorage {
error ValueTooHigh(uint256 providedValue, uint256 maxValue);
function setValueTo101() public {
revert ValueTooHigh({ providedValue: 101, maxValue: 100 });
}
}
"#,
)
.unwrap();

// Deploy the contract
let output = cmd
.forge_fuse()
.args([
"create",
"./src/SimpleStorage.sol:SimpleStorage",
"--rpc-url",
&endpoint,
"--private-key",
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
])
.assert_success()
.get_output()
.stdout_lossy();

let address = output.split("Deployed to: ").nth(1).unwrap().split('\n').next().unwrap().trim();

let contract_address = address.trim();

// Call the function that always reverts
cmd
.cast_fuse()
.args([
"send",
contract_address,
"setValueTo101()",
"--rpc-url",
&endpoint,
"--private-key",
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
])
.assert_failure()
.stderr_eq(str![[r#"
Error:
Reverted with custom error:
Possible methods:
- ValueTooHigh(uint256,uint256)
------------
[000]: 0000000000000000000000000000000000000000000000000000000000000065
[020]: 0000000000000000000000000000000000000000000000000000000000000064
Context:
- server returned an error response: error code 3: execution reverted: custom error 0x7a0e1985: ed, data: "0x7a0e198500000000000000000000000000000000000000000000000000000000000000650000000000000000000000000000000000000000000000000000000000000064"
"#]]);
});

casttest!(send_eip7702, async |_prj, cmd| {
let (_api, handle) =
anvil::spawn(NodeConfig::test().with_hardfork(Some(EthereumHardfork::PragueEOF.into())))
Expand Down

0 comments on commit 62e596f

Please sign in to comment.