-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
contract Foo { | ||
function revert_me() public pure returns(uint){ | ||
revert("Not enough Ether provided."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Solidity test that help us prove assumptions about how Solidty handles | ||
//! certain things | ||
|
||
#![cfg(feature = "solc-backend")] | ||
use rstest::rstest; | ||
|
||
mod utils; | ||
use utils::*; | ||
|
||
#[test] | ||
fn test_revert_string_reason() { | ||
with_executor(&|mut executor| { | ||
let harness = deploy_solidity_contract(&mut executor, "revert_test.sol", "Foo", &[]); | ||
|
||
let exit = harness.capture_call(&mut executor, "revert_me", &[]); | ||
|
||
let expected_reason = format!( | ||
"0x{}", | ||
hex::encode(encode_error_reason("Not enough Ether provided.")) | ||
); | ||
if let evm::Capture::Exit((evm::ExitReason::Revert(_), output)) = exit { | ||
assert_eq!(format!("0x{}", hex::encode(&output)), expected_reason); | ||
} else { | ||
panic!("failed") | ||
}; | ||
}) | ||
} | ||
|
||
#[rstest(reason_str, expected_encoding, | ||
case("Not enough Ether provided.", "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001a4e6f7420656e6f7567682045746865722070726f76696465642e000000000000"), | ||
case("A muuuuuch longer reason string that consumes multiple words", "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003c41206d75757575756368206c6f6e67657220726561736f6e20737472696e67207468617420636f6e73756d6573206d756c7469706c6520776f72647300000000"), | ||
)] | ||
fn test_reason_encoding(reason_str: &str, expected_encoding: &str) { | ||
let encoded = encode_error_reason(reason_str); | ||
assert_eq!(format!("0x{}", hex::encode(&encoded)), expected_encoding); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters