diff --git a/crates/e2e/Cargo.toml b/crates/e2e/Cargo.toml index f6e11ca7dc7..2c8ce9c6145 100644 --- a/crates/e2e/Cargo.toml +++ b/crates/e2e/Cargo.toml @@ -29,7 +29,8 @@ tokio = { version = "1.18.2", features = ["rt-multi-thread"] } log = { version = "0.4" } env_logger = { version = "0.10" } scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] } -subxt = "0.28.0" +subxt = "0.31.0" +subxt-signer = { version = "0.31.0", features = ["subxt", "sr25519"] } # Substrate pallet-contracts-primitives = "24.0.0" diff --git a/crates/e2e/src/client.rs b/crates/e2e/src/client.rs index 8165f7f6a7a..5c39a66826a 100644 --- a/crates/e2e/src/client.rs +++ b/crates/e2e/src/client.rs @@ -25,12 +25,11 @@ use super::{ ContractExecResult, ContractInstantiateResult, ContractsApi, - Signer, + Keypair, }; use ink_env::Environment; use ink_primitives::MessageResult; use pallet_contracts_primitives::ExecReturnValue; -use sp_core::Pair; #[cfg(feature = "std")] use std::{ collections::BTreeMap, @@ -52,7 +51,8 @@ use subxt::{ ValueDef, }, }, - tx::PairSigner, + tx::Signer, + Config, }; /// Result of a contract instantiation. @@ -61,7 +61,7 @@ pub struct InstantiationResult { pub account_id: E::AccountId, /// The result of the dry run, contains debug messages /// if there were any. - pub dry_run: ContractInstantiateResult, + pub dry_run: ContractInstantiateResult, /// Events that happened with the contract instantiation. pub events: ExtrinsicEvents, } @@ -191,7 +191,7 @@ where pub struct CallDryRunResult { /// The result of the dry run, contains debug messages /// if there were any. - pub exec_result: ContractExecResult, + pub exec_result: ContractExecResult, _marker: PhantomData, } @@ -271,7 +271,7 @@ where /// No contract with the given name found in scope. ContractNotFound(String), /// The `instantiate_with_code` dry run failed. - InstantiateDryRun(ContractInstantiateResult), + InstantiateDryRun(ContractInstantiateResult), /// The `instantiate_with_code` extrinsic failed. InstantiateExtrinsic(subxt::error::DispatchError), /// The `upload` dry run failed. @@ -279,7 +279,7 @@ where /// The `upload` extrinsic failed. UploadExtrinsic(subxt::error::DispatchError), /// The `call` dry run failed. - CallDryRun(ContractExecResult), + CallDryRun(ContractExecResult), /// The `call` extrinsic failed. CallExtrinsic(subxt::error::DispatchError), /// Error fetching account balance. @@ -383,12 +383,11 @@ where impl Client where C: subxt::Config, - C::AccountId: From - + scale::Codec - + serde::de::DeserializeOwned - + Debug, + C::AccountId: + From + scale::Codec + serde::de::DeserializeOwned + Debug, + C::Address: From, C::Signature: From, - >::OtherParams: Default, + >::OtherParams: Default, E: Environment, E::AccountId: Debug, @@ -424,17 +423,21 @@ where /// number of times. pub async fn create_and_fund_account( &self, - origin: &Signer, + origin: &Keypair, amount: E::Balance, - ) -> Signer + ) -> Keypair 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(); + let (_, phrase, _) = + ::generate_with_phrase(None); + let phrase = + subxt_signer::bip39::Mnemonic::parse(phrase).expect("valid phrase expected"); + let keypair = Keypair::from_phrase(&phrase, None).expect("valid phrase expected"); + let account_id = >::account_id(&keypair); + let origin_account_id = origin.public_key().to_account_id(); self.api .try_transfer_balance(origin, account_id.clone(), amount) @@ -442,19 +445,16 @@ where .unwrap_or_else(|err| { panic!( "transfer from {} to {} failed with {:?}", - origin.account_id(), - account_id, - err + origin_account_id, account_id, err ) }); log_info(&format!( "transfer from {} to {} succeeded", - origin.account_id(), - account_id, + origin_account_id, account_id, )); - pair_signer + keypair } /// This function extracts the metadata of the contract at the file path @@ -468,7 +468,7 @@ where pub async fn instantiate( &mut self, contract_name: &str, - signer: &Signer, + signer: &Keypair, constructor: CreateBuilderPartial, value: E::Balance, storage_deposit_limit: Option, @@ -488,11 +488,11 @@ where pub async fn instantiate_dry_run( &mut self, contract_name: &str, - signer: &Signer, + signer: &Keypair, constructor: CreateBuilderPartial, value: E::Balance, storage_deposit_limit: Option, - ) -> ContractInstantiateResult + ) -> ContractInstantiateResult where Args: scale::Encode, { @@ -535,7 +535,7 @@ where /// Executes an `instantiate_with_code` call and captures the resulting events. async fn exec_instantiate( &mut self, - signer: &Signer, + signer: &Keypair, code: Vec, constructor: CreateBuilderPartial, value: E::Balance, @@ -646,7 +646,7 @@ where pub async fn upload( &mut self, contract_name: &str, - signer: &Signer, + signer: &Keypair, storage_deposit_limit: Option, ) -> Result, Error> { let code = self.load_code(contract_name); @@ -660,7 +660,7 @@ where /// Executes an `upload` call and captures the resulting events. pub async fn exec_upload( &mut self, - signer: &Signer, + signer: &Keypair, code: Vec, storage_deposit_limit: Option, ) -> Result, Error> { @@ -731,7 +731,7 @@ where /// contains all events that are associated with this transaction. pub async fn call( &mut self, - signer: &Signer, + signer: &Keypair, message: Message, value: E::Balance, storage_deposit_limit: Option, @@ -793,7 +793,7 @@ where /// contains all events that are associated with this transaction. pub async fn runtime_call<'a>( &mut self, - signer: &Signer, + signer: &Keypair, pallet_name: &'a str, call_name: &'a str, call_data: Vec, @@ -828,7 +828,7 @@ where /// invoked message. pub async fn call_dry_run( &mut self, - signer: &Signer, + signer: &Keypair, message: &Message, value: E::Balance, storage_deposit_limit: Option, @@ -839,7 +839,7 @@ where let exec_result = self .api .call_dry_run( - Signer::account_id(signer).clone(), + Signer::::account_id(signer), message, value, storage_deposit_limit, @@ -940,6 +940,6 @@ where } /// Returns true if the give event is System::Extrinsic failed. -fn is_extrinsic_failed_event(event: &EventDetails) -> bool { +fn is_extrinsic_failed_event(event: &EventDetails) -> bool { event.pallet_name() == "System" && event.variant_name() == "ExtrinsicFailed" } diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 445286cbf9c..0310cd0305f 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -21,7 +21,6 @@ mod builders; mod client; -mod default_accounts; mod node_proc; mod xts; @@ -37,7 +36,6 @@ pub use client::{ InstantiationResult, UploadResult, }; -pub use default_accounts::*; pub use env_logger; pub use ink_e2e_macro::test; pub use node_proc::{ @@ -46,9 +44,11 @@ pub use node_proc::{ }; pub use sp_core::H256; pub use sp_keyring::AccountKeyring; -pub use subxt::{ +pub use subxt; +pub use subxt_signer::sr25519::{ self, - tx::PairSigner, + dev::*, + Keypair, }; pub use tokio; @@ -57,44 +57,13 @@ use pallet_contracts_primitives::{ ContractExecResult, ContractInstantiateResult, }; -use sp_core::sr25519; use std::{ cell::RefCell, sync::Once, }; use xts::ContractsApi; -/// Default set of commonly used types by Substrate runtimes. -#[cfg(feature = "std")] -pub enum SubstrateConfig {} - -#[cfg(feature = "std")] -impl subxt::Config for SubstrateConfig { - type Index = u32; - type Hash = sp_core::H256; - type Hasher = subxt::config::substrate::BlakeTwo256; - type AccountId = subxt::config::substrate::AccountId32; - type Address = sp_runtime::MultiAddress; - type Header = subxt::config::substrate::SubstrateHeader< - u32, - subxt::config::substrate::BlakeTwo256, - >; - type Signature = sp_runtime::MultiSignature; - type ExtrinsicParams = subxt::config::substrate::SubstrateExtrinsicParams; -} - -/// Default set of commonly used types by Polkadot nodes. -#[cfg(feature = "std")] -pub type PolkadotConfig = subxt::config::WithExtrinsicParams< - SubstrateConfig, - subxt::config::polkadot::PolkadotExtrinsicParams, ->; - -/// Signer that is used throughout the E2E testing. -/// -/// The E2E testing can only be used with nodes that support `sr25519` -/// cryptography. -pub type Signer = PairSigner; +pub use subxt::PolkadotConfig; /// We use this to only initialize `env_logger` once. pub static INIT: Once = Once::new(); diff --git a/crates/e2e/src/xts.rs b/crates/e2e/src/xts.rs index ffccdb344c1..7c28360bafa 100644 --- a/crates/e2e/src/xts.rs +++ b/crates/e2e/src/xts.rs @@ -18,7 +18,7 @@ use super::{ sr25519, ContractExecResult, ContractInstantiateResult, - Signer, + Keypair, }; use ink_env::Environment; @@ -33,6 +33,7 @@ use subxt::{ config::ExtrinsicParams, ext::scale_encode, rpc_params, + tx::Signer, utils::MultiAddress, OnlineClient, }; @@ -210,10 +211,10 @@ pub struct ContractsApi { impl ContractsApi where C: subxt::Config, - C::AccountId: serde::de::DeserializeOwned, - C::AccountId: scale::Codec, + C::AccountId: From + serde::de::DeserializeOwned + scale::Codec, + C::Address: From, C::Signature: From, - >::OtherParams: Default, + >::OtherParams: Default, E: Environment, E::Balance: scale::HasCompact + serde::Serialize, @@ -232,7 +233,7 @@ where /// invalid (e.g. out of date nonce) pub async fn try_transfer_balance( &self, - origin: &Signer, + origin: &Keypair, dest: C::AccountId, value: E::Balance, ) -> Result<(), subxt::Error> { @@ -267,11 +268,11 @@ where code: Vec, data: Vec, salt: Vec, - signer: &Signer, - ) -> ContractInstantiateResult { + signer: &Keypair, + ) -> ContractInstantiateResult { let code = Code::Upload(code); let call_request = RpcInstantiateRequest:: { - origin: subxt::tx::Signer::account_id(signer).clone(), + origin: Signer::::account_id(signer), value, gas_limit: None, storage_deposit_limit, @@ -298,7 +299,7 @@ where pub async fn submit_extrinsic( &self, call: &Call, - signer: &Signer, + signer: &Keypair, ) -> ExtrinsicEvents where Call: subxt::tx::TxPayload, @@ -342,7 +343,7 @@ where code: Vec, data: Vec, salt: Vec, - signer: &Signer, + signer: &Keypair, ) -> ExtrinsicEvents { let call = subxt::tx::Payload::new( "Contracts", @@ -364,12 +365,12 @@ where /// Dry runs the upload of the given `code`. pub async fn upload_dry_run( &self, - signer: &Signer, + signer: &Keypair, code: Vec, storage_deposit_limit: Option, ) -> CodeUploadResult { let call_request = RpcCodeUploadRequest:: { - origin: subxt::tx::Signer::account_id(signer).clone(), + origin: Signer::::account_id(signer), code, storage_deposit_limit, determinism: Determinism::Deterministic, @@ -394,7 +395,7 @@ where /// contains all events that are associated with this transaction. pub async fn upload( &self, - signer: &Signer, + signer: &Keypair, code: Vec, storage_deposit_limit: Option, ) -> ExtrinsicEvents { @@ -419,7 +420,7 @@ where message: &Message, value: E::Balance, storage_deposit_limit: Option, - ) -> ContractExecResult { + ) -> ContractExecResult { let call_request = RpcCallRequest:: { origin, dest: message.account_id().clone(), @@ -453,7 +454,7 @@ where gas_limit: Weight, storage_deposit_limit: Option, data: Vec, - signer: &Signer, + signer: &Keypair, ) -> ExtrinsicEvents { let call = subxt::tx::Payload::new( "Contracts", @@ -479,7 +480,7 @@ where /// contains all events that are associated with this transaction. pub async fn runtime_call<'a>( &self, - signer: &Signer, + signer: &Keypair, pallet_name: &'a str, call_name: &'a str, call_data: Vec, diff --git a/crates/env/Cargo.toml b/crates/env/Cargo.toml index c1676ede5ec..8757e749152 100644 --- a/crates/env/Cargo.toml +++ b/crates/env/Cargo.toml @@ -47,8 +47,8 @@ secp256k1 = { version = "0.27.0", features = ["recovery", "global-context"], opt # # Sadly couldn't be marked as dev-dependency. # Never use this crate outside the off-chain environment! -scale-decode = { version = "0.5.0", default-features = false, optional = true } -scale-encode = { version = "0.1.0", default-features = false, optional = true } +scale-decode = { version = "0.9.0", default-features = false, optional = true } +scale-encode = { version = "0.5.0", default-features = false, optional = true } scale-info = { version = "2.5", default-features = false, features = ["derive"], optional = true } [dev-dependencies] diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 3ad1c251bc3..5ad52bd57a9 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -18,8 +18,8 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"] derive_more = { version = "0.99", default-features = false, features = ["from", "display"] } ink_prelude = { version = "4.2.1", path = "../prelude/", default-features = false } scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] } -scale-decode = { version = "0.5.0", default-features = false, features = ["derive"], optional = true } -scale-encode = { version = "0.1.0", default-features = false, features = ["derive"], optional = true } +scale-decode = { version = "0.9.0", default-features = false, features = ["derive"], optional = true } +scale-encode = { version = "0.5.0", default-features = false, features = ["derive"], optional = true } scale-info = { version = "2.5", default-features = false, features = ["derive"], optional = true } xxhash-rust = { version = "0.8", features = ["const_xxh32"] }