Skip to content

Commit

Permalink
Introduce new feature (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 authored Aug 24, 2023
1 parent 7d0e0c8 commit e37f1f2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ink_primitives = { workspace = true, default-features = true }

cargo_metadata = { workspace = true }
contract-build = { workspace = true }
drink = { workspace = true }
drink = { workspace = true, optional = true }
funty = { workspace = true }
impl-serde = { workspace = true }
jsonrpsee = { workspace = true, features = ["ws-client"] }
Expand Down Expand Up @@ -50,3 +50,7 @@ scale-info = { workspace = true, features = ["derive"] }
[features]
default = ["std"]
std = []
drink = [
"dep:drink",
"ink_e2e_macro/drink",
]
3 changes: 3 additions & 0 deletions crates/e2e/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ syn = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
which = { workspace = true }

[features]
drink = []
2 changes: 2 additions & 0 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl InkE2ETest {

let client_building = match self.test.config.backend() {
Backend::Full => build_full_client(&environment, exec_build_contracts),
#[cfg(any(test, feature = "drink"))]
Backend::RuntimeOnly => build_runtime_client(exec_build_contracts),
};

Expand Down Expand Up @@ -144,6 +145,7 @@ fn build_full_client(environment: &syn::Path, contracts: TokenStream2) -> TokenS
}
}

#[cfg(any(test, feature = "drink"))]
fn build_runtime_client(contracts: TokenStream2) -> TokenStream2 {
quote! {
let contracts = #contracts;
Expand Down
9 changes: 9 additions & 0 deletions crates/e2e/macro/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub enum Backend {
///
/// This runs a runtime emulator within `TestExternalities` (using drink! library) in
/// the same process as the test.
#[cfg(any(test, feature = "drink"))]
RuntimeOnly,
}

Expand All @@ -38,7 +39,15 @@ impl TryFrom<syn::LitStr> for Backend {
fn try_from(value: syn::LitStr) -> Result<Self, Self::Error> {
match value.value().as_str() {
"full" => Ok(Self::Full),
#[cfg(any(test, feature = "drink"))]
"runtime_only" | "runtime-only" => Ok(Self::RuntimeOnly),
#[cfg(not(any(test, feature = "drink")))]
"runtime_only" | "runtime-only" => Err(
format_err_spanned!(
value,
"the `runtime-only` backend is not available because the `drink` feature is not enabled",
)
),
_ => {
Err(format_err_spanned!(
value,
Expand Down
2 changes: 2 additions & 0 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod builders;
mod client_utils;
mod contract_build;
mod contract_results;
#[cfg(feature = "drink")]
mod drink_client;
mod error;
pub mod events;
Expand All @@ -46,6 +47,7 @@ pub use contract_results::{
InstantiationResult,
UploadResult,
};
#[cfg(feature = "drink")]
pub use drink_client::Client as DrinkClient;
pub use ink_e2e_macro::test;
pub use node_proc::{
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/e2e-runtime-only-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ scale = { package = "parity-scale-codec", version = "3", default-features = fals
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink_e2e = { path = "../../crates/e2e" }
ink_e2e = { path = "../../crates/e2e", features = ["drink"] }

[lib]
path = "lib.rs"
Expand Down

0 comments on commit e37f1f2

Please sign in to comment.