diff --git a/crates/runner/Cargo.toml b/crates/runner/Cargo.toml index 6008e2d..c4efd9c 100644 --- a/crates/runner/Cargo.toml +++ b/crates/runner/Cargo.toml @@ -7,6 +7,10 @@ repository.workspace = true authors.workspace = true description = "Execute revive contracts in a simulated blockchain runtime" +[features] +default = ["solidity"] +solidity = ["revive-solidity", "revive-differential"] + [dependencies] serde = { workspace = true } serde_json = { workspace = true } @@ -24,5 +28,5 @@ polkadot-sdk.features = [ "pallet-timestamp" ] -revive-solidity = { workspace = true } -revive-differential = { workspace = true } +revive-solidity = { workspace = true, optional = true } +revive-differential = { workspace = true, optional = true } diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs index a988ffb..ece3d32 100644 --- a/crates/runner/src/lib.rs +++ b/crates/runner/src/lib.rs @@ -44,6 +44,10 @@ pub use crate::specs::*; mod runtime; mod specs; +#[cfg(not(feature = "revive-solidity"))] +pub(crate) const NO_SOLIDITY_FRONTEND: &str = + "revive-runner was built without the solidity frontend; please enable the 'solidity' feature!"; + /// The alice test account pub const ALICE: H160 = H160([1u8; 20]); /// The bob test account @@ -218,6 +222,7 @@ impl CallResult { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum Code { + #[cfg(feature = "revive-solidity")] /// Compile a single solidity source and use the blob of `contract` Solidity { path: Option, @@ -242,6 +247,7 @@ impl Default for Code { impl From for pallet_revive::Code { fn from(val: Code) -> Self { match val { + #[cfg(feature = "solidity")] Code::Solidity { path, contract, diff --git a/crates/runner/src/specs.rs b/crates/runner/src/specs.rs index cd6f13d..e2941b7 100644 --- a/crates/runner/src/specs.rs +++ b/crates/runner/src/specs.rs @@ -1,11 +1,13 @@ use std::time::Instant; use pallet_revive::AddressMapper; -use revive_differential::{Evm, EvmLog}; use serde::{Deserialize, Serialize}; use crate::*; use alloy_primitives::Address; +#[cfg(feature = "revive-solidity")] +use revive_differential::{Evm, EvmLog}; +#[cfg(feature = "revive-solidity")] use revive_solidity::test_utils::*; const SPEC_MARKER_BEGIN: &str = "/* runner.json"; @@ -72,6 +74,7 @@ pub enum SpecsAction { }, } +#[cfg(feature = "solidity")] impl SpecsAction { /// Derive verification actions from the EVM output log pub fn derive_verification( @@ -219,6 +222,7 @@ impl Specs { }; match code { + #[cfg(feature = "revive-solidity")] Code::Bytes(bytes) if bytes.is_empty() => { let contract_source = match std::fs::read_to_string(contract_path) { Err(err) => panic!("unable to read {contract_path}: {err}"), @@ -226,6 +230,9 @@ impl Specs { }; *bytes = compile_blob(contract_name, &contract_source) } + #[cfg(not(feature = "revive-solidity"))] + Code::Bytes(_) => panic!("{NO_SOLIDITY_FRONTEND}"), + #[cfg(feature = "revive-solidity")] Code::Solidity { path, .. } if path.is_none() => *path = Some(contract_path.into()), _ => continue, } @@ -236,6 +243,9 @@ impl Specs { /// The test takes a [`Specs`] and executes the actions in order pub fn run(self) -> Vec { if self.differential { + #[cfg(not(feature = "solidity"))] + panic!("{NO_SOLIDITY_FRONTEND}"); + #[cfg(feature = "solidity")] self.run_on_evm() } else { self @@ -243,6 +253,7 @@ impl Specs { .run_on_pallet() } + #[cfg(feature = "solidity")] fn run_on_evm(self) -> Self { let mut derived_specs = Self { actions: vec![],