From 5bf07bb68eb82a0360b4d82774861d88c3a454cd Mon Sep 17 00:00:00 2001 From: jonas pauli Date: Mon, 7 Oct 2024 17:55:58 +0200 Subject: [PATCH] improved crate structure --- contract-tests/tests/spectre.rs | 38 ++++++++++----------- contract-tests/tests/step_input_encoding.rs | 23 +++++++------ contracts/README.md | 4 +++ 3 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 contracts/README.md diff --git a/contract-tests/tests/spectre.rs b/contract-tests/tests/spectre.rs index e7a7c2f..8d1ae38 100644 --- a/contract-tests/tests/spectre.rs +++ b/contract-tests/tests/spectre.rs @@ -6,28 +6,30 @@ * These are the highest level integration tests for the Spectre protocol * They treat the Spectre contract as an ethereum light-client and test against the spec */ -use std::path::PathBuf; -use std::sync::Arc; -use contract_tests::make_client; #[cfg(feature = "contracts")] -use contracts::{MockVerifier, Spectre}; -use eth_types::{Minimal, LIMB_BITS}; -use ethers::core::types::U256; -use ethers::providers::Middleware; -use halo2_base::halo2_proofs::halo2curves::bn256::Fr; -use lightclient_circuits::sync_step_circuit::StepCircuit; -use rstest::rstest; -use test_utils::{get_initial_sync_committee_poseidon, read_test_files_and_gen_witness}; - -const SLOTS_PER_EPOCH: usize = 8; -const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: usize = 8; -const SLOTS_PER_SYNC_COMMITTEE_PERIOD: usize = EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH; -const FINALITY_THRESHOLD: usize = 20; // ~ 2/3 of 32 +mod contract_integration { + use std::path::PathBuf; + use std::sync::Arc; + + use contract_tests::make_client; + use contracts::{MockVerifier, Spectre}; + use eth_types::{Minimal, LIMB_BITS}; + use ethers::core::types::U256; + use ethers::providers::Middleware; + use halo2_base::halo2_proofs::halo2curves::bn256::Fr; + use lightclient_circuits::sync_step_circuit::StepCircuit; + use rstest::rstest; + use test_utils::{get_initial_sync_committee_poseidon, read_test_files_and_gen_witness}; + const SLOTS_PER_EPOCH: usize = 8; + const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: usize = 8; + const SLOTS_PER_SYNC_COMMITTEE_PERIOD: usize = + EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH; + const FINALITY_THRESHOLD: usize = 20; // ~ 2/3 of 32 +} #[tokio::test] #[cfg(feature = "contracts")] - async fn test_deploy_spectre() -> anyhow::Result<()> { let (_anvil_instance, ethclient) = make_client(); let _contract = deploy_spectre_mock_verifiers(ethclient, 0, U256::zero(), 0).await?; @@ -37,7 +39,6 @@ async fn test_deploy_spectre() -> anyhow::Result<()> { #[rstest] #[tokio::test] #[cfg(feature = "contracts")] - async fn test_contract_initialization_and_first_step( #[files("../consensus-spec-tests/tests/minimal/capella/light_client/sync/pyspec_tests/**")] #[exclude("deneb*")] @@ -82,7 +83,6 @@ async fn test_contract_initialization_and_first_step( contract.execution_payload_roots(head).call().await?, step_input.execution_payload_root ); - Ok(()) } diff --git a/contract-tests/tests/step_input_encoding.rs b/contract-tests/tests/step_input_encoding.rs index c929a48..26be4df 100644 --- a/contract-tests/tests/step_input_encoding.rs +++ b/contract-tests/tests/step_input_encoding.rs @@ -2,17 +2,20 @@ // Code: https://github.com/ChainSafe/Spectre // SPDX-License-Identifier: LGPL-3.0-only -use std::ops::Deref; -use std::path::PathBuf; +#[cfg(feature = "contracts")] +mod contract_integration { + use std::ops::Deref; + use std::path::PathBuf; -use contract_tests::make_client; -use eth_types::{Minimal, LIMB_BITS}; -use ethers::contract::abigen; -use lightclient_circuits::halo2_proofs::halo2curves::bn256; -use lightclient_circuits::witness::SyncStepArgs; -use rstest::rstest; -use ssz_rs::Merkleized; -use test_utils::read_test_files_and_gen_witness; + use contract_tests::make_client; + use eth_types::{Minimal, LIMB_BITS}; + use ethers::contract::abigen; + use lightclient_circuits::halo2_proofs::halo2curves::bn256; + use lightclient_circuits::witness::SyncStepArgs; + use rstest::rstest; + use ssz_rs::Merkleized; + use test_utils::read_test_files_and_gen_witness; +} #[cfg(feature = "contracts")] abigen!( diff --git a/contracts/README.md b/contracts/README.md new file mode 100644 index 0000000..8d1dd21 --- /dev/null +++ b/contracts/README.md @@ -0,0 +1,4 @@ +# Running smart contract integration tests +When running the Spectre smart contract integration tests, replace this crate with [this crate](https://github.com/ChainSafe/spectre-contracts/tree/a430caeb3678582b73e3ee73b6f001bd9d1e75ca) + +Additionally make sure to enable the `contracts` feature when running tests against the real contracts crate. \ No newline at end of file