From e67b2bd6c819068f8632b37494e0c16077f977ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 30 Jun 2023 12:53:32 +0200 Subject: [PATCH 1/8] Remove `whitelisted_attributes` from E2EConfig --- crates/e2e/macro/src/config.rs | 39 ++-------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/crates/e2e/macro/src/config.rs b/crates/e2e/macro/src/config.rs index 425af650477..1c4da1bdf84 100644 --- a/crates/e2e/macro/src/config.rs +++ b/crates/e2e/macro/src/config.rs @@ -15,17 +15,12 @@ use ink_ir::{ ast, format_err_spanned, - utils::{ - duplicate_config_err, - WhitelistedAttributes, - }, + utils::duplicate_config_err, }; /// The End-to-End test configuration. #[derive(Debug, Default, PartialEq, Eq)] pub struct E2EConfig { - /// The set of attributes that can be passed to call builder in the codegen. - whitelisted_attributes: WhitelistedAttributes, /// Additional contracts that have to be built before executing the test. additional_contracts: Vec, /// The [`Environment`](https://docs.rs/ink_env/4.1.0/ink_env/trait.Environment.html) to use @@ -41,14 +36,11 @@ impl TryFrom for E2EConfig { type Error = syn::Error; fn try_from(args: ast::AttributeArgs) -> Result { - let mut whitelisted_attributes = WhitelistedAttributes::default(); let mut additional_contracts: Option<(syn::LitStr, ast::MetaNameValue)> = None; let mut environment: Option<(syn::Path, ast::MetaNameValue)> = None; for arg in args.into_iter() { - if arg.name.is_ident("keep_attr") { - whitelisted_attributes.parse_arg_value(&arg)?; - } else if arg.name.is_ident("additional_contracts") { + if arg.name.is_ident("additional_contracts") { if let Some((_, ast)) = additional_contracts { return Err(duplicate_config_err( ast, @@ -91,7 +83,6 @@ impl TryFrom for E2EConfig { Ok(E2EConfig { additional_contracts, - whitelisted_attributes, environment, }) } @@ -197,7 +188,6 @@ mod tests { environment = crate::CustomEnvironment, }, Ok(E2EConfig { - whitelisted_attributes: Default::default(), additional_contracts: vec![ "adder/Cargo.toml".into(), "flipper/Cargo.toml".into(), @@ -206,29 +196,4 @@ mod tests { }), ); } - - #[test] - fn keep_attr_works() { - let mut attrs = WhitelistedAttributes::default(); - attrs.0.insert("foo".to_string(), ()); - attrs.0.insert("bar".to_string(), ()); - assert_try_from( - syn::parse_quote! { - keep_attr = "foo, bar" - }, - Ok(E2EConfig { - whitelisted_attributes: attrs, - additional_contracts: Vec::new(), - environment: None, - }), - ) - } - - #[test] - fn keep_attr_invalid_value_fails() { - assert_try_from( - syn::parse_quote! { keep_attr = 1u16 }, - Err("expected a string with attributes separated by `,`"), - ); - } } From a579f03adbe1777b5fad6f69f566e5872788e720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 30 Jun 2023 13:04:28 +0200 Subject: [PATCH 2/8] Simplify building control --- crates/e2e/macro/src/codegen.rs | 40 ++++++++++----------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index fb81939c4c1..0c04519feab 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -21,14 +21,7 @@ use core::cell::RefCell; use derive_more::From; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use std::{ - collections::HashMap, - sync::Once, -}; - -/// We use this to only build the contracts once for all tests, at the -/// time of generating the Rust code for the tests, so at compile time. -static BUILD_ONCE: Once = Once::new(); +use std::collections::HashMap; thread_local! { // We save a mapping of `contract_manifest_path` to the built `*.contract` files. @@ -99,27 +92,18 @@ impl InkE2ETest { let mut already_built_contracts = already_built_contracts(); if already_built_contracts.is_empty() { - // Build all of them for the first time and initialize everything - BUILD_ONCE.call_once(|| { - tracing_subscriber::fmt::init(); - for manifest_path in contracts_to_build_and_import { - let dest_wasm = build_contract(&manifest_path); - let _ = already_built_contracts.insert(manifest_path, dest_wasm); - } - set_already_built_contracts(already_built_contracts.clone()); - }); - } else if !already_built_contracts.is_empty() { - // Some contracts have already been built and we check if the - // `additional_contracts` for this particular test contain ones - // that haven't been build before - for manifest_path in contracts_to_build_and_import { - if already_built_contracts.get(&manifest_path).is_none() { - let dest_wasm = build_contract(&manifest_path); - let _ = already_built_contracts.insert(manifest_path, dest_wasm); - } - } - set_already_built_contracts(already_built_contracts.clone()); + tracing_subscriber::fmt::init(); + } + + // Some contracts have already been built and we check if the + // `additional_contracts` for this particular test contain ones + // that haven't been build before + for manifest_path in contracts_to_build_and_import { + already_built_contracts + .entry(manifest_path.clone()) + .or_insert_with(|| build_contract(&manifest_path)); } + set_already_built_contracts(already_built_contracts.clone()); assert!( !already_built_contracts.is_empty(), From eeeb7f1ef340737ec66c0ca74a3c80d218885efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 30 Jun 2023 14:31:05 +0200 Subject: [PATCH 3/8] Remove unnecessary configs --- crates/e2e/macro/src/codegen.rs | 4 ++-- crates/e2e/src/lib.rs | 26 -------------------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 0c04519feab..7d71d60a39a 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -151,7 +151,7 @@ impl InkE2ETest { let run = async { // spawn a contracts node process just for this test - let node_proc = ::ink_e2e::TestNodeProcess::<::ink_e2e::PolkadotConfig> + let node_proc = ::ink_e2e::TestNodeProcess::<::subxt::PolkadotConfig> ::build(#contracts_node) .spawn() .await @@ -160,7 +160,7 @@ impl InkE2ETest { ); let mut client = ::ink_e2e::Client::< - ::ink_e2e::PolkadotConfig, + ::subxt::PolkadotConfig, #environment >::new( node_proc.client(), diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 343361934b1..4a0b6957e20 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -61,32 +61,6 @@ use std::{ }; use xts::ContractsApi; -/// Default set of commonly used types by Substrate runtimes. -#[cfg(feature = "std")] -pub enum SubstrateConfig {} - -#[cfg(feature = "std")] -impl subxt::Config for SubstrateConfig { - type Index = u32; - type Hash = sp_core::H256; - type Hasher = subxt::config::substrate::BlakeTwo256; - type AccountId = subxt::config::substrate::AccountId32; - type Address = sp_runtime::MultiAddress; - type Header = subxt::config::substrate::SubstrateHeader< - u32, - subxt::config::substrate::BlakeTwo256, - >; - type Signature = sp_runtime::MultiSignature; - type ExtrinsicParams = subxt::config::substrate::SubstrateExtrinsicParams; -} - -/// Default set of commonly used types by Polkadot nodes. -#[cfg(feature = "std")] -pub type PolkadotConfig = subxt::config::WithExtrinsicParams< - SubstrateConfig, - subxt::config::polkadot::PolkadotExtrinsicParams, ->; - /// Signer that is used throughout the E2E testing. /// /// The E2E testing can only be used with nodes that support `sr25519` From 89cce281a008ec256209653ff9476c05711b9feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 30 Jun 2023 14:36:14 +0200 Subject: [PATCH 4/8] Fix initializing tracing --- crates/e2e/macro/src/codegen.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 7d71d60a39a..1d7c269d0c7 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -21,7 +21,13 @@ use core::cell::RefCell; use derive_more::From; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use std::collections::HashMap; +use std::{ + collections::HashMap, + sync::Once, +}; + +/// We use this to initialize the tracing subscriber only once. +static INIT_ONCE: Once = Once::new(); thread_local! { // We save a mapping of `contract_manifest_path` to the built `*.contract` files. @@ -58,6 +64,8 @@ impl InkE2ETest { return quote! {} } + INIT_ONCE.call_once(tracing_subscriber::fmt::init); + let item_fn = &self.test.item_fn.item_fn; let fn_name = &item_fn.sig.ident; let block = &item_fn.block; @@ -91,10 +99,6 @@ impl InkE2ETest { }; let mut already_built_contracts = already_built_contracts(); - if already_built_contracts.is_empty() { - tracing_subscriber::fmt::init(); - } - // Some contracts have already been built and we check if the // `additional_contracts` for this particular test contain ones // that haven't been build before From 28ccb042d49d0a996ed4133a3f19a20d1b53d351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 30 Jun 2023 14:50:34 +0200 Subject: [PATCH 5/8] Reexport config --- crates/e2e/macro/src/codegen.rs | 4 ++-- crates/e2e/src/lib.rs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 1d7c269d0c7..818002db190 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -155,7 +155,7 @@ impl InkE2ETest { let run = async { // spawn a contracts node process just for this test - let node_proc = ::ink_e2e::TestNodeProcess::<::subxt::PolkadotConfig> + let node_proc = ::ink_e2e::TestNodeProcess::<::ink_e2e::PolkadotConfig> ::build(#contracts_node) .spawn() .await @@ -164,7 +164,7 @@ impl InkE2ETest { ); let mut client = ::ink_e2e::Client::< - ::subxt::PolkadotConfig, + ::ink_e2e::PolkadotConfig, #environment >::new( node_proc.client(), diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 4a0b6957e20..76e5641ffd1 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -61,6 +61,8 @@ use std::{ }; use xts::ContractsApi; +pub use subxt::PolkadotConfig; + /// Signer that is used throughout the E2E testing. /// /// The E2E testing can only be used with nodes that support `sr25519` From cdfc8393a3e89b8d9003d6de88bf98982a2e7913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 30 Jun 2023 15:20:22 +0200 Subject: [PATCH 6/8] Codec version in ui tests --- .../ink/tests/ui/contract/fail/message-returns-non-codec.stderr | 2 +- .../ink/tests/ui/trait_def/fail/message_output_non_codec.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr index ca1c72912dd..3812818afb7 100644 --- a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr +++ b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr @@ -46,7 +46,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder $CARGO/parity-scale-codec-3.6.1/src/codec.rs + --> $CARGO/parity-scale-codec-3.6.2/src/codec.rs | | pub trait Decode: Sized { | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr index 7697d0ef22f..a78ec12f407 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr @@ -35,7 +35,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder $CARGO/parity-scale-codec-3.6.1/src/codec.rs + --> $CARGO/parity-scale-codec-3.6.2/src/codec.rs | | pub trait Decode: Sized { | ^^^^^^^^^^^^^^^^^^^^^^^ From a0e483eb45efe20a0bc845804932b00022a7967b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 3 Jul 2023 13:37:58 +0200 Subject: [PATCH 7/8] Bump codec version --- .../ink/tests/ui/contract/fail/message-returns-non-codec.stderr | 2 +- .../ink/tests/ui/trait_def/fail/message_output_non_codec.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr index 3812818afb7..eecbabe13bf 100644 --- a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr +++ b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr @@ -46,7 +46,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder $CARGO/parity-scale-codec-3.6.2/src/codec.rs + --> $CARGO/parity-scale-codec-3.6.3/src/codec.rs | | pub trait Decode: Sized { | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr index a78ec12f407..4306a056bfe 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr @@ -35,7 +35,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder $CARGO/parity-scale-codec-3.6.2/src/codec.rs + --> $CARGO/parity-scale-codec-3.6.3/src/codec.rs | | pub trait Decode: Sized { | ^^^^^^^^^^^^^^^^^^^^^^^ From 3ac803c6027c6b396482c8c9b7c53f0dd1d43046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 3 Jul 2023 13:38:17 +0200 Subject: [PATCH 8/8] Revert codegen changes --- crates/e2e/macro/src/codegen.rs | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 818002db190..fb81939c4c1 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -26,8 +26,9 @@ use std::{ sync::Once, }; -/// We use this to initialize the tracing subscriber only once. -static INIT_ONCE: Once = Once::new(); +/// We use this to only build the contracts once for all tests, at the +/// time of generating the Rust code for the tests, so at compile time. +static BUILD_ONCE: Once = Once::new(); thread_local! { // We save a mapping of `contract_manifest_path` to the built `*.contract` files. @@ -64,8 +65,6 @@ impl InkE2ETest { return quote! {} } - INIT_ONCE.call_once(tracing_subscriber::fmt::init); - let item_fn = &self.test.item_fn.item_fn; let fn_name = &item_fn.sig.ident; let block = &item_fn.block; @@ -99,15 +98,28 @@ impl InkE2ETest { }; let mut already_built_contracts = already_built_contracts(); - // Some contracts have already been built and we check if the - // `additional_contracts` for this particular test contain ones - // that haven't been build before - for manifest_path in contracts_to_build_and_import { - already_built_contracts - .entry(manifest_path.clone()) - .or_insert_with(|| build_contract(&manifest_path)); + if already_built_contracts.is_empty() { + // Build all of them for the first time and initialize everything + BUILD_ONCE.call_once(|| { + tracing_subscriber::fmt::init(); + for manifest_path in contracts_to_build_and_import { + let dest_wasm = build_contract(&manifest_path); + let _ = already_built_contracts.insert(manifest_path, dest_wasm); + } + set_already_built_contracts(already_built_contracts.clone()); + }); + } else if !already_built_contracts.is_empty() { + // Some contracts have already been built and we check if the + // `additional_contracts` for this particular test contain ones + // that haven't been build before + for manifest_path in contracts_to_build_and_import { + if already_built_contracts.get(&manifest_path).is_none() { + let dest_wasm = build_contract(&manifest_path); + let _ = already_built_contracts.insert(manifest_path, dest_wasm); + } + } + set_already_built_contracts(already_built_contracts.clone()); } - set_already_built_contracts(already_built_contracts.clone()); assert!( !already_built_contracts.is_empty(),