Skip to content

Commit 66a282b

Browse files
committed
feat: Add tests for cast call with --override-* and --trace flags
1 parent b5ae7a6 commit 66a282b

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
@@ -2430,6 +2430,30 @@ contract Counter {
24302430
.stdout_eq(str![[r#"
24312431
4660
24322432
2433+
"#]]);
2434+
2435+
// Override state, `number()` should return overridden value.
2436+
cmd.cast_fuse()
2437+
.args([
2438+
"call",
2439+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2440+
"--rpc-url",
2441+
&handle.http_endpoint(),
2442+
"--override-state",
2443+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x1234",
2444+
"number()(uint256)",
2445+
"--trace",
2446+
])
2447+
.assert_success()
2448+
.stdout_eq(str![[r#"
2449+
Traces:
2450+
[2402] 0x5FbDB2315678afecb367f032d93F642f64180aa3::number()
2451+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000001234
2452+
2453+
2454+
Transaction successfully executed.
2455+
[GAS]
2456+
24332457
"#]]);
24342458

24352459
// Override balance, `getBalance()` should return overridden value.
@@ -2448,6 +2472,31 @@ contract Counter {
24482472
.stdout_eq(str![[r#"
24492473
4369
24502474
2475+
"#]]);
2476+
2477+
// Override balance, `getBalance()` should return overridden value.
2478+
cmd.cast_fuse()
2479+
.args([
2480+
"call",
2481+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2482+
"--rpc-url",
2483+
&handle.http_endpoint(),
2484+
"--override-balance",
2485+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x1111",
2486+
"getBalance(address)(uint256)",
2487+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2488+
"--trace",
2489+
])
2490+
.assert_success()
2491+
.stdout_eq(str![[r#"
2492+
Traces:
2493+
[747] 0x5FbDB2315678afecb367f032d93F642f64180aa3::getBalance(0x5FbDB2315678afecb367f032d93F642f64180aa3)
2494+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000001111
2495+
2496+
2497+
Transaction successfully executed.
2498+
[GAS]
2499+
24512500
"#]]);
24522501

24532502
// Override code with
@@ -2469,6 +2518,28 @@ contract Counter {
24692518
.stderr_eq(str![[r#"
24702519
Error: server returned an error response: error code 3: execution reverted, data: "0x"
24712520
2521+
"#]]);
2522+
2523+
// Override code with
2524+
// contract Counter {
2525+
// uint256 public number1;
2526+
// }
2527+
// Calling `number()` should revert.
2528+
cmd.cast_fuse()
2529+
.args([
2530+
"call",
2531+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2532+
"--rpc-url",
2533+
&handle.http_endpoint(),
2534+
"--override-code",
2535+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063c223a39e14602a575b5f5ffd5b60306044565b604051603b9190605f565b60405180910390f35b5f5481565b5f819050919050565b6059816049565b82525050565b5f60208201905060705f8301846052565b9291505056fea26469706673582212202a0acfb9083efed3e0e9f27177b090731d4392cf196d58e27e05088f59008d0964736f6c634300081d0033",
2536+
"number()(uint256)",
2537+
"--trace"
2538+
])
2539+
.assert_success()
2540+
.stderr_eq(str![[r#"
2541+
Error: Transaction failed.
2542+
24722543
"#]]);
24732544

24742545
// Calling `number1()` with overridden state should return new value.
@@ -2488,6 +2559,32 @@ Error: server returned an error response: error code 3: execution reverted, data
24882559
.stdout_eq(str![[r#"
24892560
8738
24902561
2562+
"#]]);
2563+
2564+
// Calling `number1()` with overridden state should return new value.
2565+
cmd.cast_fuse()
2566+
.args([
2567+
"call",
2568+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2569+
"--rpc-url",
2570+
&handle.http_endpoint(),
2571+
"--override-code",
2572+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063c223a39e14602a575b5f5ffd5b60306044565b604051603b9190605f565b60405180910390f35b5f5481565b5f819050919050565b6059816049565b82525050565b5f60208201905060705f8301846052565b9291505056fea26469706673582212202a0acfb9083efed3e0e9f27177b090731d4392cf196d58e27e05088f59008d0964736f6c634300081d0033",
2573+
"--override-state",
2574+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x2222",
2575+
"number1()(uint256)",
2576+
"--trace"
2577+
])
2578+
.assert_success()
2579+
.stdout_eq(str![[r#"
2580+
Traces:
2581+
[2402] 0x5FbDB2315678afecb367f032d93F642f64180aa3::number1()
2582+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000002222
2583+
2584+
2585+
Transaction successfully executed.
2586+
[GAS]
2587+
24912588
"#]]);
24922589

24932590
// Calling `number1()` with overridden state should return new value.
@@ -2507,6 +2604,32 @@ Error: server returned an error response: error code 3: execution reverted, data
25072604
.stdout_eq(str![[r#"
25082605
8738
25092606
2607+
"#]]);
2608+
2609+
// Calling `number1()` with overridden state should return new value.
2610+
cmd.cast_fuse()
2611+
.args([
2612+
"call",
2613+
"0x5FbDB2315678afecb367f032d93F642f64180aa3",
2614+
"--rpc-url",
2615+
&handle.http_endpoint(),
2616+
"--override-code",
2617+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c8063c223a39e14602a575b5f5ffd5b60306044565b604051603b9190605f565b60405180910390f35b5f5481565b5f819050919050565b6059816049565b82525050565b5f60208201905060705f8301846052565b9291505056fea26469706673582212202a0acfb9083efed3e0e9f27177b090731d4392cf196d58e27e05088f59008d0964736f6c634300081d0033",
2618+
"--override-state-diff",
2619+
"0x5FbDB2315678afecb367f032d93F642f64180aa3:0x0:0x2222",
2620+
"number1()(uint256)",
2621+
"--trace",
2622+
])
2623+
.assert_success()
2624+
.stdout_eq(str![[r#"
2625+
Traces:
2626+
[2402] 0x5FbDB2315678afecb367f032d93F642f64180aa3::number1()
2627+
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000002222
2628+
2629+
2630+
Transaction successfully executed.
2631+
[GAS]
2632+
25102633
"#]]);
25112634
});
25122635

0 commit comments

Comments
 (0)