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

Merge runtime / runtime-only #1968

Merged
merged 5 commits into from
Nov 3, 2023
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
4 changes: 2 additions & 2 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ 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, self.test.config.runtime())
Backend::RuntimeOnly { runtime } => {
build_runtime_client(exec_build_contracts, runtime)
}
};

Expand Down
40 changes: 22 additions & 18 deletions crates/e2e/macro/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
// limitations under the License.

/// The type of the architecture that should be used to run test.
#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, darling::FromMeta)]
#[derive(Clone, Eq, PartialEq, Debug, Default, darling::FromMeta)]
#[darling(rename_all = "snake_case")]
pub enum Backend {
/// The standard approach with running dedicated single-node blockchain in a
/// background process.
#[default]
Full,

/// The lightweight approach skipping node layer.
///
/// This runs a runtime emulator within `TestExternalities` (using drink! library) in
/// the same process as the test.
#[cfg(any(test, feature = "drink"))]
RuntimeOnly,
RuntimeOnly { runtime: Option<syn::Path> },
}

/// The End-to-End test configuration.
Expand All @@ -44,10 +46,6 @@ pub struct E2EConfig {
/// The type of the architecture that should be used to run test.
#[darling(default)]
backend: Backend,
/// The runtime to use for the runtime only test.
#[cfg(any(test, feature = "drink"))]
#[darling(default)]
runtime: Option<syn::Path>,
}

impl E2EConfig {
Expand All @@ -73,13 +71,7 @@ impl E2EConfig {

/// The type of the architecture that should be used to run test.
pub fn backend(&self) -> Backend {
self.backend
}

/// The runtime to use for the runtime only test.
#[cfg(any(test, feature = "drink"))]
pub fn runtime(&self) -> Option<syn::Path> {
self.runtime.clone()
self.backend.clone()
}
}

Expand All @@ -97,8 +89,7 @@ mod tests {
let input = quote! {
additional_contracts = "adder/Cargo.toml flipper/Cargo.toml",
environment = crate::CustomEnvironment,
backend = "runtime_only",
runtime = ::drink::MinimalRuntime,
backend(runtime_only()),
};
let config =
E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap();
Expand All @@ -111,10 +102,23 @@ mod tests {
config.environment(),
Some(syn::parse_quote! { crate::CustomEnvironment })
);
assert_eq!(config.backend(), Backend::RuntimeOnly);

assert_eq!(config.backend(), Backend::RuntimeOnly { runtime: None });
}

#[test]
fn config_works_with_custom_backend() {
let input = quote! {
backend(runtime_only(runtime = ::ink_e2e::MinimalRuntime)),
};
let config =
E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap();

assert_eq!(
config.runtime(),
Some(syn::parse_quote! { ::drink::MinimalRuntime })
config.backend(),
Backend::RuntimeOnly {
runtime: Some(syn::parse_quote! { ::ink_e2e::MinimalRuntime })
}
);
}
}
6 changes: 3 additions & 3 deletions integration-tests/e2e-runtime-only-backend/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub mod flipper {
/// - flip the flipper
/// - get the flipper's value
/// - assert that the value is `true`
#[ink_e2e::test(backend = "runtime_only")]
#[ink_e2e::test(backend(runtime_only()))]
async fn it_works<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
// given
const INITIAL_VALUE: bool = false;
Expand Down Expand Up @@ -115,7 +115,7 @@ pub mod flipper {
/// - transfer some funds to the contract using runtime call
/// - get the contract's balance again
/// - assert that the contract's balance increased by the transferred amount
#[ink_e2e::test(backend = "runtime_only")]
#[ink_e2e::test(backend(runtime_only()))]
async fn runtime_call_works() -> E2EResult<()> {
// given
let contract = deploy(&mut client, false).await.expect("deploy failed");
Expand Down Expand Up @@ -156,7 +156,7 @@ pub mod flipper {
}

/// Just instantiate a contract using non-default runtime.
#[ink_e2e::test(backend = "runtime_only", runtime = ink_e2e::MinimalRuntime)]
#[ink_e2e::test(backend(runtime_only(runtime = ink_e2e::MinimalRuntime)))]
async fn custom_runtime<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
client
.instantiate(
Expand Down