-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: reenable and refactor solidity tests
This refactors the solidity tests to use the `ForgeScript` type rather than the unstable `forge_script` crate.
- Loading branch information
1 parent
77254da
commit a5c5a67
Showing
2 changed files
with
30 additions
and
33 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// mod sol_test; | ||
mod sol_test; | ||
mod sol_test_util; | ||
pub(crate) use sol_test_util::{ForgeScript, ForgeScriptError}; |
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 |
---|---|---|
@@ -1,42 +1,39 @@ | ||
use alloy_primitives::{Bytes, U256}; | ||
use alloy_sol_types::{sol, SolValue}; | ||
use forge_script::ScriptArgs; | ||
use crate::tests::{ForgeScript, ForgeScriptError}; | ||
use alloy_sol_types::{private::primitives::U256, sol}; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn we_can_run_solidity_script_from_rust() { | ||
ScriptArgs { | ||
path: "./sol_src/tests/TestScript.t.sol".to_string(), | ||
sig: "rustTestWeCanThrowErrorDependingOnParameter".to_string(), | ||
args: vec![U256::from(1234).to_string()], | ||
..Default::default() | ||
} | ||
.run_script() | ||
.await | ||
#[test] | ||
#[ignore = "Because forge needs to be installed, we are ignoring this test by default. They will still be run from within the ci."] | ||
fn we_can_run_solidity_script_from_rust() { | ||
ForgeScript::new( | ||
"./sol_src/tests/TestScript.t.sol", | ||
"rustTestWeCanThrowErrorDependingOnParameter", | ||
) | ||
.arg(U256::from(1234)) | ||
.execute() | ||
.unwrap(); | ||
|
||
assert!(ScriptArgs { | ||
path: "./sol_src/tests/TestScript.t.sol".to_string(), | ||
sig: "rustTestWeCanThrowErrorDependingOnParameter".to_string(), | ||
args: vec![U256::from(0).to_string()], | ||
..Default::default() | ||
} | ||
.run_script() | ||
.await | ||
.is_err()); | ||
assert!(matches!( | ||
ForgeScript::new( | ||
"./sol_src/tests/TestScript.t.sol", | ||
"rustTestWeCanThrowErrorDependingOnParameter", | ||
) | ||
.arg(U256::from(0)) | ||
.execute(), | ||
Err(ForgeScriptError::SolidityError { .. }) | ||
)); | ||
} | ||
#[tokio::test(flavor = "multi_thread")] | ||
async fn we_can_pass_custom_struct_into_solidity_from_rust() { | ||
#[test] | ||
#[ignore = "Because forge needs to be installed, we are ignoring this test by default. They will still be run from within the ci."] | ||
fn we_can_pass_custom_struct_into_solidity_from_rust() { | ||
sol!("./sol_src/tests/TestScript.t.sol"); | ||
let arg = TestScript::CustomStruct { | ||
value: U256::from(1234), | ||
}; | ||
ScriptArgs { | ||
path: "./sol_src/tests/TestScript.t.sol".to_string(), | ||
sig: "rustTestWeCanAcceptCustomStructAsEncodedBytes".to_string(), | ||
args: vec![Bytes::from(arg.abi_encode()).to_string()], | ||
..Default::default() | ||
} | ||
.run_script() | ||
.await | ||
ForgeScript::new( | ||
"./sol_src/tests/TestScript.t.sol", | ||
"rustTestWeCanAcceptCustomStructAsEncodedBytes", | ||
) | ||
.arg(arg) | ||
.execute() | ||
.unwrap(); | ||
} |