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

Improve syntax for ink! e2e runtime_only attribute argument #2083

Merged
merged 2 commits into from
Jan 30, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Linter: Publish the linting crates on crates.io - [#2060](https://github.com/paritytech/ink/pull/2060)
- [E2E] Added `create_call_builder` for testing existing contracts - [#2075](https://github.com/paritytech/ink/pull/2075)

### Changed
- Improve syntax for ink! e2e `runtime_only` attribute argument - [#2083](https://github.com/paritytech/ink/pull/2083)

### Fixed
- Fix the `StorageVec` type by excluding the `len_cached` field from its type info - [#2052](https://github.com/paritytech/ink/pull/2052)

Expand Down
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ blake2 = { version = "0.10" }
cargo_metadata = { version = "0.18.0" }
cfg-if = { version = "1.0" }
contract-build = { version = "4.0.0-rc.1" }
darling = { version = "0.20.3" }
darling = { version = "0.20.4" }
derive_more = { version = "0.99.17", default-features = false }
drink = { version = "=0.8.5" }
either = { version = "1.5", default-features = false }
Expand Down
11 changes: 3 additions & 8 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl InkE2ETest {
build_full_client(&environment, exec_build_contracts, node_url)
}
#[cfg(any(test, feature = "drink"))]
Backend::RuntimeOnly { runtime } => {
build_runtime_client(exec_build_contracts, runtime)
Backend::RuntimeOnly(runtime) => {
build_runtime_client(exec_build_contracts, runtime.into())
}
};

Expand Down Expand Up @@ -154,12 +154,7 @@ fn build_full_client(
}

#[cfg(any(test, feature = "drink"))]
fn build_runtime_client(
contracts: TokenStream2,
runtime: Option<syn::Path>,
) -> TokenStream2 {
let runtime =
runtime.unwrap_or_else(|| syn::parse_quote! { ::ink_e2e::MinimalRuntime });
fn build_runtime_client(contracts: TokenStream2, runtime: syn::Path) -> TokenStream2 {
quote! {
let contracts = #contracts;
let mut client = ::ink_e2e::DrinkClient::<_, _, #runtime>::new(contracts);
Expand Down
32 changes: 26 additions & 6 deletions crates/e2e/macro/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,27 @@ 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 { runtime: Option<syn::Path> },
RuntimeOnly(RuntimeOnly),
}

/// The runtime emulator that should be used within `TestExternalities` (using drink!
/// library).
#[cfg(any(test, feature = "drink"))]
#[derive(Clone, Eq, PartialEq, Debug, darling::FromMeta)]
pub enum RuntimeOnly {
#[darling(word)]
Default,
Runtime(syn::Path),
}

#[cfg(any(test, feature = "drink"))]
impl From<RuntimeOnly> for syn::Path {
fn from(value: RuntimeOnly) -> Self {
match value {
RuntimeOnly::Default => syn::parse_quote! { ::ink_e2e::MinimalRuntime },
RuntimeOnly::Runtime(path) => path,
}
}
}

/// The End-to-End test configuration.
Expand Down Expand Up @@ -100,7 +120,7 @@ mod tests {
let input = quote! {
additional_contracts = "adder/Cargo.toml flipper/Cargo.toml",
environment = crate::CustomEnvironment,
backend(runtime_only()),
backend(runtime_only),
node_url = "ws://127.0.0.1:8000"
};
let config =
Expand All @@ -115,7 +135,7 @@ mod tests {
Some(syn::parse_quote! { crate::CustomEnvironment })
);

assert_eq!(config.backend(), Backend::RuntimeOnly { runtime: None });
assert_eq!(config.backend(), Backend::RuntimeOnly(RuntimeOnly::Default));
assert_eq!(config.node_url(), Some(String::from("ws://127.0.0.1:8000")));

std::env::set_var("CONTRACTS_NODE_URL", "ws://127.0.0.1:9000");
Expand All @@ -132,9 +152,9 @@ mod tests {

assert_eq!(
config.backend(),
Backend::RuntimeOnly {
runtime: Some(syn::parse_quote! { ::ink_e2e::MinimalRuntime })
}
Backend::RuntimeOnly(RuntimeOnly::Runtime(
syn::parse_quote! { ::ink_e2e::MinimalRuntime }
))
);
assert_eq!(config.node_url(), None)
}
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/e2e-runtime-only-backend/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 @@ -88,7 +88,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 mut constructor = FlipperRef::new(false);
Expand Down
Loading