|
| 1 | +use foundry_config::Config; |
1 | 2 | use foundry_test_utils::util::OutputExt;
|
2 | 3 | use std::path::Path;
|
3 | 4 |
|
| 5 | +// <https://github.com/foundry-rs/foundry/issues/11125> |
4 | 6 | casttest!(error_decode_with_openchain, |prj, cmd| {
|
5 | 7 | prj.clear_cache();
|
| 8 | + |
6 | 9 | cmd.args(["decode-error", "0x7a0e198500000000000000000000000000000000000000000000000000000000000000650000000000000000000000000000000000000000000000000000000000000064"]).assert_success().stdout_eq(str![[r#"
|
7 | 10 | ValueTooHigh(uint256,uint256)
|
8 | 11 | 101
|
9 | 12 | 100
|
10 | 13 |
|
11 | 14 | "#]]);
|
| 15 | + |
| 16 | + // Read cache to ensure the error is cached |
| 17 | + assert_eq!( |
| 18 | + read_error_cache().get("0x7a0e1985"), |
| 19 | + Some(&serde_json::Value::String("ValueTooHigh(uint256,uint256)".to_string())), |
| 20 | + "Selector should be cached" |
| 21 | + ); |
| 22 | +}); |
| 23 | + |
| 24 | +// <https://github.com/foundry-rs/foundry/issues/11125> |
| 25 | +// NOTE: if a user does happen to mine and submit 0x37d01491 this is expected to fail. |
| 26 | +casttest!(error_decode_with_openchain_nonexistent, |prj, cmd| { |
| 27 | + prj.clear_cache(); |
| 28 | + |
| 29 | + cmd.args(["decode-error", "0x37d0149100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"]).assert_failure().stderr_eq(str![[r#" |
| 30 | +Error: No matching error signature found for selector `37d01491` |
| 31 | +
|
| 32 | +"#]]); |
| 33 | + |
| 34 | + // Read cache to ensure the error is not cached |
| 35 | + assert_eq!(read_error_cache().get("0x37d01491"), None, "Selector should not be cached"); |
12 | 36 | });
|
13 | 37 |
|
| 38 | +/// Read the errors section from the signatures cache in the global foundry cache directory. |
| 39 | +fn read_error_cache() -> serde_json::Value { |
| 40 | + let cache = Config::foundry_cache_dir().unwrap().join("signatures"); |
| 41 | + let contents = std::fs::read_to_string(cache).unwrap(); |
| 42 | + let cache_json: serde_json::Value = serde_json::from_str(&contents).unwrap(); |
| 43 | + cache_json.get("errors").cloned().unwrap_or_default() |
| 44 | +} |
| 45 | + |
14 | 46 | casttest!(fourbyte, |_prj, cmd| {
|
15 | 47 | cmd.args(["4byte", "0xa9059cbb"]).assert_success().stdout_eq(str![[r#"
|
16 | 48 | transfer(address,uint256)
|
|
0 commit comments