diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 426370f..6ef60fa 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -32,3 +32,38 @@ jobs: echo "Lock files not up to date" exit 1 fi + + tests: + name: "Run tests" + runs-on: + ["runs-on", "runner=64cpu-linux-x64", "run-id=${{ github.run_id }}"] + env: + CARGO_NET_GIT_FETCH_WITH_CLI: "true" + steps: + - name: "Checkout sources" + uses: "actions/checkout@v4" + + - name: "Install sp1up" + run: | + curl -L https://sp1.succinct.xyz | bash + echo "$HOME/.sp1/bin" >> $GITHUB_PATH + + - name: "Install SP1 toolchain" + run: | + sp1up + + - name: "Set up test fixture" + run: | + git clone https://github.com/succinctlabs/rsp-tests --branch 2024-08-26 --depth 1 ../rsp-tests + cd ../rsp-tests/ + docker compose up -d + + - name: "Use local test fixture" + run: | + echo "RPC_1=http://localhost:9545/main/evm/1" >> $GITHUB_ENV + echo "RPC_10=http://localhost:9545/main/evm/10" >> $GITHUB_ENV + + - name: "Run tests" + run: | + export RUST_LOG=info + cargo test --all -- --nocapture diff --git a/README.md b/README.md index 9c03442..b66570f 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ geth \ When running the host CLI or integration tests, **make sure to use an RPC URL pointing to a Geth node running with said options**, or errors will arise when preimage recovery is needed. You can reach out to the Succinct team to access an RPC URL that supports this endpoint. +> [!TIP] +> +> Don't have access to such a node but still want to try out RSP? Use [`rsp-tests`](https://github.com/succinctlabs/rsp-tests) to get quickly set up with an offline cache built for selected blocks. + ### Running the CLI The host CLI automatically identifies the underlying chain type using the RPC (with the `eth_chainId` call). Simply suppply a block number and an RPC URL: diff --git a/crates/executor/host/src/lib.rs b/crates/executor/host/src/lib.rs index dec5c37..ef19c8a 100644 --- a/crates/executor/host/src/lib.rs +++ b/crates/executor/host/src/lib.rs @@ -189,75 +189,3 @@ impl + Clone> HostExecutor { Ok(client_input) } } - -#[cfg(test)] -mod tests { - use super::*; - - use alloy_provider::ReqwestProvider; - use rsp_client_executor::ClientExecutor; - use tracing_subscriber::{ - filter::EnvFilter, fmt, prelude::__tracing_subscriber_SubscriberExt, - util::SubscriberInitExt, - }; - use url::Url; - - #[tokio::test(flavor = "multi_thread")] - async fn test_e2e_ethereum() { - run_e2e::("RPC_1", 18884864, "client_input_ethereum.json").await; - } - - #[tokio::test(flavor = "multi_thread")] - async fn test_e2e_optimism() { - run_e2e::("RPC_10", 122853660, "client_input_optimism.json").await; - } - - #[test] - fn test_input_bincode_roundtrip() { - let file = std::fs::File::open("client_input_ethereum.json").unwrap(); - let client_input: ClientExecutorInput = serde_json::from_reader(file).unwrap(); - let serialized = bincode::serialize(&client_input).unwrap(); - let deserialized = bincode::deserialize::(&serialized).unwrap(); - assert_eq!(client_input, deserialized); - } - - async fn run_e2e(env_var_key: &str, block_number: u64, input_file: &str) - where - V: Variant, - { - // Intialize the environment variables. - dotenv::dotenv().ok(); - - // Initialize the logger. - let _ = tracing_subscriber::registry() - .with(fmt::layer()) - .with(EnvFilter::from_default_env()) - .try_init(); - - // Setup the provider. - let rpc_url = - Url::parse(std::env::var(env_var_key).unwrap().as_str()).expect("invalid rpc url"); - let provider = ReqwestProvider::new_http(rpc_url); - - // Setup the host executor. - let host_executor = HostExecutor::new(provider); - - // Execute the host. - let (client_input, _) = - host_executor.execute(block_number).await.expect("failed to execute host"); - - // Setup the client executor. - let client_executor = ClientExecutor; - - // Execute the client. - client_executor.execute::(client_input.clone()).expect("failed to execute client"); - - // Save the client input to a file. - let file = std::fs::File::create(input_file).unwrap(); - serde_json::to_writer_pretty(file, &client_input).unwrap(); - - // Load the client input from a file. - let file = std::fs::File::open(input_file).unwrap(); - let _: ClientExecutorInput = serde_json::from_reader(file).unwrap(); - } -} diff --git a/crates/executor/host/tests/integration.rs b/crates/executor/host/tests/integration.rs new file mode 100644 index 0000000..6c89129 --- /dev/null +++ b/crates/executor/host/tests/integration.rs @@ -0,0 +1,57 @@ +use alloy_provider::ReqwestProvider; +use rsp_client_executor::{ + io::ClientExecutorInput, ClientExecutor, EthereumVariant, OptimismVariant, Variant, +}; +use rsp_host_executor::HostExecutor; +use tracing_subscriber::{ + filter::EnvFilter, fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, +}; +use url::Url; + +#[tokio::test(flavor = "multi_thread")] +async fn test_e2e_ethereum() { + run_e2e::("RPC_1", 18884864).await; +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_e2e_optimism() { + run_e2e::("RPC_10", 122853660).await; +} + +async fn run_e2e(env_var_key: &str, block_number: u64) +where + V: Variant, +{ + // Intialize the environment variables. + dotenv::dotenv().ok(); + + // Initialize the logger. + let _ = tracing_subscriber::registry() + .with(fmt::layer()) + .with(EnvFilter::from_default_env()) + .try_init(); + + // Setup the provider. + let rpc_url = + Url::parse(std::env::var(env_var_key).unwrap().as_str()).expect("invalid rpc url"); + let provider = ReqwestProvider::new_http(rpc_url); + + // Setup the host executor. + let host_executor = HostExecutor::new(provider); + + // Execute the host. + let (client_input, _) = + host_executor.execute(block_number).await.expect("failed to execute host"); + + // Setup the client executor. + let client_executor = ClientExecutor; + + // Execute the client. + client_executor.execute::(client_input.clone()).expect("failed to execute client"); + + // Save the client input to a buffer. + let buffer = bincode::serialize(&client_input).unwrap(); + + // Load the client input from a buffer. + let _: ClientExecutorInput = bincode::deserialize(&buffer).unwrap(); +}