Skip to content

Commit

Permalink
hide contract integration tests behind a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas089 committed Oct 7, 2024
1 parent 085bff7 commit 1f89e37
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
"preprocessor",
"eth-types",
"contract-tests",
"test-utils",
"test-utils", "contracts",
]

resolver = "2"
Expand Down Expand Up @@ -35,6 +35,7 @@ lightclient-circuits = { path = "lightclient-circuits" }
test-utils = { path = "test-utils" }

eth-types = { path = "eth-types" }
contracts = { path = "contracts" }
preprocessor = { path = "preprocessor" }


Expand Down
6 changes: 5 additions & 1 deletion contract-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ edition = "2021"
[dependencies]
ethers = "2.0.10"
lightclient-circuits = { workspace = true }
contracts = { path = "../contracts", optional = true }

[features]
contracts = ["dep:contracts"]


[dev-dependencies]
rstest = "0.18.2"
Expand All @@ -19,4 +24,3 @@ eth-types = { workspace = true }
ssz_rs = { workspace = true }
halo2-base = { workspace = true }
snark-verifier-sdk = { workspace = true }
contracts = { git = "https://github.com/jonas089/spectre-contracts" }
6 changes: 6 additions & 0 deletions contract-tests/tests/spectre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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;
Expand All @@ -25,6 +26,8 @@ const SLOTS_PER_SYNC_COMMITTEE_PERIOD: usize = EPOCHS_PER_SYNC_COMMITTEE_PERIOD
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?;
Expand All @@ -33,6 +36,8 @@ 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*")]
Expand Down Expand Up @@ -86,6 +91,7 @@ async fn test_contract_initialization_and_first_step(
/// Deploy the Spectre contract using the given ethclient
/// Also deploys the step verifier and the update verifier contracts
/// and passes their addresses along with the other params to the constructor
#[cfg(feature = "contracts")]
async fn deploy_spectre_mock_verifiers<M: Middleware + 'static>(
ethclient: Arc<M>,
initial_sync_period: usize,
Expand Down
3 changes: 3 additions & 0 deletions contract-tests/tests/step_input_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ use rstest::rstest;
use ssz_rs::Merkleized;
use test_utils::read_test_files_and_gen_witness;

#[cfg(feature = "contracts")]
abigen!(
StepExternal,
"../contracts/out/StepExternal.sol/StepExternal.json";
);

#[cfg(feature = "contracts")]
// SyncStepInput type produced by abigen macro matches the solidity struct type
impl<Spec: eth_types::Spec> From<SyncStepArgs<Spec>> for StepInput {
fn from(args: SyncStepArgs<Spec>) -> Self {
Expand Down Expand Up @@ -51,6 +53,7 @@ impl<Spec: eth_types::Spec> From<SyncStepArgs<Spec>> for StepInput {

#[rstest]
#[tokio::test]
#[cfg(feature = "contracts")]
async fn test_step_instance_commitment_evm_equivalence(
#[files("../consensus-spec-tests/tests/minimal/capella/light_client/sync/pyspec_tests/**")]
#[exclude("deneb*")]
Expand Down
8 changes: 8 additions & 0 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "contracts"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
1 change: 1 addition & 0 deletions contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// replace this crate with the actual contracts crate to run integration tests

0 comments on commit 1f89e37

Please sign in to comment.