Skip to content

Commit

Permalink
test: reenable and refactor solidity tests
Browse files Browse the repository at this point in the history
This refactors the solidity tests to use the `ForgeScript` type rather than the unstable `forge_script` crate.
  • Loading branch information
JayWhite2357 committed Oct 1, 2024
1 parent 77254da commit a5c5a67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/tests/mod.rs
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};
61 changes: 29 additions & 32 deletions crates/proof-of-sql/src/tests/sol_test.rs
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();
}

0 comments on commit a5c5a67

Please sign in to comment.