Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: separate integration tests #29

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
72 changes: 0 additions & 72 deletions crates/executor/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,75 +189,3 @@ impl<T: Transport + Clone, P: Provider<T> + Clone> HostExecutor<T, P> {
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::<EthereumVariant>("RPC_1", 18884864, "client_input_ethereum.json").await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_e2e_optimism() {
run_e2e::<OptimismVariant>("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::<ClientExecutorInput>(&serialized).unwrap();
assert_eq!(client_input, deserialized);
}

async fn run_e2e<V>(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::<V>(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();
}
}
57 changes: 57 additions & 0 deletions crates/executor/host/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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::<EthereumVariant>("RPC_1", 18884864).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_e2e_optimism() {
run_e2e::<OptimismVariant>("RPC_10", 122853660).await;
}

async fn run_e2e<V>(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::<V>(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();
}