Skip to content

Commit 2d8f9d7

Browse files
committed
feat: Add tests for cast call with --override-* and --trace flags
1 parent eae8db8 commit 2d8f9d7

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

crates/cast/tests/cli/main.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,30 @@ contract Counter {
24052405
.stdout_eq(str![[r#"
24062406
4660
24072407
2408+
"#]]);
2409+
2410+
// Override state, `number()` should return overridden value.
2411+
cmd.cast_fuse()
2412+
.args([
2413+
"call",
2414+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2415+
"--rpc-url",
2416+
&handle.http_endpoint(),
2417+
"--override-state",
2418+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x1234",
2419+
"number()(uint256)",
2420+
"--trace",
2421+
])
2422+
.assert_success()
2423+
.stdout_eq(str![[r#"
2424+
Traces:
2425+
[2402] 0x5FbDB2315678afecb367f032d93F642f64180aa3::number()
2426+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000001234
2427+
2428+
2429+
Transaction successfully executed.
2430+
[GAS]
2431+
24082432
"#]]);
24092433

24102434
// Override balance, `getBalance()` should return overridden value.
@@ -2423,6 +2447,31 @@ contract Counter {
24232447
.stdout_eq(str![[r#"
24242448
4369
24252449
2450+
"#]]);
2451+
2452+
// Override balance, `getBalance()` should return overridden value.
2453+
cmd.cast_fuse()
2454+
.args([
2455+
"call",
2456+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2457+
"--rpc-url",
2458+
&handle.http_endpoint(),
2459+
"--override-balance",
2460+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x1111",
2461+
"getBalance(address)(uint256)",
2462+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2463+
"--trace",
2464+
])
2465+
.assert_success()
2466+
.stdout_eq(str![[r#"
2467+
Traces:
2468+
[747] 0x5FbDB2315678afecb367f032d93F642f64180aa3::getBalance(0x5FbDB2315678afecb367f032d93F642f64180aa3)
2469+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000001111
2470+
2471+
2472+
Transaction successfully executed.
2473+
[GAS]
2474+
24262475
"#]]);
24272476

24282477
// Override code with
@@ -2444,6 +2493,28 @@ contract Counter {
24442493
.stderr_eq(str![[r#"
24452494
Error: server returned an error response: error code 3: execution reverted, data: "0x"
24462495
2496+
"#]]);
2497+
2498+
// Override code with
2499+
// contract Counter {
2500+
// uint256 public number1;
2501+
// }
2502+
// Calling `number()` should revert.
2503+
cmd.cast_fuse()
2504+
.args([
2505+
"call",
2506+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2507+
"--rpc-url",
2508+
&handle.http_endpoint(),
2509+
"--override-code",
2510+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063c223a39e14602a575b5f5ffd5b60306044565b604051603b9190605f565b60405180910390f35b5f5481565b5f819050919050565b6059816049565b82525050565b5f60208201905060705f8301846052565b9291505056fea26469706673582212202a0acfb9083efed3e0e9f27177b090731d4392cf196d58e27e05088f59008d0964736f6c634300081d0033",
2511+
"number()(uint256)",
2512+
"--trace"
2513+
])
2514+
.assert_success()
2515+
.stderr_eq(str![[r#"
2516+
Error: Transaction failed.
2517+
24472518
"#]]);
24482519

24492520
// Calling `number1()` with overridden state should return new value.
@@ -2463,6 +2534,32 @@ Error: server returned an error response: error code 3: execution reverted, data
24632534
.stdout_eq(str![[r#"
24642535
8738
24652536
2537+
"#]]);
2538+
2539+
// Calling `number1()` with overridden state should return new value.
2540+
cmd.cast_fuse()
2541+
.args([
2542+
"call",
2543+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2544+
"--rpc-url",
2545+
&handle.http_endpoint(),
2546+
"--override-code",
2547+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063c223a39e14602a575b5f5ffd5b60306044565b604051603b9190605f565b60405180910390f35b5f5481565b5f819050919050565b6059816049565b82525050565b5f60208201905060705f8301846052565b9291505056fea26469706673582212202a0acfb9083efed3e0e9f27177b090731d4392cf196d58e27e05088f59008d0964736f6c634300081d0033",
2548+
"--override-state",
2549+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x2222",
2550+
"number1()(uint256)",
2551+
"--trace"
2552+
])
2553+
.assert_success()
2554+
.stdout_eq(str![[r#"
2555+
Traces:
2556+
[2402] 0x5FbDB2315678afecb367f032d93F642f64180aa3::number1()
2557+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000002222
2558+
2559+
2560+
Transaction successfully executed.
2561+
[GAS]
2562+
24662563
"#]]);
24672564

24682565
// Calling `number1()` with overridden state should return new value.
@@ -2482,6 +2579,32 @@ Error: server returned an error response: error code 3: execution reverted, data
24822579
.stdout_eq(str![[r#"
24832580
8738
24842581
2582+
"#]]);
2583+
2584+
// Calling `number1()` with overridden state should return new value.
2585+
cmd.cast_fuse()
2586+
.args([
2587+
"call",
2588+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2589+
"--rpc-url",
2590+
&handle.http_endpoint(),
2591+
"--override-code",
2592+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063c223a39e14602a575b5f5ffd5b60306044565b604051603b9190605f565b60405180910390f35b5f5481565b5f819050919050565b6059816049565b82525050565b5f60208201905060705f8301846052565b9291505056fea26469706673582212202a0acfb9083efed3e0e9f27177b090731d4392cf196d58e27e05088f59008d0964736f6c634300081d0033",
2593+
"--override-state-diff",
2594+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x2222",
2595+
"number1()(uint256)",
2596+
"--trace",
2597+
])
2598+
.assert_success()
2599+
.stdout_eq(str![[r#"
2600+
Traces:
2601+
[2402] 0x5FbDB2315678afecb367f032d93F642f64180aa3::number1()
2602+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000002222
2603+
2604+
2605+
Transaction successfully executed.
2606+
[GAS]
2607+
24852608
"#]]);
24862609
});
24872610

0 commit comments

Comments
 (0)