From 7ae8ac52af42d245c4c4235a2d2fa207bf247d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 25 Jul 2023 14:12:13 +0200 Subject: [PATCH 01/21] Introduce new module for the trait. Rename `client` module --- crates/e2e/src/backend.rs | 4 +++ crates/e2e/src/lib.rs | 35 +++++-------------- crates/e2e/src/{client.rs => subxt_client.rs} | 0 3 files changed, 13 insertions(+), 26 deletions(-) create mode 100644 crates/e2e/src/backend.rs rename crates/e2e/src/{client.rs => subxt_client.rs} (100%) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs new file mode 100644 index 00000000000..10070e54327 --- /dev/null +++ b/crates/e2e/src/backend.rs @@ -0,0 +1,4 @@ +use jsonrpsee::core::async_trait; + +#[async_trait] +pub trait E2EBackend {} diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 8da67d3724e..86c13b3ff15 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -19,50 +19,33 @@ html_favicon_url = "https://use.ink/crate-docs/favicon.png" )] +mod backend; mod builders; -mod client; mod contract_results; mod default_accounts; mod error; pub mod events; mod node_proc; +mod subxt_client; mod xts; -pub use client::{ - CallBuilderFinal, - Client, - Error, -}; +pub use backend::E2EBackend; pub use contract_results::{ - CallDryRunResult, - CallResult, - InstantiationResult, - UploadResult, + CallDryRunResult, CallResult, InstantiationResult, UploadResult, }; pub use default_accounts::*; pub use ink_e2e_macro::test; -pub use node_proc::{ - TestNodeProcess, - TestNodeProcessBuilder, -}; +pub use node_proc::{TestNodeProcess, TestNodeProcessBuilder}; pub use sp_core::H256; pub use sp_keyring::AccountKeyring; -pub use subxt::{ - self, - tx::PairSigner, -}; +pub use subxt::{self, tx::PairSigner}; +pub use subxt_client::{CallBuilderFinal, Client, Error}; pub use tokio; pub use tracing_subscriber; -use pallet_contracts_primitives::{ - ContractExecResult, - ContractInstantiateResult, -}; +use pallet_contracts_primitives::{ContractExecResult, ContractInstantiateResult}; use sp_core::sr25519; -use std::{ - cell::RefCell, - sync::Once, -}; +use std::{cell::RefCell, sync::Once}; use xts::ContractsApi; pub use subxt::PolkadotConfig; diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/subxt_client.rs similarity index 100% rename from crates/e2e/src/client.rs rename to crates/e2e/src/subxt_client.rs From 02c32d9c11bacd5c617816f51c181d6c2f579fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 25 Jul 2023 14:15:10 +0200 Subject: [PATCH 02/21] `exec_upload` should be a private method --- crates/e2e/src/subxt_client.rs | 61 ++++++++++------------------------ 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index 7d4c56f3af9..bf794de9371 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -13,57 +13,30 @@ // limitations under the License. use super::{ - builders::{ - constructor_exec_input, - CreateBuilderPartial, - }, - events::{ - CodeStoredEvent, - ContractInstantiatedEvent, - EventWithTopics, - }, - log_error, - log_info, - sr25519, - ContractInstantiateResult, - ContractsApi, - Signer, + builders::{constructor_exec_input, CreateBuilderPartial}, + events::{CodeStoredEvent, ContractInstantiatedEvent, EventWithTopics}, + log_error, log_info, sr25519, ContractInstantiateResult, ContractsApi, Signer, }; use crate::contract_results::{ - CallDryRunResult, - CallResult, - InstantiationResult, - UploadResult, + CallDryRunResult, CallResult, InstantiationResult, UploadResult, }; use ink_env::{ call::{ - utils::{ - ReturnType, - Set, - }, - Call, - ExecutionInput, + utils::{ReturnType, Set}, + Call, ExecutionInput, }, Environment, }; use sp_core::Pair; #[cfg(feature = "std")] -use std::{ - collections::BTreeMap, - fmt::Debug, - path::PathBuf, -}; +use std::{collections::BTreeMap, fmt::Debug, path::PathBuf}; use crate::events; use subxt::{ blocks::ExtrinsicEvents, config::ExtrinsicParams, events::EventDetails, - ext::scale_value::{ - Composite, - Value, - ValueDef, - }, + ext::scale_value::{Composite, Value, ValueDef}, tx::PairSigner, }; @@ -286,7 +259,7 @@ where )); log_info(&format!("instantiate dry run result: {:?}", dry_run.result)); if dry_run.result.is_err() { - return Err(Error::::InstantiateDryRun(dry_run)) + return Err(Error::::InstantiateDryRun(dry_run)); } let tx_events = self @@ -331,7 +304,7 @@ where log_error(&format!( "extrinsic for instantiate failed: {dispatch_error}" )); - return Err(Error::::InstantiateExtrinsic(dispatch_error)) + return Err(Error::::InstantiateExtrinsic(dispatch_error)); } } let account_id = account_id.expect("cannot extract `account_id` from events"); @@ -380,7 +353,7 @@ where } /// Executes an `upload` call and captures the resulting events. - pub async fn exec_upload( + async fn exec_upload( &mut self, signer: &Signer, code: Vec, @@ -393,7 +366,7 @@ where .await; log_info(&format!("upload dry run: {dry_run:?}")); if dry_run.is_err() { - return Err(Error::::UploadDryRun(dry_run)) + return Err(Error::::UploadDryRun(dry_run)); } let tx_events = self.api.upload(signer, code, storage_deposit_limit).await; @@ -414,7 +387,7 @@ where uploaded.code_hash )); hash = Some(uploaded.code_hash); - break + break; } else if is_extrinsic_failed_event(&evt) { let metadata = self.api.client.metadata(); let dispatch_error = @@ -422,7 +395,7 @@ where .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for upload failed: {dispatch_error}")); - return Err(Error::::UploadExtrinsic(dispatch_error)) + return Err(Error::::UploadExtrinsic(dispatch_error)); } } @@ -470,7 +443,7 @@ where let dry_run = self.call_dry_run(signer, message, value, None).await; if dry_run.exec_result.result.is_err() { - return Err(Error::::CallDryRun(dry_run.exec_result)) + return Err(Error::::CallDryRun(dry_run.exec_result)); } let tx_events = self @@ -496,7 +469,7 @@ where subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata) .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)) + return Err(Error::::CallExtrinsic(dispatch_error)); } } @@ -541,7 +514,7 @@ where .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)) + return Err(Error::::CallExtrinsic(dispatch_error)); } } From 7902e6d11625baaba6a1cf2a7fcf4adafacaa749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 25 Jul 2023 14:24:12 +0200 Subject: [PATCH 03/21] Divide interface into general-chain and contracts-specific --- crates/e2e/src/backend.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 10070e54327..f4dfbe3f02c 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -1,4 +1,13 @@ use jsonrpsee::core::async_trait; +/// Full E2E testing backend: combines general chain API and contract-specific operations. #[async_trait] -pub trait E2EBackend {} +pub trait E2EBackend: ChainBackend + ContractsBackend {} + +/// General chain operations useful in contract testing. +#[async_trait] +pub trait ChainBackend {} + +/// Contract-specific operations. +#[async_trait] +pub trait ContractsBackend {} From 420afe6d4b2249f5154f53d6e8c5ea5ca3660bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 26 Jul 2023 08:50:06 +0200 Subject: [PATCH 04/21] Actor type --- crates/e2e/src/backend.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index f4dfbe3f02c..898237d3b6e 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -6,8 +6,14 @@ pub trait E2EBackend: ChainBackend + ContractsBackend {} /// General chain operations useful in contract testing. #[async_trait] -pub trait ChainBackend {} +pub trait ChainBackend { + /// Abstract type representing the entity that interacts with the chain. + type Actor; +} /// Contract-specific operations. #[async_trait] -pub trait ContractsBackend {} +pub trait ContractsBackend { + /// Abstract type representing the entity that interacts with the chain. + type Actor; +} From 37828b6832723a6012d7b96ae6d44a4902177457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 26 Jul 2023 10:53:05 +0200 Subject: [PATCH 05/21] Problems with Send/Sync --- crates/e2e/src/backend.rs | 39 +++++++++- crates/e2e/src/subxt_client.rs | 126 ++++++++++++++++++++------------- 2 files changed, 115 insertions(+), 50 deletions(-) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 898237d3b6e..494190d8747 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -1,4 +1,5 @@ use jsonrpsee::core::async_trait; +use subxt::dynamic::Value; /// Full E2E testing backend: combines general chain API and contract-specific operations. #[async_trait] @@ -8,7 +9,43 @@ pub trait E2EBackend: ChainBackend + ContractsBackend {} #[async_trait] pub trait ChainBackend { /// Abstract type representing the entity that interacts with the chain. - type Actor; + type Actor: Send; + /// Identifier type for an actor. + type ActorId; + /// Balance type. + type Balance: Send; + /// Error type. + type Error; + /// Event log type. + type EventLog; + + /// Generate a new actor's credentials and fund it with the given amount from the `sender` actor. + async fn create_and_fund_account( + &mut self, + origin: &Self::Actor, + amount: Self::Balance, + ) -> Self::Actor; + + /// Returns the balance of `actor`. + async fn balance(&self, actor: Self::ActorId) -> Result; + + /// Executes a runtime call `call_name` for the `pallet_name`. + /// The `call_data` is a `Vec`. + /// + /// Note: + /// - `pallet_name` must be in camel case, for example `Balances`. + /// - `call_name` must be snake case, for example `force_transfer`. + /// - `call_data` is a `Vec` that holds a representation of some value. + /// + /// Returns when the transaction is included in a block. The return value contains all events + /// that are associated with this transaction. + async fn runtime_call<'a>( + &mut self, + actor: &Self::Actor, + pallet_name: &'a str, + call_name: &'a str, + call_data: Vec, + ) -> Result; } /// Contract-specific operations. diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index bf794de9371..2bf5762746d 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -27,10 +27,12 @@ use ink_env::{ }, Environment, }; +use jsonrpsee::core::async_trait; use sp_core::Pair; #[cfg(feature = "std")] use std::{collections::BTreeMap, fmt::Debug, path::PathBuf}; +use crate::backend::ChainBackend; use crate::events; use subxt::{ blocks::ExtrinsicEvents, @@ -105,46 +107,6 @@ where } } - /// Generate a new keypair and fund with the given amount from the origin account. - /// - /// Because many tests may execute this in parallel, transfers may fail due to a race - /// condition with account indices. Therefore this will reattempt transfers a - /// number of times. - pub async fn create_and_fund_account( - &self, - origin: &Signer, - amount: E::Balance, - ) -> Signer - where - E::Balance: Clone, - C::AccountId: Clone + core::fmt::Display + Debug, - C::AccountId: From, - { - let (pair, _, _) = ::generate_with_phrase(None); - let pair_signer = PairSigner::::new(pair); - let account_id = pair_signer.account_id().to_owned(); - - self.api - .try_transfer_balance(origin, account_id.clone(), amount) - .await - .unwrap_or_else(|err| { - panic!( - "transfer from {} to {} failed with {:?}", - origin.account_id(), - account_id, - err - ) - }); - - log_info(&format!( - "transfer from {} to {} succeeded", - origin.account_id(), - account_id, - )); - - pair_signer - } - /// This function extracts the metadata of the contract at the file path /// `target/ink/$contract_name.contract`. /// @@ -561,19 +523,77 @@ where _marker: Default::default(), } } +} - /// Returns the balance of `account_id`. - pub async fn balance(&self, account_id: E::AccountId) -> Result> - where - E::Balance: TryFrom, - { +#[async_trait] +impl ChainBackend for Client +where + C: subxt::Config + Send + Sync, + C::AccountId: Clone + + Debug + + Send + + Sync + + core::fmt::Display + + From + + scale::Codec + + serde::de::DeserializeOwned, + C::Signature: From, + >::OtherParams: Default, + + E: Environment, + E::AccountId: Debug + Send + Sync, + E::Balance: Clone + + Debug + + Send + + Sync + + TryFrom + + scale::HasCompact + + serde::Serialize, +{ + type Actor = Signer; + type ActorId = E::AccountId; + type Balance = E::Balance; + type Error = Error; + type EventLog = ExtrinsicEvents; + + async fn create_and_fund_account( + &mut self, + origin: &Self::Actor, + amount: Self::Balance, + ) -> Self::Actor { + let (pair, _, _) = ::generate_with_phrase(None); + let pair_signer = PairSigner::::new(pair); + let account_id = pair_signer.account_id().to_owned(); + + self.api + .try_transfer_balance(origin, account_id.clone(), amount) + .await + .unwrap_or_else(|err| { + panic!( + "transfer from {} to {} failed with {:?}", + origin.account_id(), + account_id, + err + ) + }); + + log_info(&format!( + "transfer from {} to {} succeeded", + origin.account_id(), + account_id, + )); + + pair_signer + } + + async fn balance(&self, actor: Self::ActorId) -> Result { let account_addr = subxt::dynamic::storage( "System", "Account", vec![ // Something that encodes to an AccountId32 is what we need for the map // key here: - Value::from_bytes(&account_id), + Value::from_bytes(&actor), ], ); @@ -605,11 +625,19 @@ where Error::::Balance(format!("{balance:?} failed to convert from u128")) })?; - log_info(&format!( - "balance of contract {account_id:?} is {balance:?}" - )); + log_info(&format!("balance of contract {actor:?} is {balance:?}")); Ok(balance) } + + async fn runtime_call<'a>( + &mut self, + actor: &Self::Actor, + pallet_name: &'a str, + call_name: &'a str, + call_data: Vec, + ) -> Result { + todo!() + } } /// Try to extract the given field from a dynamic [`Value`]. From e605a0ebbfa065df06ed8295cb80a726e63f2d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 26 Jul 2023 11:03:21 +0200 Subject: [PATCH 06/21] Seems that adding everywhere Send/Sync requirement solves :shrug: --- crates/e2e/src/subxt_client.rs | 69 ++++++++++++---------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index 2bf5762746d..8a04ef3e777 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -441,48 +441,6 @@ where }) } - /// Executes a runtime call `call_name` for the `pallet_name`. - /// The `call_data` is a `Vec` - /// - /// Note: - /// - `pallet_name` must be in camel case, for example `Balances`. - /// - `call_name` must be snake case, for example `force_transfer`. - /// - `call_data` is a `Vec` that holds a representation of - /// some value. - /// - /// Returns when the transaction is included in a block. The return value - /// contains all events that are associated with this transaction. - pub async fn runtime_call<'a>( - &mut self, - signer: &Signer, - pallet_name: &'a str, - call_name: &'a str, - call_data: Vec, - ) -> Result, Error> { - let tx_events = self - .api - .runtime_call(signer, pallet_name, call_name, call_data) - .await; - - for evt in tx_events.iter() { - let evt = evt.unwrap_or_else(|err| { - panic!("unable to unwrap event: {err:?}"); - }); - - if is_extrinsic_failed_event(&evt) { - let metadata = self.api.client.metadata(); - let dispatch_error = - subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata) - .map_err(|e| Error::::Decoding(e.to_string()))?; - - log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)); - } - } - - Ok(tx_events) - } - /// Executes a dry-run `call`. /// /// Returns the result of the dry run, together with the decoded return value of the @@ -538,7 +496,9 @@ where + scale::Codec + serde::de::DeserializeOwned, C::Signature: From, - >::OtherParams: Default, + C::Address: Send + Sync, + >::OtherParams: + Default + Send + Sync, E: Environment, E::AccountId: Debug + Send + Sync, @@ -636,7 +596,28 @@ where call_name: &'a str, call_data: Vec, ) -> Result { - todo!() + let tx_events = self + .api + .runtime_call(actor, pallet_name, call_name, call_data) + .await; + + for evt in tx_events.iter() { + let evt = evt.unwrap_or_else(|err| { + panic!("unable to unwrap event: {err:?}"); + }); + + if is_extrinsic_failed_event(&evt) { + let metadata = self.api.client.metadata(); + let dispatch_error = + subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata) + .map_err(|e| Error::::Decoding(e.to_string()))?; + + log_error(&format!("extrinsic for call failed: {dispatch_error}")); + return Err(Error::::CallExtrinsic(dispatch_error)); + } + } + + Ok(tx_events) } } From b13556e258f237fc77fc7ade3c595a79eea5eb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 26 Jul 2023 11:56:20 +0200 Subject: [PATCH 07/21] Adjust tests --- crates/e2e/src/lib.rs | 2 +- integration-tests/call-builder-return-value/lib.rs | 1 + integration-tests/call-runtime/lib.rs | 1 + integration-tests/contract-transfer/lib.rs | 2 ++ integration-tests/e2e-call-runtime/lib.rs | 2 +- .../lang-err-integration-tests/call-builder-delegate/lib.rs | 1 + .../lang-err-integration-tests/call-builder/lib.rs | 6 ++---- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 86c13b3ff15..012a15b7bf9 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -29,7 +29,7 @@ mod node_proc; mod subxt_client; mod xts; -pub use backend::E2EBackend; +pub use backend::{ChainBackend, ContractsBackend, E2EBackend}; pub use contract_results::{ CallDryRunResult, CallResult, InstantiationResult, UploadResult, }; diff --git a/integration-tests/call-builder-return-value/lib.rs b/integration-tests/call-builder-return-value/lib.rs index b68210f04f5..515ffc1e164 100755 --- a/integration-tests/call-builder-return-value/lib.rs +++ b/integration-tests/call-builder-return-value/lib.rs @@ -113,6 +113,7 @@ mod call_builder { mod e2e_tests { use super::*; use incrementer::IncrementerRef; + use ink_e2e::ChainBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/call-runtime/lib.rs b/integration-tests/call-runtime/lib.rs index 919a06f525b..03ab1799c35 100644 --- a/integration-tests/call-runtime/lib.rs +++ b/integration-tests/call-runtime/lib.rs @@ -114,6 +114,7 @@ mod runtime_call { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::ChainBackend; use ink::{ env::{ diff --git a/integration-tests/contract-transfer/lib.rs b/integration-tests/contract-transfer/lib.rs index 2dc444bd486..008233e981a 100644 --- a/integration-tests/contract-transfer/lib.rs +++ b/integration-tests/contract-transfer/lib.rs @@ -182,6 +182,8 @@ pub mod give_me { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::ChainBackend; + type E2EResult = std::result::Result>; #[ink_e2e::test] diff --git a/integration-tests/e2e-call-runtime/lib.rs b/integration-tests/e2e-call-runtime/lib.rs index 16a899feb4e..6722896255f 100644 --- a/integration-tests/e2e-call-runtime/lib.rs +++ b/integration-tests/e2e-call-runtime/lib.rs @@ -21,7 +21,7 @@ pub mod e2e_call_runtime { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::subxt::dynamic::Value; + use ink_e2e::{subxt::dynamic::Value, ChainBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs b/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs index f3b9997cc9a..0e39c31bf83 100755 --- a/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs +++ b/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs @@ -94,6 +94,7 @@ mod call_builder { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::ChainBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/call-builder/lib.rs b/integration-tests/lang-err-integration-tests/call-builder/lib.rs index 1d0d52cc795..ab528358155 100755 --- a/integration-tests/lang-err-integration-tests/call-builder/lib.rs +++ b/integration-tests/lang-err-integration-tests/call-builder/lib.rs @@ -166,10 +166,8 @@ mod call_builder { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use integration_flipper::{ - Flipper, - FlipperRef, - }; + use ink_e2e::ChainBackend; + use integration_flipper::{Flipper, FlipperRef}; type E2EResult = std::result::Result>; From 0361c459589d08c0d11765291bc8fcf8e5cd686a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 26 Jul 2023 11:57:33 +0200 Subject: [PATCH 08/21] Fmt --- crates/e2e/src/backend.rs | 10 +++--- crates/e2e/src/lib.rs | 37 +++++++++++++++---- crates/e2e/src/subxt_client.rs | 65 ++++++++++++++++++++++++---------- 3 files changed, 83 insertions(+), 29 deletions(-) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 494190d8747..c9911124ba5 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -19,7 +19,8 @@ pub trait ChainBackend { /// Event log type. type EventLog; - /// Generate a new actor's credentials and fund it with the given amount from the `sender` actor. + /// Generate a new actor's credentials and fund it with the given amount from the + /// `sender` actor. async fn create_and_fund_account( &mut self, origin: &Self::Actor, @@ -35,10 +36,11 @@ pub trait ChainBackend { /// Note: /// - `pallet_name` must be in camel case, for example `Balances`. /// - `call_name` must be snake case, for example `force_transfer`. - /// - `call_data` is a `Vec` that holds a representation of some value. + /// - `call_data` is a `Vec` that holds a representation of + /// some value. /// - /// Returns when the transaction is included in a block. The return value contains all events - /// that are associated with this transaction. + /// Returns when the transaction is included in a block. The return value contains all + /// events that are associated with this transaction. async fn runtime_call<'a>( &mut self, actor: &Self::Actor, diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 012a15b7bf9..ba1d3a9f9a6 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -29,23 +29,46 @@ mod node_proc; mod subxt_client; mod xts; -pub use backend::{ChainBackend, ContractsBackend, E2EBackend}; +pub use backend::{ + ChainBackend, + ContractsBackend, + E2EBackend, +}; pub use contract_results::{ - CallDryRunResult, CallResult, InstantiationResult, UploadResult, + CallDryRunResult, + CallResult, + InstantiationResult, + UploadResult, }; pub use default_accounts::*; pub use ink_e2e_macro::test; -pub use node_proc::{TestNodeProcess, TestNodeProcessBuilder}; +pub use node_proc::{ + TestNodeProcess, + TestNodeProcessBuilder, +}; pub use sp_core::H256; pub use sp_keyring::AccountKeyring; -pub use subxt::{self, tx::PairSigner}; -pub use subxt_client::{CallBuilderFinal, Client, Error}; +pub use subxt::{ + self, + tx::PairSigner, +}; +pub use subxt_client::{ + CallBuilderFinal, + Client, + Error, +}; pub use tokio; pub use tracing_subscriber; -use pallet_contracts_primitives::{ContractExecResult, ContractInstantiateResult}; +use pallet_contracts_primitives::{ + ContractExecResult, + ContractInstantiateResult, +}; use sp_core::sr25519; -use std::{cell::RefCell, sync::Once}; +use std::{ + cell::RefCell, + sync::Once, +}; use xts::ContractsApi; pub use subxt::PolkadotConfig; diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index 8a04ef3e777..992182997e3 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -13,32 +13,61 @@ // limitations under the License. use super::{ - builders::{constructor_exec_input, CreateBuilderPartial}, - events::{CodeStoredEvent, ContractInstantiatedEvent, EventWithTopics}, - log_error, log_info, sr25519, ContractInstantiateResult, ContractsApi, Signer, + builders::{ + constructor_exec_input, + CreateBuilderPartial, + }, + events::{ + CodeStoredEvent, + ContractInstantiatedEvent, + EventWithTopics, + }, + log_error, + log_info, + sr25519, + ContractInstantiateResult, + ContractsApi, + Signer, }; use crate::contract_results::{ - CallDryRunResult, CallResult, InstantiationResult, UploadResult, + CallDryRunResult, + CallResult, + InstantiationResult, + UploadResult, }; use ink_env::{ call::{ - utils::{ReturnType, Set}, - Call, ExecutionInput, + utils::{ + ReturnType, + Set, + }, + Call, + ExecutionInput, }, Environment, }; use jsonrpsee::core::async_trait; use sp_core::Pair; #[cfg(feature = "std")] -use std::{collections::BTreeMap, fmt::Debug, path::PathBuf}; +use std::{ + collections::BTreeMap, + fmt::Debug, + path::PathBuf, +}; -use crate::backend::ChainBackend; -use crate::events; +use crate::{ + backend::ChainBackend, + events, +}; use subxt::{ blocks::ExtrinsicEvents, config::ExtrinsicParams, events::EventDetails, - ext::scale_value::{Composite, Value, ValueDef}, + ext::scale_value::{ + Composite, + Value, + ValueDef, + }, tx::PairSigner, }; @@ -221,7 +250,7 @@ where )); log_info(&format!("instantiate dry run result: {:?}", dry_run.result)); if dry_run.result.is_err() { - return Err(Error::::InstantiateDryRun(dry_run)); + return Err(Error::::InstantiateDryRun(dry_run)) } let tx_events = self @@ -266,7 +295,7 @@ where log_error(&format!( "extrinsic for instantiate failed: {dispatch_error}" )); - return Err(Error::::InstantiateExtrinsic(dispatch_error)); + return Err(Error::::InstantiateExtrinsic(dispatch_error)) } } let account_id = account_id.expect("cannot extract `account_id` from events"); @@ -328,7 +357,7 @@ where .await; log_info(&format!("upload dry run: {dry_run:?}")); if dry_run.is_err() { - return Err(Error::::UploadDryRun(dry_run)); + return Err(Error::::UploadDryRun(dry_run)) } let tx_events = self.api.upload(signer, code, storage_deposit_limit).await; @@ -349,7 +378,7 @@ where uploaded.code_hash )); hash = Some(uploaded.code_hash); - break; + break } else if is_extrinsic_failed_event(&evt) { let metadata = self.api.client.metadata(); let dispatch_error = @@ -357,7 +386,7 @@ where .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for upload failed: {dispatch_error}")); - return Err(Error::::UploadExtrinsic(dispatch_error)); + return Err(Error::::UploadExtrinsic(dispatch_error)) } } @@ -405,7 +434,7 @@ where let dry_run = self.call_dry_run(signer, message, value, None).await; if dry_run.exec_result.result.is_err() { - return Err(Error::::CallDryRun(dry_run.exec_result)); + return Err(Error::::CallDryRun(dry_run.exec_result)) } let tx_events = self @@ -431,7 +460,7 @@ where subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata) .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)); + return Err(Error::::CallExtrinsic(dispatch_error)) } } @@ -613,7 +642,7 @@ where .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)); + return Err(Error::::CallExtrinsic(dispatch_error)) } } From 1af58568eb1643d51dd2306e5a47aa4a300cb05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 26 Jul 2023 12:03:36 +0200 Subject: [PATCH 09/21] Fmt --- .../lang-err-integration-tests/call-builder/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integration-tests/lang-err-integration-tests/call-builder/lib.rs b/integration-tests/lang-err-integration-tests/call-builder/lib.rs index ab528358155..56869004312 100755 --- a/integration-tests/lang-err-integration-tests/call-builder/lib.rs +++ b/integration-tests/lang-err-integration-tests/call-builder/lib.rs @@ -167,7 +167,10 @@ mod call_builder { mod e2e_tests { use super::*; use ink_e2e::ChainBackend; - use integration_flipper::{Flipper, FlipperRef}; + use integration_flipper::{ + Flipper, + FlipperRef, + }; type E2EResult = std::result::Result>; From 3a5d827d084e8f8aed7580568f7d8239287e9f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 26 Jul 2023 12:04:33 +0200 Subject: [PATCH 10/21] Fmt --- integration-tests/e2e-call-runtime/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integration-tests/e2e-call-runtime/lib.rs b/integration-tests/e2e-call-runtime/lib.rs index 6722896255f..a3657c13c5e 100644 --- a/integration-tests/e2e-call-runtime/lib.rs +++ b/integration-tests/e2e-call-runtime/lib.rs @@ -21,7 +21,10 @@ pub mod e2e_call_runtime { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{subxt::dynamic::Value, ChainBackend}; + use ink_e2e::{ + subxt::dynamic::Value, + ChainBackend, + }; type E2EResult = std::result::Result>; From 08c496c21edc7fa70d8f2d4a3b3da855437a2e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 17:47:31 +0200 Subject: [PATCH 11/21] Yanked contract-build version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 66c5a1cd3d3..51795de994e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ array-init = { version = "2.0", default-features = false } blake2 = { version = "0.10" } cargo_metadata = { version = "0.17.0" } cfg-if = { version = "1.0" } -contract-build = { version = "3.1.0" } +contract-build = { version = "3.0.1" } derive_more = { version = "0.99.17", default-features = false } either = { version = "1.5", default-features = false } funty = { version = "2.0.0" } From 7b831e8cf17ef8226ebbe5bd12a008a5b18c55ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 18:02:26 +0200 Subject: [PATCH 12/21] Leftovers from merge --- crates/e2e/macro/src/codegen.rs | 40 ++++++++++----------------------- crates/e2e/src/subxt_client.rs | 5 +++-- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 6cf9c168990..128de7e277a 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -13,18 +13,12 @@ // limitations under the License. use crate::ir; -use contract_build::{ - ManifestPath, - Target, -}; +use contract_build::{ManifestPath, Target}; use core::cell::RefCell; use derive_more::From; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use std::{ - collections::HashMap, - sync::Once, -}; +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. @@ -62,7 +56,7 @@ impl InkE2ETest { pub fn generate_code(&self) -> TokenStream2 { #[cfg(clippy)] if true { - return quote! {} + return quote! {}; } let item_fn = &self.test.item_fn.item_fn; @@ -265,15 +259,8 @@ impl ContractManifests { /// Wasm build artifact. fn build_contract(path_to_cargo_toml: &str) -> String { use contract_build::{ - BuildArtifacts, - BuildMode, - ExecuteArgs, - Features, - Network, - OptimizationPasses, - OutputType, - UnstableFlags, - Verbosity, + BuildArtifacts, BuildMode, ExecuteArgs, Features, Network, OptimizationPasses, + OutputType, UnstableFlags, Verbosity, }; let manifest_path = ManifestPath::new(path_to_cargo_toml).unwrap_or_else(|err| { @@ -293,19 +280,16 @@ fn build_contract(path_to_cargo_toml: &str) -> String { output_type: OutputType::HumanReadable, skip_wasm_validation: false, target: Target::Wasm, - ..ExecuteArgs::default() }; match contract_build::execute(args) { - Ok(build_result) => { - build_result - .dest_wasm - .expect("Wasm code artifact not generated") - .canonicalize() - .expect("Invalid dest bundle path") - .to_string_lossy() - .into() - } + Ok(build_result) => build_result + .dest_wasm + .expect("Wasm code artifact not generated") + .canonicalize() + .expect("Invalid dest bundle path") + .to_string_lossy() + .into(), Err(err) => { panic!("contract build for {path_to_cargo_toml} failed: {err}") } diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index 791c1c77b57..fe73d988e17 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -490,11 +490,12 @@ where + Sync + core::fmt::Display + scale::Codec + + From + serde::de::DeserializeOwned, + C::Address: From, C::Signature: From, C::Address: Send + Sync, - >::OtherParams: - Default + Send + Sync, + >::OtherParams: Default + Send + Sync, E: Environment, E::AccountId: Debug + Send + Sync, From 9e40e916a37df522a0f79bcb2be816080e2ed90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 18:41:11 +0200 Subject: [PATCH 13/21] Move instantiate* --- crates/e2e/src/backend.rs | 39 ++++++++- crates/e2e/src/subxt_client.rs | 143 +++++++++++++++++++-------------- 2 files changed, 118 insertions(+), 64 deletions(-) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index c9911124ba5..8af5d548132 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -1,9 +1,13 @@ +use crate::builders::CreateBuilderPartial; +use crate::InstantiationResult; +use ink_env::Environment; use jsonrpsee::core::async_trait; +use pallet_contracts_primitives::ContractInstantiateResult; use subxt::dynamic::Value; /// Full E2E testing backend: combines general chain API and contract-specific operations. #[async_trait] -pub trait E2EBackend: ChainBackend + ContractsBackend {} +pub trait E2EBackend: ChainBackend + ContractsBackend {} /// General chain operations useful in contract testing. #[async_trait] @@ -52,7 +56,38 @@ pub trait ChainBackend { /// Contract-specific operations. #[async_trait] -pub trait ContractsBackend { +pub trait ContractsBackend { /// Abstract type representing the entity that interacts with the chain. type Actor; + /// Error type. + type Error; + /// Event log type. + type EventLog; + + /// The function subsequently uploads and instantiates an instance of the contract. + /// + /// This function extracts the metadata of the contract at the file path + /// `target/ink/$contract_name.contract`. + /// + /// Calling this function multiple times should be idempotent, the contract is + /// newly instantiated each time using a unique salt. No existing contract + /// instance is reused! + async fn instantiate( + &mut self, + contract_name: &str, + caller: &Self::Actor, + constructor: CreateBuilderPartial, + value: E::Balance, + storage_deposit_limit: Option, + ) -> Result, Self::Error>; + + /// Dry run contract instantiation. + async fn instantiate_dry_run( + &mut self, + contract_name: &str, + caller: &Self::Actor, + constructor: CreateBuilderPartial, + value: E::Balance, + storage_deposit_limit: Option, + ) -> ContractInstantiateResult; } diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index fe73d988e17..cdc0572aa35 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -28,10 +28,11 @@ use ink_env::{ Environment, }; use jsonrpsee::core::async_trait; +use scale::Encode; #[cfg(feature = "std")] use std::{collections::BTreeMap, fmt::Debug, path::PathBuf}; -use crate::{backend::ChainBackend, events}; +use crate::{backend::ChainBackend, events, ContractsBackend}; use subxt::{ blocks::ExtrinsicEvents, config::ExtrinsicParams, @@ -104,67 +105,6 @@ where } } - /// This function extracts the metadata of the contract at the file path - /// `target/ink/$contract_name.contract`. - /// - /// The function subsequently uploads and instantiates an instance of the contract. - /// - /// Calling this function multiple times is idempotent, the contract is - /// newly instantiated each time using a unique salt. No existing contract - /// instance is reused! - pub async fn instantiate( - &mut self, - contract_name: &str, - signer: &Keypair, - constructor: CreateBuilderPartial, - value: E::Balance, - storage_deposit_limit: Option, - ) -> Result>, Error> - where - Args: scale::Encode, - { - let code = self.load_code(contract_name); - let ret = self - .exec_instantiate::( - signer, - code, - constructor, - value, - storage_deposit_limit, - ) - .await?; - log_info(&format!("instantiated contract at {:?}", ret.account_id)); - Ok(ret) - } - - /// Dry run contract instantiation using the given constructor. - pub async fn instantiate_dry_run( - &mut self, - contract_name: &str, - signer: &Keypair, - constructor: CreateBuilderPartial, - value: E::Balance, - storage_deposit_limit: Option, - ) -> ContractInstantiateResult - where - Args: scale::Encode, - { - let code = self.load_code(contract_name); - let data = constructor_exec_input(constructor); - - let salt = Self::salt(); - self.api - .instantiate_with_code_dry_run( - value, - storage_deposit_limit, - code, - data, - salt, - signer, - ) - .await - } - /// Load the Wasm code for the given contract. fn load_code(&self, contract: &str) -> Vec { let wasm_path = self @@ -619,6 +559,85 @@ where } } +#[async_trait] +impl ContractsBackend for Client +where + C: subxt::Config + Send + Sync, + C::AccountId: Clone + + Debug + + Send + + Sync + + core::fmt::Display + + scale::Codec + + From + + serde::de::DeserializeOwned, + C::Address: From, + C::Signature: From, + C::Address: Send + Sync, + >::OtherParams: Default + Send + Sync, + + E: Environment, + E::AccountId: Debug + Send + Sync, + E::Balance: Clone + + Debug + + Send + + Sync + + TryFrom + + scale::HasCompact + + serde::Serialize, + E::Hash: Debug + scale::Encode, +{ + type Actor = Keypair; + type Error = Error; + type EventLog = ExtrinsicEvents; + + async fn instantiate( + &mut self, + contract_name: &str, + caller: &Self::Actor, + constructor: CreateBuilderPartial, + value: E::Balance, + storage_deposit_limit: Option, + ) -> Result, Self::Error> { + let code = self.load_code(contract_name); + let ret = self + .exec_instantiate::( + caller, + code, + constructor, + value, + storage_deposit_limit, + ) + .await?; + log_info(&format!("instantiated contract at {:?}", ret.account_id)); + Ok(ret) + } + + async fn instantiate_dry_run( + &mut self, + contract_name: &str, + caller: &Self::Actor, + constructor: CreateBuilderPartial, + value: E::Balance, + storage_deposit_limit: Option, + ) -> ContractInstantiateResult { + let code = self.load_code(contract_name); + let data = constructor_exec_input(constructor); + + let salt = Self::salt(); + self.api + .instantiate_with_code_dry_run( + value, + storage_deposit_limit, + code, + data, + salt, + caller, + ) + .await + } +} + /// Try to extract the given field from a dynamic [`Value`]. /// /// Returns `Err` if: From 3749d18e667a9f199af049d7268c9e713529ab74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 18:44:05 +0200 Subject: [PATCH 14/21] Upload --- crates/e2e/src/backend.rs | 16 ++++++++++++++- crates/e2e/src/subxt_client.rs | 37 ++++++++++++++-------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 8af5d548132..f75b9ccdebe 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -1,5 +1,5 @@ use crate::builders::CreateBuilderPartial; -use crate::InstantiationResult; +use crate::{InstantiationResult, UploadResult}; use ink_env::Environment; use jsonrpsee::core::async_trait; use pallet_contracts_primitives::ContractInstantiateResult; @@ -90,4 +90,18 @@ pub trait ContractsBackend { value: E::Balance, storage_deposit_limit: Option, ) -> ContractInstantiateResult; + + /// The function subsequently uploads and instantiates an instance of the contract. + /// + /// This function extracts the Wasm of the contract for the specified contract. + /// + /// Calling this function multiple times should be idempotent, the contract is + /// newly instantiated each time using a unique salt. No existing contract + /// instance is reused! + async fn upload( + &mut self, + contract_name: &str, + caller: &Self::Actor, + storage_deposit_limit: Option, + ) -> Result, Self::Error>; } diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index cdc0572aa35..f67469e6b79 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -230,27 +230,6 @@ where .to_vec() } - /// This function extracts the Wasm of the contract for the specified contract. - /// - /// The function subsequently uploads and instantiates an instance of the contract. - /// - /// Calling this function multiple times is idempotent, the contract is - /// newly instantiated each time using a unique salt. No existing contract - /// instance is reused! - pub async fn upload( - &mut self, - contract_name: &str, - signer: &Keypair, - storage_deposit_limit: Option, - ) -> Result>, Error> { - let code = self.load_code(contract_name); - let ret = self - .exec_upload(signer, code, storage_deposit_limit) - .await?; - log_info(&format!("contract stored with hash {:?}", ret.code_hash)); - Ok(ret) - } - /// Executes an `upload` call and captures the resulting events. async fn exec_upload( &mut self, @@ -585,7 +564,7 @@ where + TryFrom + scale::HasCompact + serde::Serialize, - E::Hash: Debug + scale::Encode, + E::Hash: Debug + Send + scale::Encode, { type Actor = Keypair; type Error = Error; @@ -636,6 +615,20 @@ where ) .await } + + async fn upload( + &mut self, + contract_name: &str, + caller: &Self::Actor, + storage_deposit_limit: Option, + ) -> Result, Self::Error> { + let code = self.load_code(contract_name); + let ret = self + .exec_upload(caller, code, storage_deposit_limit) + .await?; + log_info(&format!("contract stored with hash {:?}", ret.code_hash)); + Ok(ret) + } } /// Try to extract the given field from a dynamic [`Value`]. From 4d96eb4ae7cea9e7bc2c46785c7c905408e71a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 18:51:59 +0200 Subject: [PATCH 15/21] Trait completed --- crates/e2e/src/backend.rs | 32 +++++- crates/e2e/src/subxt_client.rs | 190 +++++++++++++++------------------ 2 files changed, 120 insertions(+), 102 deletions(-) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index f75b9ccdebe..2b189f360c9 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -1,5 +1,7 @@ use crate::builders::CreateBuilderPartial; -use crate::{InstantiationResult, UploadResult}; +use crate::{ + CallBuilderFinal, CallDryRunResult, CallResult, InstantiationResult, UploadResult, +}; use ink_env::Environment; use jsonrpsee::core::async_trait; use pallet_contracts_primitives::ContractInstantiateResult; @@ -104,4 +106,32 @@ pub trait ContractsBackend { caller: &Self::Actor, storage_deposit_limit: Option, ) -> Result, Self::Error>; + + /// Executes a `call` for the contract at `account_id`. + /// + /// Returns when the transaction is included in a block. The return value + /// contains all events that are associated with this transaction. + async fn call( + &mut self, + caller: &Self::Actor, + message: &CallBuilderFinal, + value: E::Balance, + storage_deposit_limit: Option, + ) -> Result, Self::Error> + where + CallBuilderFinal: Clone; + + /// Executes a dry-run `call`. + /// + /// Returns the result of the dry run, together with the decoded return value of the + /// invoked message. + async fn call_dry_run( + &mut self, + caller: &Self::Actor, + message: &CallBuilderFinal, + value: E::Balance, + storage_deposit_limit: Option, + ) -> CallDryRunResult + where + CallBuilderFinal: Clone; } diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index f67469e6b79..b6aa1943fb7 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -28,7 +28,7 @@ use ink_env::{ Environment, }; use jsonrpsee::core::async_trait; -use scale::Encode; +use scale::{Decode, Encode}; #[cfg(feature = "std")] use std::{collections::BTreeMap, fmt::Debug, path::PathBuf}; @@ -297,106 +297,6 @@ where events: tx_events, }) } - - /// Executes a `call` for the contract at `account_id`. - /// - /// Returns when the transaction is included in a block. The return value - /// contains all events that are associated with this transaction. - pub async fn call( - &mut self, - signer: &Keypair, - message: &CallBuilderFinal, - value: E::Balance, - storage_deposit_limit: Option, - ) -> Result>, Error> - where - Args: scale::Encode, - RetType: scale::Decode, - CallBuilderFinal: Clone, - { - let account_id = message.clone().params().callee().clone(); - let exec_input = scale::Encode::encode(message.clone().params().exec_input()); - log_info(&format!("call: {:02X?}", exec_input)); - - let dry_run = self.call_dry_run(signer, message, value, None).await; - - if dry_run.exec_result.result.is_err() { - return Err(Error::::CallDryRun(dry_run.exec_result)); - } - - let tx_events = self - .api - .call( - subxt::utils::MultiAddress::Id(account_id.clone()), - value, - dry_run.exec_result.gas_required.into(), - storage_deposit_limit, - exec_input, - signer, - ) - .await; - - for evt in tx_events.iter() { - let evt = evt.unwrap_or_else(|err| { - panic!("unable to unwrap event: {err:?}"); - }); - - if is_extrinsic_failed_event(&evt) { - let metadata = self.api.client.metadata(); - let dispatch_error = - subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata) - .map_err(|e| Error::::Decoding(e.to_string()))?; - log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)); - } - } - - Ok(CallResult { - dry_run, - events: tx_events, - }) - } - - /// Executes a dry-run `call`. - /// - /// Returns the result of the dry run, together with the decoded return value of the - /// invoked message. - pub async fn call_dry_run( - &mut self, - signer: &Keypair, - message: &CallBuilderFinal, - value: E::Balance, - storage_deposit_limit: Option, - ) -> CallDryRunResult - where - Args: scale::Encode, - RetType: scale::Decode, - CallBuilderFinal: Clone, - { - let dest = message.clone().params().callee().clone(); - let exec_input = scale::Encode::encode(message.clone().params().exec_input()); - - let exec_result = self - .api - .call_dry_run( - Signer::::account_id(signer), - dest, - exec_input, - value, - storage_deposit_limit, - ) - .await; - log_info(&format!("call dry run: {:?}", &exec_result.result)); - log_info(&format!( - "call dry run debug message: {}", - String::from_utf8_lossy(&exec_result.debug_message) - )); - - CallDryRunResult { - exec_result, - _marker: Default::default(), - } - } } #[async_trait] @@ -629,6 +529,94 @@ where log_info(&format!("contract stored with hash {:?}", ret.code_hash)); Ok(ret) } + + async fn call( + &mut self, + caller: &Self::Actor, + message: &CallBuilderFinal, + value: E::Balance, + storage_deposit_limit: Option, + ) -> Result, Self::Error> + where + CallBuilderFinal: Clone, + { + let account_id = message.clone().params().callee().clone(); + let exec_input = Encode::encode(message.clone().params().exec_input()); + log_info(&format!("call: {:02X?}", exec_input)); + + let dry_run = self.call_dry_run(caller, message, value, None).await; + + if dry_run.exec_result.result.is_err() { + return Err(Error::::CallDryRun(dry_run.exec_result)); + } + + let tx_events = self + .api + .call( + subxt::utils::MultiAddress::Id(account_id.clone()), + value, + dry_run.exec_result.gas_required.into(), + storage_deposit_limit, + exec_input, + caller, + ) + .await; + + for evt in tx_events.iter() { + let evt = evt.unwrap_or_else(|err| { + panic!("unable to unwrap event: {err:?}"); + }); + + if is_extrinsic_failed_event(&evt) { + let metadata = self.api.client.metadata(); + let dispatch_error = + subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata) + .map_err(|e| Error::::Decoding(e.to_string()))?; + log_error(&format!("extrinsic for call failed: {dispatch_error}")); + return Err(Error::::CallExtrinsic(dispatch_error)); + } + } + + Ok(CallResult { + dry_run, + events: tx_events, + }) + } + + async fn call_dry_run( + &mut self, + caller: &Self::Actor, + message: &CallBuilderFinal, + value: E::Balance, + storage_deposit_limit: Option, + ) -> CallDryRunResult + where + CallBuilderFinal: Clone, + { + let dest = message.clone().params().callee().clone(); + let exec_input = Encode::encode(message.clone().params().exec_input()); + + let exec_result = self + .api + .call_dry_run( + Signer::::account_id(caller), + dest, + exec_input, + value, + storage_deposit_limit, + ) + .await; + log_info(&format!("call dry run: {:?}", &exec_result.result)); + log_info(&format!( + "call dry run debug message: {}", + String::from_utf8_lossy(&exec_result.debug_message) + )); + + CallDryRunResult { + exec_result, + _marker: Default::default(), + } + } } /// Try to extract the given field from a dynamic [`Value`]. From e56a4a5bb1bbe08b01575e37ef0fb2670d880327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 18:54:10 +0200 Subject: [PATCH 16/21] Implement E2EBackend, but it requires the whole litany of trait bounds... --- crates/e2e/src/subxt_client.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index b6aa1943fb7..7870012145c 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -32,7 +32,7 @@ use scale::{Decode, Encode}; #[cfg(feature = "std")] use std::{collections::BTreeMap, fmt::Debug, path::PathBuf}; -use crate::{backend::ChainBackend, events, ContractsBackend}; +use crate::{backend::ChainBackend, events, ContractsBackend, E2EBackend}; use subxt::{ blocks::ExtrinsicEvents, config::ExtrinsicParams, @@ -619,6 +619,35 @@ where } } +impl E2EBackend for Client +where + C: subxt::Config + Send + Sync, + C::AccountId: Clone + + Debug + + Send + + Sync + + core::fmt::Display + + scale::Codec + + From + + serde::de::DeserializeOwned, + C::Address: From, + C::Signature: From, + C::Address: Send + Sync, + >::OtherParams: Default + Send + Sync, + + E: Environment, + E::AccountId: Debug + Send + Sync, + E::Balance: Clone + + Debug + + Send + + Sync + + TryFrom + + scale::HasCompact + + serde::Serialize, + E::Hash: Debug + Send + scale::Encode, +{ +} + /// Try to extract the given field from a dynamic [`Value`]. /// /// Returns `Err` if: From 80d9d6bd0d275294048dd8cc7ae33b06ff701451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 19:23:34 +0200 Subject: [PATCH 17/21] Add import to tests --- crates/e2e/macro/src/codegen.rs | 39 ++++++---- crates/e2e/src/backend.rs | 8 ++- crates/e2e/src/lib.rs | 10 +-- crates/e2e/src/subxt_client.rs | 71 ++++++++++++++----- .../call-builder-return-value/lib.rs | 12 +--- integration-tests/call-runtime/lib.rs | 12 +--- integration-tests/contract-terminate/lib.rs | 2 + integration-tests/contract-transfer/lib.rs | 2 +- integration-tests/custom-allocator/lib.rs | 6 +- integration-tests/custom-environment/lib.rs | 6 +- integration-tests/e2e-call-runtime/lib.rs | 5 +- integration-tests/erc20/lib.rs | 19 ++--- integration-tests/events/lib.rs | 2 +- integration-tests/flipper/lib.rs | 1 + .../call-builder-delegate/lib.rs | 8 +-- .../call-builder/lib.rs | 13 +--- .../constructors-return-value/lib.rs | 5 +- .../contract-ref/lib.rs | 1 + .../integration-flipper/lib.rs | 7 +- .../mapping-integration-tests/lib.rs | 2 + .../multi-contract-caller/lib.rs | 1 + integration-tests/set-code-hash/lib.rs | 1 + .../trait-dyn-cross-contract-calls/lib.rs | 11 +-- integration-tests/wildcard-selector/lib.rs | 7 +- 24 files changed, 134 insertions(+), 117 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 128de7e277a..fb81939c4c1 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -13,12 +13,18 @@ // limitations under the License. use crate::ir; -use contract_build::{ManifestPath, Target}; +use contract_build::{ + ManifestPath, + Target, +}; use core::cell::RefCell; use derive_more::From; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use std::{collections::HashMap, sync::Once}; +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. @@ -56,7 +62,7 @@ impl InkE2ETest { pub fn generate_code(&self) -> TokenStream2 { #[cfg(clippy)] if true { - return quote! {}; + return quote! {} } let item_fn = &self.test.item_fn.item_fn; @@ -259,8 +265,15 @@ impl ContractManifests { /// Wasm build artifact. fn build_contract(path_to_cargo_toml: &str) -> String { use contract_build::{ - BuildArtifacts, BuildMode, ExecuteArgs, Features, Network, OptimizationPasses, - OutputType, UnstableFlags, Verbosity, + BuildArtifacts, + BuildMode, + ExecuteArgs, + Features, + Network, + OptimizationPasses, + OutputType, + UnstableFlags, + Verbosity, }; let manifest_path = ManifestPath::new(path_to_cargo_toml).unwrap_or_else(|err| { @@ -283,13 +296,15 @@ fn build_contract(path_to_cargo_toml: &str) -> String { }; match contract_build::execute(args) { - Ok(build_result) => build_result - .dest_wasm - .expect("Wasm code artifact not generated") - .canonicalize() - .expect("Invalid dest bundle path") - .to_string_lossy() - .into(), + Ok(build_result) => { + build_result + .dest_wasm + .expect("Wasm code artifact not generated") + .canonicalize() + .expect("Invalid dest bundle path") + .to_string_lossy() + .into() + } Err(err) => { panic!("contract build for {path_to_cargo_toml} failed: {err}") } diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 2b189f360c9..818b43c40e5 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -1,6 +1,10 @@ -use crate::builders::CreateBuilderPartial; use crate::{ - CallBuilderFinal, CallDryRunResult, CallResult, InstantiationResult, UploadResult, + builders::CreateBuilderPartial, + CallBuilderFinal, + CallDryRunResult, + CallResult, + InstantiationResult, + UploadResult, }; use ink_env::Environment; use jsonrpsee::core::async_trait; diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 4d9852ae520..7876f7b01fc 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -47,16 +47,16 @@ pub use node_proc::{ pub use sp_core::H256; pub use sp_keyring::AccountKeyring; pub use subxt; -pub use subxt_signer::sr25519::{ - self, - dev::*, - Keypair, -}; pub use subxt_client::{ CallBuilderFinal, Client, Error, }; +pub use subxt_signer::sr25519::{ + self, + dev::*, + Keypair, +}; pub use tokio; pub use tracing_subscriber; diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index 7870012145c..fc442083cc0 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -13,31 +13,66 @@ // limitations under the License. use super::{ - builders::{constructor_exec_input, CreateBuilderPartial}, - events::{CodeStoredEvent, ContractInstantiatedEvent, EventWithTopics}, - log_error, log_info, sr25519, ContractInstantiateResult, ContractsApi, Keypair, + builders::{ + constructor_exec_input, + CreateBuilderPartial, + }, + events::{ + CodeStoredEvent, + ContractInstantiatedEvent, + EventWithTopics, + }, + log_error, + log_info, + sr25519, + ContractInstantiateResult, + ContractsApi, + Keypair, }; use crate::contract_results::{ - CallDryRunResult, CallResult, InstantiationResult, UploadResult, + CallDryRunResult, + CallResult, + InstantiationResult, + UploadResult, }; use ink_env::{ call::{ - utils::{ReturnType, Set}, - Call, ExecutionInput, + utils::{ + ReturnType, + Set, + }, + Call, + ExecutionInput, }, Environment, }; use jsonrpsee::core::async_trait; -use scale::{Decode, Encode}; +use scale::{ + Decode, + Encode, +}; #[cfg(feature = "std")] -use std::{collections::BTreeMap, fmt::Debug, path::PathBuf}; +use std::{ + collections::BTreeMap, + fmt::Debug, + path::PathBuf, +}; -use crate::{backend::ChainBackend, events, ContractsBackend, E2EBackend}; +use crate::{ + backend::ChainBackend, + events, + ContractsBackend, + E2EBackend, +}; use subxt::{ blocks::ExtrinsicEvents, config::ExtrinsicParams, events::EventDetails, - ext::scale_value::{Composite, Value, ValueDef}, + ext::scale_value::{ + Composite, + Value, + ValueDef, + }, tx::Signer, }; @@ -158,7 +193,7 @@ where )); log_info(&format!("instantiate dry run result: {:?}", dry_run.result)); if dry_run.result.is_err() { - return Err(Error::::InstantiateDryRun(dry_run)); + return Err(Error::::InstantiateDryRun(dry_run)) } let tx_events = self @@ -203,7 +238,7 @@ where log_error(&format!( "extrinsic for instantiate failed: {dispatch_error}" )); - return Err(Error::::InstantiateExtrinsic(dispatch_error)); + return Err(Error::::InstantiateExtrinsic(dispatch_error)) } } let account_id = account_id.expect("cannot extract `account_id` from events"); @@ -244,7 +279,7 @@ where .await; log_info(&format!("upload dry run: {dry_run:?}")); if dry_run.is_err() { - return Err(Error::::UploadDryRun(dry_run)); + return Err(Error::::UploadDryRun(dry_run)) } let tx_events = self.api.upload(signer, code, storage_deposit_limit).await; @@ -265,7 +300,7 @@ where uploaded.code_hash )); hash = Some(uploaded.code_hash); - break; + break } else if is_extrinsic_failed_event(&evt) { let metadata = self.api.client.metadata(); let dispatch_error = @@ -273,7 +308,7 @@ where .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for upload failed: {dispatch_error}")); - return Err(Error::::UploadExtrinsic(dispatch_error)); + return Err(Error::::UploadExtrinsic(dispatch_error)) } } @@ -430,7 +465,7 @@ where .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)); + return Err(Error::::CallExtrinsic(dispatch_error)) } } @@ -547,7 +582,7 @@ where let dry_run = self.call_dry_run(caller, message, value, None).await; if dry_run.exec_result.result.is_err() { - return Err(Error::::CallDryRun(dry_run.exec_result)); + return Err(Error::::CallDryRun(dry_run.exec_result)) } let tx_events = self @@ -573,7 +608,7 @@ where subxt::error::DispatchError::decode_from(evt.field_bytes(), metadata) .map_err(|e| Error::::Decoding(e.to_string()))?; log_error(&format!("extrinsic for call failed: {dispatch_error}")); - return Err(Error::::CallExtrinsic(dispatch_error)); + return Err(Error::::CallExtrinsic(dispatch_error)) } } diff --git a/integration-tests/call-builder-return-value/lib.rs b/integration-tests/call-builder-return-value/lib.rs index 515ffc1e164..e254730908d 100755 --- a/integration-tests/call-builder-return-value/lib.rs +++ b/integration-tests/call-builder-return-value/lib.rs @@ -7,18 +7,12 @@ mod call_builder { use ink::{ env::{ - call::{ - ExecutionInput, - Selector, - }, + call::{ExecutionInput, Selector}, DefaultEnvironment, }, prelude::{ format, - string::{ - String, - ToString, - }, + string::{String, ToString}, }, }; @@ -113,7 +107,7 @@ mod call_builder { mod e2e_tests { use super::*; use incrementer::IncrementerRef; - use ink_e2e::ChainBackend; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/call-runtime/lib.rs b/integration-tests/call-runtime/lib.rs index 03ab1799c35..ed8e40bf5b5 100644 --- a/integration-tests/call-runtime/lib.rs +++ b/integration-tests/call-runtime/lib.rs @@ -41,10 +41,7 @@ enum BalancesCall { #[ink::contract] mod runtime_call { - use crate::{ - BalancesCall, - RuntimeCall, - }; + use crate::{BalancesCall, RuntimeCall}; use ink::env::Error as EnvError; @@ -114,13 +111,10 @@ mod runtime_call { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::ChainBackend; + use ink_e2e::{ChainBackend, ContractsBackend}; use ink::{ - env::{ - test::default_accounts, - DefaultEnvironment, - }, + env::{test::default_accounts, DefaultEnvironment}, primitives::AccountId, }; diff --git a/integration-tests/contract-terminate/lib.rs b/integration-tests/contract-terminate/lib.rs index fe19dfcae0d..e8e50f89e5f 100644 --- a/integration-tests/contract-terminate/lib.rs +++ b/integration-tests/contract-terminate/lib.rs @@ -56,6 +56,8 @@ pub mod just_terminates { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; + type E2EResult = std::result::Result>; #[ink_e2e::test] diff --git a/integration-tests/contract-transfer/lib.rs b/integration-tests/contract-transfer/lib.rs index 008233e981a..49c9b2c5a14 100644 --- a/integration-tests/contract-transfer/lib.rs +++ b/integration-tests/contract-transfer/lib.rs @@ -182,7 +182,7 @@ pub mod give_me { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::ChainBackend; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/custom-allocator/lib.rs b/integration-tests/custom-allocator/lib.rs index 55629ff505d..aab2e02d7d1 100755 --- a/integration-tests/custom-allocator/lib.rs +++ b/integration-tests/custom-allocator/lib.rs @@ -38,10 +38,7 @@ static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc; #[ink::contract] mod custom_allocator { - use ink::prelude::{ - vec, - vec::Vec, - }; + use ink::prelude::{vec, vec::Vec}; #[ink(storage)] pub struct CustomAllocator { @@ -107,6 +104,7 @@ mod custom_allocator { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/custom-environment/lib.rs b/integration-tests/custom-environment/lib.rs index e14b9f6424e..52f84c35a8b 100644 --- a/integration-tests/custom-environment/lib.rs +++ b/integration-tests/custom-environment/lib.rs @@ -1,9 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -use ink::env::{ - DefaultEnvironment, - Environment, -}; +use ink::env::{DefaultEnvironment, Environment}; /// Our custom environment diverges from the `DefaultEnvironment` in the event topics /// limit. @@ -84,6 +81,7 @@ mod runtime_call { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = Result>; diff --git a/integration-tests/e2e-call-runtime/lib.rs b/integration-tests/e2e-call-runtime/lib.rs index a3657c13c5e..86a7b5582b8 100644 --- a/integration-tests/e2e-call-runtime/lib.rs +++ b/integration-tests/e2e-call-runtime/lib.rs @@ -21,10 +21,7 @@ pub mod e2e_call_runtime { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - subxt::dynamic::Value, - ChainBackend, - }; + use ink_e2e::{subxt::dynamic::Value, ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/erc20/lib.rs b/integration-tests/erc20/lib.rs index 668ba3859fb..3568fb095ad 100644 --- a/integration-tests/erc20/lib.rs +++ b/integration-tests/erc20/lib.rs @@ -175,7 +175,7 @@ mod erc20 { let caller = self.env().caller(); let allowance = self.allowance_impl(&from, &caller); if allowance < value { - return Err(Error::InsufficientAllowance) + return Err(Error::InsufficientAllowance); } self.transfer_from_to(&from, &to, value)?; self.allowances @@ -199,7 +199,7 @@ mod erc20 { ) -> Result<()> { let from_balance = self.balance_of_impl(from); if from_balance < value { - return Err(Error::InsufficientBalance) + return Err(Error::InsufficientBalance); } self.balances.insert(from, &(from_balance - value)); @@ -218,10 +218,7 @@ mod erc20 { mod tests { use super::*; - use ink::primitives::{ - Clear, - Hash, - }; + use ink::primitives::{Clear, Hash}; fn assert_transfer_event( event: &ink::env::test::EmittedEvent, @@ -481,11 +478,7 @@ mod erc20 { T: scale::Encode, { use ink::{ - env::hash::{ - Blake2x256, - CryptoHash, - HashOutput, - }, + env::hash::{Blake2x256, CryptoHash, HashOutput}, primitives::Clear, }; @@ -495,7 +488,7 @@ mod erc20 { let len_encoded = encoded.len(); if len_encoded <= len_result { result.as_mut()[..len_encoded].copy_from_slice(&encoded); - return result + return result; } let mut hash_output = <::Type as Default>::default(); @@ -509,6 +502,8 @@ mod erc20 { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; + type E2EResult = std::result::Result>; #[ink_e2e::test] diff --git a/integration-tests/events/lib.rs b/integration-tests/events/lib.rs index aa88c7af2f8..1b19daabb3d 100644 --- a/integration-tests/events/lib.rs +++ b/integration-tests/events/lib.rs @@ -201,7 +201,7 @@ pub mod events { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::H256; + use ink_e2e::{ChainBackend, ContractsBackend, H256}; type E2EResult = std::result::Result>; diff --git a/integration-tests/flipper/lib.rs b/integration-tests/flipper/lib.rs index e0e96e86fcb..91ca200a01e 100644 --- a/integration-tests/flipper/lib.rs +++ b/integration-tests/flipper/lib.rs @@ -55,6 +55,7 @@ pub mod flipper { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs b/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs index 0e39c31bf83..87b788ccbd6 100755 --- a/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs +++ b/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs @@ -19,11 +19,7 @@ #[ink::contract] mod call_builder { use ink::env::{ - call::{ - build_call, - ExecutionInput, - Selector, - }, + call::{build_call, ExecutionInput, Selector}, DefaultEnvironment, }; @@ -94,7 +90,7 @@ mod call_builder { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::ChainBackend; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/call-builder/lib.rs b/integration-tests/lang-err-integration-tests/call-builder/lib.rs index 56869004312..765d233fad9 100755 --- a/integration-tests/lang-err-integration-tests/call-builder/lib.rs +++ b/integration-tests/lang-err-integration-tests/call-builder/lib.rs @@ -20,11 +20,7 @@ mod call_builder { use constructors_return_value::ConstructorsReturnValueRef; use ink::env::{ - call::{ - build_call, - ExecutionInput, - Selector, - }, + call::{build_call, ExecutionInput, Selector}, DefaultEnvironment, }; @@ -166,11 +162,8 @@ mod call_builder { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::ChainBackend; - use integration_flipper::{ - Flipper, - FlipperRef, - }; + use ink_e2e::{ChainBackend, ContractsBackend}; + use integration_flipper::{Flipper, FlipperRef}; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs b/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs index 5d7d2d62b9e..b374b8f1c94 100644 --- a/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs +++ b/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs @@ -1,9 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] pub use self::constructors_return_value::{ - ConstructorError, - ConstructorsReturnValue, - ConstructorsReturnValueRef, + ConstructorError, ConstructorsReturnValue, ConstructorsReturnValueRef, }; #[ink::contract] @@ -107,6 +105,7 @@ pub mod constructors_return_value { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; use scale::Decode as _; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/contract-ref/lib.rs b/integration-tests/lang-err-integration-tests/contract-ref/lib.rs index 6c070d7bd28..5c7c708283d 100755 --- a/integration-tests/lang-err-integration-tests/contract-ref/lib.rs +++ b/integration-tests/lang-err-integration-tests/contract-ref/lib.rs @@ -68,6 +68,7 @@ mod contract_ref { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs b/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs index dceb8ea1da4..e7a6314a1d6 100644 --- a/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs +++ b/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs @@ -1,9 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -pub use self::integration_flipper::{ - Flipper, - FlipperRef, -}; +pub use self::integration_flipper::{Flipper, FlipperRef}; #[ink::contract] pub mod integration_flipper { @@ -67,6 +64,8 @@ pub mod integration_flipper { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; + type E2EResult = std::result::Result>; #[ink_e2e::test] diff --git a/integration-tests/mapping-integration-tests/lib.rs b/integration-tests/mapping-integration-tests/lib.rs index 64e32ac3088..e9f6e65f400 100755 --- a/integration-tests/mapping-integration-tests/lib.rs +++ b/integration-tests/mapping-integration-tests/lib.rs @@ -89,6 +89,8 @@ mod mapping_integration_tests { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; + type E2EResult = std::result::Result>; #[ink_e2e::test] diff --git a/integration-tests/multi-contract-caller/lib.rs b/integration-tests/multi-contract-caller/lib.rs index 960cd19c634..b8db0874a3c 100644 --- a/integration-tests/multi-contract-caller/lib.rs +++ b/integration-tests/multi-contract-caller/lib.rs @@ -115,6 +115,7 @@ mod multi_contract_caller { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/set-code-hash/lib.rs b/integration-tests/set-code-hash/lib.rs index dd632d35920..f4dddb5c19c 100644 --- a/integration-tests/set-code-hash/lib.rs +++ b/integration-tests/set-code-hash/lib.rs @@ -68,6 +68,7 @@ pub mod incrementer { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; type E2EResult = std::result::Result>; diff --git a/integration-tests/trait-dyn-cross-contract-calls/lib.rs b/integration-tests/trait-dyn-cross-contract-calls/lib.rs index 9d8f8309ffc..38124fbe393 100644 --- a/integration-tests/trait-dyn-cross-contract-calls/lib.rs +++ b/integration-tests/trait-dyn-cross-contract-calls/lib.rs @@ -43,15 +43,10 @@ pub mod caller { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { - use super::caller::{ - Caller, - CallerRef, - }; + use super::caller::{Caller, CallerRef}; use dyn_traits::Increment; - use trait_incrementer::incrementer::{ - Incrementer, - IncrementerRef, - }; + use ink_e2e::{ChainBackend, ContractsBackend}; + use trait_incrementer::incrementer::{Incrementer, IncrementerRef}; type E2EResult = Result>; diff --git a/integration-tests/wildcard-selector/lib.rs b/integration-tests/wildcard-selector/lib.rs index 729bd56c3d1..38dec93159d 100644 --- a/integration-tests/wildcard-selector/lib.rs +++ b/integration-tests/wildcard-selector/lib.rs @@ -37,12 +37,9 @@ pub mod wildcard_selector { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; + use ink_e2e::{ChainBackend, ContractsBackend}; - use ink::env::call::utils::{ - Argument, - ArgumentList, - EmptyArgumentList, - }; + use ink::env::call::utils::{Argument, ArgumentList, EmptyArgumentList}; type E2EResult = std::result::Result>; type Environment = ::Env; From 87e4e7d22c6f2d1829e12591c232ee4f01e6128c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 19:27:15 +0200 Subject: [PATCH 18/21] Fmt --- .../call-builder-return-value/lib.rs | 15 ++++++++++--- integration-tests/call-runtime/lib.rs | 15 ++++++++++--- integration-tests/contract-terminate/lib.rs | 5 ++++- integration-tests/contract-transfer/lib.rs | 5 ++++- integration-tests/custom-allocator/lib.rs | 10 +++++++-- integration-tests/custom-environment/lib.rs | 10 +++++++-- integration-tests/e2e-call-runtime/lib.rs | 6 ++++- integration-tests/erc20/lib.rs | 22 ++++++++++++++----- integration-tests/events/lib.rs | 6 ++++- integration-tests/flipper/lib.rs | 5 ++++- .../call-builder-delegate/lib.rs | 11 ++++++++-- .../call-builder/lib.rs | 16 +++++++++++--- .../constructors-return-value/lib.rs | 9 ++++++-- .../contract-ref/lib.rs | 5 ++++- .../integration-flipper/lib.rs | 10 +++++++-- .../mapping-integration-tests/lib.rs | 5 ++++- .../multi-contract-caller/lib.rs | 5 ++++- integration-tests/set-code-hash/lib.rs | 5 ++++- .../trait-dyn-cross-contract-calls/lib.rs | 15 ++++++++++--- integration-tests/wildcard-selector/lib.rs | 13 ++++++++--- 20 files changed, 153 insertions(+), 40 deletions(-) diff --git a/integration-tests/call-builder-return-value/lib.rs b/integration-tests/call-builder-return-value/lib.rs index e254730908d..b142da61ef2 100755 --- a/integration-tests/call-builder-return-value/lib.rs +++ b/integration-tests/call-builder-return-value/lib.rs @@ -7,12 +7,18 @@ mod call_builder { use ink::{ env::{ - call::{ExecutionInput, Selector}, + call::{ + ExecutionInput, + Selector, + }, DefaultEnvironment, }, prelude::{ format, - string::{String, ToString}, + string::{ + String, + ToString, + }, }, }; @@ -107,7 +113,10 @@ mod call_builder { mod e2e_tests { use super::*; use incrementer::IncrementerRef; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/call-runtime/lib.rs b/integration-tests/call-runtime/lib.rs index ed8e40bf5b5..80335a73264 100644 --- a/integration-tests/call-runtime/lib.rs +++ b/integration-tests/call-runtime/lib.rs @@ -41,7 +41,10 @@ enum BalancesCall { #[ink::contract] mod runtime_call { - use crate::{BalancesCall, RuntimeCall}; + use crate::{ + BalancesCall, + RuntimeCall, + }; use ink::env::Error as EnvError; @@ -111,10 +114,16 @@ mod runtime_call { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; use ink::{ - env::{test::default_accounts, DefaultEnvironment}, + env::{ + test::default_accounts, + DefaultEnvironment, + }, primitives::AccountId, }; diff --git a/integration-tests/contract-terminate/lib.rs b/integration-tests/contract-terminate/lib.rs index e8e50f89e5f..16419370361 100644 --- a/integration-tests/contract-terminate/lib.rs +++ b/integration-tests/contract-terminate/lib.rs @@ -56,7 +56,10 @@ pub mod just_terminates { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/contract-transfer/lib.rs b/integration-tests/contract-transfer/lib.rs index 49c9b2c5a14..06dafe99975 100644 --- a/integration-tests/contract-transfer/lib.rs +++ b/integration-tests/contract-transfer/lib.rs @@ -182,7 +182,10 @@ pub mod give_me { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/custom-allocator/lib.rs b/integration-tests/custom-allocator/lib.rs index aab2e02d7d1..85af8cba14e 100755 --- a/integration-tests/custom-allocator/lib.rs +++ b/integration-tests/custom-allocator/lib.rs @@ -38,7 +38,10 @@ static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc; #[ink::contract] mod custom_allocator { - use ink::prelude::{vec, vec::Vec}; + use ink::prelude::{ + vec, + vec::Vec, + }; #[ink(storage)] pub struct CustomAllocator { @@ -104,7 +107,10 @@ mod custom_allocator { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/custom-environment/lib.rs b/integration-tests/custom-environment/lib.rs index 52f84c35a8b..ae5dcf14f18 100644 --- a/integration-tests/custom-environment/lib.rs +++ b/integration-tests/custom-environment/lib.rs @@ -1,6 +1,9 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -use ink::env::{DefaultEnvironment, Environment}; +use ink::env::{ + DefaultEnvironment, + Environment, +}; /// Our custom environment diverges from the `DefaultEnvironment` in the event topics /// limit. @@ -81,7 +84,10 @@ mod runtime_call { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = Result>; diff --git a/integration-tests/e2e-call-runtime/lib.rs b/integration-tests/e2e-call-runtime/lib.rs index 86a7b5582b8..98ff0663fca 100644 --- a/integration-tests/e2e-call-runtime/lib.rs +++ b/integration-tests/e2e-call-runtime/lib.rs @@ -21,7 +21,11 @@ pub mod e2e_call_runtime { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{subxt::dynamic::Value, ChainBackend, ContractsBackend}; + use ink_e2e::{ + subxt::dynamic::Value, + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/erc20/lib.rs b/integration-tests/erc20/lib.rs index 3568fb095ad..4b05d609b5e 100644 --- a/integration-tests/erc20/lib.rs +++ b/integration-tests/erc20/lib.rs @@ -175,7 +175,7 @@ mod erc20 { let caller = self.env().caller(); let allowance = self.allowance_impl(&from, &caller); if allowance < value { - return Err(Error::InsufficientAllowance); + return Err(Error::InsufficientAllowance) } self.transfer_from_to(&from, &to, value)?; self.allowances @@ -199,7 +199,7 @@ mod erc20 { ) -> Result<()> { let from_balance = self.balance_of_impl(from); if from_balance < value { - return Err(Error::InsufficientBalance); + return Err(Error::InsufficientBalance) } self.balances.insert(from, &(from_balance - value)); @@ -218,7 +218,10 @@ mod erc20 { mod tests { use super::*; - use ink::primitives::{Clear, Hash}; + use ink::primitives::{ + Clear, + Hash, + }; fn assert_transfer_event( event: &ink::env::test::EmittedEvent, @@ -478,7 +481,11 @@ mod erc20 { T: scale::Encode, { use ink::{ - env::hash::{Blake2x256, CryptoHash, HashOutput}, + env::hash::{ + Blake2x256, + CryptoHash, + HashOutput, + }, primitives::Clear, }; @@ -488,7 +495,7 @@ mod erc20 { let len_encoded = encoded.len(); if len_encoded <= len_result { result.as_mut()[..len_encoded].copy_from_slice(&encoded); - return result; + return result } let mut hash_output = <::Type as Default>::default(); @@ -502,7 +509,10 @@ mod erc20 { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/events/lib.rs b/integration-tests/events/lib.rs index 1b19daabb3d..2d8ac3f48f5 100644 --- a/integration-tests/events/lib.rs +++ b/integration-tests/events/lib.rs @@ -201,7 +201,11 @@ pub mod events { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend, H256}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + H256, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/flipper/lib.rs b/integration-tests/flipper/lib.rs index 91ca200a01e..48473b9dc6c 100644 --- a/integration-tests/flipper/lib.rs +++ b/integration-tests/flipper/lib.rs @@ -55,7 +55,10 @@ pub mod flipper { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs b/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs index 87b788ccbd6..9c5034636e7 100755 --- a/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs +++ b/integration-tests/lang-err-integration-tests/call-builder-delegate/lib.rs @@ -19,7 +19,11 @@ #[ink::contract] mod call_builder { use ink::env::{ - call::{build_call, ExecutionInput, Selector}, + call::{ + build_call, + ExecutionInput, + Selector, + }, DefaultEnvironment, }; @@ -90,7 +94,10 @@ mod call_builder { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/call-builder/lib.rs b/integration-tests/lang-err-integration-tests/call-builder/lib.rs index 765d233fad9..beff3de39ef 100755 --- a/integration-tests/lang-err-integration-tests/call-builder/lib.rs +++ b/integration-tests/lang-err-integration-tests/call-builder/lib.rs @@ -20,7 +20,11 @@ mod call_builder { use constructors_return_value::ConstructorsReturnValueRef; use ink::env::{ - call::{build_call, ExecutionInput, Selector}, + call::{ + build_call, + ExecutionInput, + Selector, + }, DefaultEnvironment, }; @@ -162,8 +166,14 @@ mod call_builder { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; - use integration_flipper::{Flipper, FlipperRef}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; + use integration_flipper::{ + Flipper, + FlipperRef, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs b/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs index b374b8f1c94..732baabc925 100644 --- a/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs +++ b/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs @@ -1,7 +1,9 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] pub use self::constructors_return_value::{ - ConstructorError, ConstructorsReturnValue, ConstructorsReturnValueRef, + ConstructorError, + ConstructorsReturnValue, + ConstructorsReturnValueRef, }; #[ink::contract] @@ -105,7 +107,10 @@ pub mod constructors_return_value { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; use scale::Decode as _; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/contract-ref/lib.rs b/integration-tests/lang-err-integration-tests/contract-ref/lib.rs index 5c7c708283d..4aafef0ab62 100755 --- a/integration-tests/lang-err-integration-tests/contract-ref/lib.rs +++ b/integration-tests/lang-err-integration-tests/contract-ref/lib.rs @@ -68,7 +68,10 @@ mod contract_ref { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs b/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs index e7a6314a1d6..10cce31e1e9 100644 --- a/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs +++ b/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs @@ -1,6 +1,9 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -pub use self::integration_flipper::{Flipper, FlipperRef}; +pub use self::integration_flipper::{ + Flipper, + FlipperRef, +}; #[ink::contract] pub mod integration_flipper { @@ -64,7 +67,10 @@ pub mod integration_flipper { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/mapping-integration-tests/lib.rs b/integration-tests/mapping-integration-tests/lib.rs index e9f6e65f400..1951dde3a0e 100755 --- a/integration-tests/mapping-integration-tests/lib.rs +++ b/integration-tests/mapping-integration-tests/lib.rs @@ -89,7 +89,10 @@ mod mapping_integration_tests { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/multi-contract-caller/lib.rs b/integration-tests/multi-contract-caller/lib.rs index b8db0874a3c..f3a94dc6ff6 100644 --- a/integration-tests/multi-contract-caller/lib.rs +++ b/integration-tests/multi-contract-caller/lib.rs @@ -115,7 +115,10 @@ mod multi_contract_caller { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/set-code-hash/lib.rs b/integration-tests/set-code-hash/lib.rs index f4dddb5c19c..2008595a9c5 100644 --- a/integration-tests/set-code-hash/lib.rs +++ b/integration-tests/set-code-hash/lib.rs @@ -68,7 +68,10 @@ pub mod incrementer { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; type E2EResult = std::result::Result>; diff --git a/integration-tests/trait-dyn-cross-contract-calls/lib.rs b/integration-tests/trait-dyn-cross-contract-calls/lib.rs index 38124fbe393..2313a3c0917 100644 --- a/integration-tests/trait-dyn-cross-contract-calls/lib.rs +++ b/integration-tests/trait-dyn-cross-contract-calls/lib.rs @@ -43,10 +43,19 @@ pub mod caller { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { - use super::caller::{Caller, CallerRef}; + use super::caller::{ + Caller, + CallerRef, + }; use dyn_traits::Increment; - use ink_e2e::{ChainBackend, ContractsBackend}; - use trait_incrementer::incrementer::{Incrementer, IncrementerRef}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; + use trait_incrementer::incrementer::{ + Incrementer, + IncrementerRef, + }; type E2EResult = Result>; diff --git a/integration-tests/wildcard-selector/lib.rs b/integration-tests/wildcard-selector/lib.rs index 38dec93159d..2f056640c98 100644 --- a/integration-tests/wildcard-selector/lib.rs +++ b/integration-tests/wildcard-selector/lib.rs @@ -37,9 +37,16 @@ pub mod wildcard_selector { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ChainBackend, ContractsBackend}; - - use ink::env::call::utils::{Argument, ArgumentList, EmptyArgumentList}; + use ink_e2e::{ + ChainBackend, + ContractsBackend, + }; + + use ink::env::call::utils::{ + Argument, + ArgumentList, + EmptyArgumentList, + }; type E2EResult = std::result::Result>; type Environment = ::Env; From 448b78a9c06493215d47338159439b05d3d0c183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 27 Jul 2023 23:09:16 +0200 Subject: [PATCH 19/21] New contract-build --- Cargo.toml | 2 +- crates/e2e/macro/src/codegen.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 51795de994e..330f90c9d02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ array-init = { version = "2.0", default-features = false } blake2 = { version = "0.10" } cargo_metadata = { version = "0.17.0" } cfg-if = { version = "1.0" } -contract-build = { version = "3.0.1" } +contract-build = { version = "4.0.0-alpha" } derive_more = { version = "0.99.17", default-features = false } either = { version = "1.5", default-features = false } funty = { version = "2.0.0" } diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index fb81939c4c1..07d4c87847c 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -293,6 +293,7 @@ fn build_contract(path_to_cargo_toml: &str) -> String { output_type: OutputType::HumanReadable, skip_wasm_validation: false, target: Target::Wasm, + ..Default::default() }; match contract_build::execute(args) { From 4ac14886cffd10ee8948407587fde88a0359c00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 28 Jul 2023 18:01:13 +0200 Subject: [PATCH 20/21] Add license to recently added files --- crates/e2e/src/backend.rs | 14 ++++++++++++++ crates/e2e/src/contract_results.rs | 14 ++++++++++++++ crates/e2e/src/error.rs | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index 818b43c40e5..c334f9c298e 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -1,3 +1,17 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use crate::{ builders::CreateBuilderPartial, CallBuilderFinal, diff --git a/crates/e2e/src/contract_results.rs b/crates/e2e/src/contract_results.rs index 982691163f0..63c661e4b99 100644 --- a/crates/e2e/src/contract_results.rs +++ b/crates/e2e/src/contract_results.rs @@ -1,3 +1,17 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use ink::codegen::ContractCallBuilder; use ink_env::{ call::FromAccountId, diff --git a/crates/e2e/src/error.rs b/crates/e2e/src/error.rs index e3242d99a57..33de1d4113b 100644 --- a/crates/e2e/src/error.rs +++ b/crates/e2e/src/error.rs @@ -1,3 +1,17 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use pallet_contracts_primitives::{ CodeUploadResult, ContractExecResult, From cff7fa49881939d3d77940ae2e627b9d9c5c48d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Sat, 29 Jul 2023 23:02:19 +0200 Subject: [PATCH 21/21] Don't import ChainBackend if not needed --- integration-tests/contract-terminate/lib.rs | 5 +---- integration-tests/custom-allocator/lib.rs | 5 +---- integration-tests/custom-environment/lib.rs | 5 +---- integration-tests/erc20/lib.rs | 5 +---- integration-tests/events/lib.rs | 1 - integration-tests/flipper/lib.rs | 5 +---- .../constructors-return-value/lib.rs | 7 ++----- .../lang-err-integration-tests/contract-ref/lib.rs | 5 +---- .../lang-err-integration-tests/integration-flipper/lib.rs | 5 +---- integration-tests/mapping-integration-tests/lib.rs | 5 +---- integration-tests/multi-contract-caller/lib.rs | 5 +---- integration-tests/set-code-hash/lib.rs | 5 +---- integration-tests/trait-dyn-cross-contract-calls/lib.rs | 5 +---- integration-tests/wildcard-selector/lib.rs | 5 +---- 14 files changed, 14 insertions(+), 54 deletions(-) diff --git a/integration-tests/contract-terminate/lib.rs b/integration-tests/contract-terminate/lib.rs index 16419370361..c215d089565 100644 --- a/integration-tests/contract-terminate/lib.rs +++ b/integration-tests/contract-terminate/lib.rs @@ -56,10 +56,7 @@ pub mod just_terminates { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/custom-allocator/lib.rs b/integration-tests/custom-allocator/lib.rs index 85af8cba14e..ab4f21d3f1e 100755 --- a/integration-tests/custom-allocator/lib.rs +++ b/integration-tests/custom-allocator/lib.rs @@ -107,10 +107,7 @@ mod custom_allocator { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/custom-environment/lib.rs b/integration-tests/custom-environment/lib.rs index ae5dcf14f18..ce974f8aedd 100644 --- a/integration-tests/custom-environment/lib.rs +++ b/integration-tests/custom-environment/lib.rs @@ -84,10 +84,7 @@ mod runtime_call { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = Result>; diff --git a/integration-tests/erc20/lib.rs b/integration-tests/erc20/lib.rs index 4b05d609b5e..64b2d743e9b 100644 --- a/integration-tests/erc20/lib.rs +++ b/integration-tests/erc20/lib.rs @@ -509,10 +509,7 @@ mod erc20 { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/events/lib.rs b/integration-tests/events/lib.rs index 2d8ac3f48f5..c7618f6be89 100644 --- a/integration-tests/events/lib.rs +++ b/integration-tests/events/lib.rs @@ -202,7 +202,6 @@ pub mod events { mod e2e_tests { use super::*; use ink_e2e::{ - ChainBackend, ContractsBackend, H256, }; diff --git a/integration-tests/flipper/lib.rs b/integration-tests/flipper/lib.rs index 48473b9dc6c..3dd658a769d 100644 --- a/integration-tests/flipper/lib.rs +++ b/integration-tests/flipper/lib.rs @@ -55,10 +55,7 @@ pub mod flipper { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs b/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs index 732baabc925..51a9b5b27ec 100644 --- a/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs +++ b/integration-tests/lang-err-integration-tests/constructors-return-value/lib.rs @@ -107,10 +107,7 @@ pub mod constructors_return_value { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; use scale::Decode as _; type E2EResult = std::result::Result>; @@ -201,7 +198,7 @@ pub mod constructors_return_value { ) .await .expect("instantiate failed"); - let mut call = contract.call::(); + let call = contract.call::(); let get = call.get_value(); let value = client diff --git a/integration-tests/lang-err-integration-tests/contract-ref/lib.rs b/integration-tests/lang-err-integration-tests/contract-ref/lib.rs index 4aafef0ab62..e305250e054 100755 --- a/integration-tests/lang-err-integration-tests/contract-ref/lib.rs +++ b/integration-tests/lang-err-integration-tests/contract-ref/lib.rs @@ -68,10 +68,7 @@ mod contract_ref { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs b/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs index 10cce31e1e9..2cea0bd0186 100644 --- a/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs +++ b/integration-tests/lang-err-integration-tests/integration-flipper/lib.rs @@ -67,10 +67,7 @@ pub mod integration_flipper { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/mapping-integration-tests/lib.rs b/integration-tests/mapping-integration-tests/lib.rs index 1951dde3a0e..7f15c46f6da 100755 --- a/integration-tests/mapping-integration-tests/lib.rs +++ b/integration-tests/mapping-integration-tests/lib.rs @@ -89,10 +89,7 @@ mod mapping_integration_tests { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/multi-contract-caller/lib.rs b/integration-tests/multi-contract-caller/lib.rs index f3a94dc6ff6..fc5d4a8d35e 100644 --- a/integration-tests/multi-contract-caller/lib.rs +++ b/integration-tests/multi-contract-caller/lib.rs @@ -115,10 +115,7 @@ mod multi_contract_caller { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/set-code-hash/lib.rs b/integration-tests/set-code-hash/lib.rs index 2008595a9c5..c90bcbb5362 100644 --- a/integration-tests/set-code-hash/lib.rs +++ b/integration-tests/set-code-hash/lib.rs @@ -68,10 +68,7 @@ pub mod incrementer { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; diff --git a/integration-tests/trait-dyn-cross-contract-calls/lib.rs b/integration-tests/trait-dyn-cross-contract-calls/lib.rs index 2313a3c0917..8366e97bd70 100644 --- a/integration-tests/trait-dyn-cross-contract-calls/lib.rs +++ b/integration-tests/trait-dyn-cross-contract-calls/lib.rs @@ -48,10 +48,7 @@ mod e2e_tests { CallerRef, }; use dyn_traits::Increment; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; use trait_incrementer::incrementer::{ Incrementer, IncrementerRef, diff --git a/integration-tests/wildcard-selector/lib.rs b/integration-tests/wildcard-selector/lib.rs index 2f056640c98..a1bda19f0bd 100644 --- a/integration-tests/wildcard-selector/lib.rs +++ b/integration-tests/wildcard-selector/lib.rs @@ -37,10 +37,7 @@ pub mod wildcard_selector { #[cfg(all(test, feature = "e2e-tests"))] mod e2e_tests { use super::*; - use ink_e2e::{ - ChainBackend, - ContractsBackend, - }; + use ink_e2e::ContractsBackend; use ink::env::call::utils::{ Argument,