Skip to content

Commit 26c1e50

Browse files
committed
Manual backports of #1795 and #1855 to update subxt
1 parent 949c00a commit 26c1e50

File tree

6 files changed

+62
-91
lines changed

6 files changed

+62
-91
lines changed

crates/e2e/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ tokio = { version = "1.18.2", features = ["rt-multi-thread"] }
2929
log = { version = "0.4" }
3030
env_logger = { version = "0.10" }
3131
scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] }
32-
subxt = "0.28.0"
32+
subxt = "0.31.0"
33+
subxt-signer = { version = "0.31.0", features = ["subxt", "sr25519"] }
3334

3435
# Substrate
3536
pallet-contracts-primitives = "24.0.0"

crates/e2e/src/client.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ use super::{
2525
ContractExecResult,
2626
ContractInstantiateResult,
2727
ContractsApi,
28-
Signer,
28+
Keypair,
2929
};
3030
use ink_env::Environment;
3131
use ink_primitives::MessageResult;
3232
use pallet_contracts_primitives::ExecReturnValue;
33-
use sp_core::Pair;
3433
#[cfg(feature = "std")]
3534
use std::{
3635
collections::BTreeMap,
@@ -52,7 +51,8 @@ use subxt::{
5251
ValueDef,
5352
},
5453
},
55-
tx::PairSigner,
54+
tx::Signer,
55+
Config,
5656
};
5757

5858
/// Result of a contract instantiation.
@@ -61,7 +61,7 @@ pub struct InstantiationResult<C: subxt::Config, E: Environment> {
6161
pub account_id: E::AccountId,
6262
/// The result of the dry run, contains debug messages
6363
/// if there were any.
64-
pub dry_run: ContractInstantiateResult<C::AccountId, E::Balance>,
64+
pub dry_run: ContractInstantiateResult<C::AccountId, E::Balance, ()>,
6565
/// Events that happened with the contract instantiation.
6666
pub events: ExtrinsicEvents<C>,
6767
}
@@ -191,7 +191,7 @@ where
191191
pub struct CallDryRunResult<E: Environment, V> {
192192
/// The result of the dry run, contains debug messages
193193
/// if there were any.
194-
pub exec_result: ContractExecResult<E::Balance>,
194+
pub exec_result: ContractExecResult<E::Balance, ()>,
195195
_marker: PhantomData<V>,
196196
}
197197

@@ -271,15 +271,15 @@ where
271271
/// No contract with the given name found in scope.
272272
ContractNotFound(String),
273273
/// The `instantiate_with_code` dry run failed.
274-
InstantiateDryRun(ContractInstantiateResult<C::AccountId, E::Balance>),
274+
InstantiateDryRun(ContractInstantiateResult<C::AccountId, E::Balance, ()>),
275275
/// The `instantiate_with_code` extrinsic failed.
276276
InstantiateExtrinsic(subxt::error::DispatchError),
277277
/// The `upload` dry run failed.
278278
UploadDryRun(CodeUploadResult<E::Hash, E::Balance>),
279279
/// The `upload` extrinsic failed.
280280
UploadExtrinsic(subxt::error::DispatchError),
281281
/// The `call` dry run failed.
282-
CallDryRun(ContractExecResult<E::Balance>),
282+
CallDryRun(ContractExecResult<E::Balance, ()>),
283283
/// The `call` extrinsic failed.
284284
CallExtrinsic(subxt::error::DispatchError),
285285
/// Error fetching account balance.
@@ -383,12 +383,11 @@ where
383383
impl<C, E> Client<C, E>
384384
where
385385
C: subxt::Config,
386-
C::AccountId: From<sp_runtime::AccountId32>
387-
+ scale::Codec
388-
+ serde::de::DeserializeOwned
389-
+ Debug,
386+
C::AccountId:
387+
From<sr25519::PublicKey> + scale::Codec + serde::de::DeserializeOwned + Debug,
388+
C::Address: From<sr25519::PublicKey>,
390389
C::Signature: From<sr25519::Signature>,
391-
<C::ExtrinsicParams as ExtrinsicParams<C::Index, C::Hash>>::OtherParams: Default,
390+
<C::ExtrinsicParams as ExtrinsicParams<C::Hash>>::OtherParams: Default,
392391

393392
E: Environment,
394393
E::AccountId: Debug,
@@ -424,37 +423,38 @@ where
424423
/// number of times.
425424
pub async fn create_and_fund_account(
426425
&self,
427-
origin: &Signer<C>,
426+
origin: &Keypair,
428427
amount: E::Balance,
429-
) -> Signer<C>
428+
) -> Keypair
430429
where
431430
E::Balance: Clone,
432431
C::AccountId: Clone + core::fmt::Display + Debug,
433432
C::AccountId: From<sp_core::crypto::AccountId32>,
434433
{
435-
let (pair, _, _) = <sr25519::Pair as Pair>::generate_with_phrase(None);
436-
let pair_signer = PairSigner::<C, _>::new(pair);
437-
let account_id = pair_signer.account_id().to_owned();
434+
let (_, phrase, _) =
435+
<sp_core::sr25519::Pair as sp_core::Pair>::generate_with_phrase(None);
436+
let phrase =
437+
subxt_signer::bip39::Mnemonic::parse(phrase).expect("valid phrase expected");
438+
let keypair = Keypair::from_phrase(&phrase, None).expect("valid phrase expected");
439+
let account_id = <Keypair as Signer<C>>::account_id(&keypair);
440+
let origin_account_id = origin.public_key().to_account_id();
438441

439442
self.api
440443
.try_transfer_balance(origin, account_id.clone(), amount)
441444
.await
442445
.unwrap_or_else(|err| {
443446
panic!(
444447
"transfer from {} to {} failed with {:?}",
445-
origin.account_id(),
446-
account_id,
447-
err
448+
origin_account_id, account_id, err
448449
)
449450
});
450451

451452
log_info(&format!(
452453
"transfer from {} to {} succeeded",
453-
origin.account_id(),
454-
account_id,
454+
origin_account_id, account_id,
455455
));
456456

457-
pair_signer
457+
keypair
458458
}
459459

460460
/// This function extracts the metadata of the contract at the file path
@@ -468,7 +468,7 @@ where
468468
pub async fn instantiate<ContractRef, Args, R>(
469469
&mut self,
470470
contract_name: &str,
471-
signer: &Signer<C>,
471+
signer: &Keypair,
472472
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
473473
value: E::Balance,
474474
storage_deposit_limit: Option<E::Balance>,
@@ -488,11 +488,11 @@ where
488488
pub async fn instantiate_dry_run<ContractRef, Args, R>(
489489
&mut self,
490490
contract_name: &str,
491-
signer: &Signer<C>,
491+
signer: &Keypair,
492492
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
493493
value: E::Balance,
494494
storage_deposit_limit: Option<E::Balance>,
495-
) -> ContractInstantiateResult<C::AccountId, E::Balance>
495+
) -> ContractInstantiateResult<C::AccountId, E::Balance, ()>
496496
where
497497
Args: scale::Encode,
498498
{
@@ -535,7 +535,7 @@ where
535535
/// Executes an `instantiate_with_code` call and captures the resulting events.
536536
async fn exec_instantiate<ContractRef, Args, R>(
537537
&mut self,
538-
signer: &Signer<C>,
538+
signer: &Keypair,
539539
code: Vec<u8>,
540540
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
541541
value: E::Balance,
@@ -646,7 +646,7 @@ where
646646
pub async fn upload(
647647
&mut self,
648648
contract_name: &str,
649-
signer: &Signer<C>,
649+
signer: &Keypair,
650650
storage_deposit_limit: Option<E::Balance>,
651651
) -> Result<UploadResult<C, E>, Error<C, E>> {
652652
let code = self.load_code(contract_name);
@@ -660,7 +660,7 @@ where
660660
/// Executes an `upload` call and captures the resulting events.
661661
pub async fn exec_upload(
662662
&mut self,
663-
signer: &Signer<C>,
663+
signer: &Keypair,
664664
code: Vec<u8>,
665665
storage_deposit_limit: Option<E::Balance>,
666666
) -> Result<UploadResult<C, E>, Error<C, E>> {
@@ -731,7 +731,7 @@ where
731731
/// contains all events that are associated with this transaction.
732732
pub async fn call<RetType>(
733733
&mut self,
734-
signer: &Signer<C>,
734+
signer: &Keypair,
735735
message: Message<E, RetType>,
736736
value: E::Balance,
737737
storage_deposit_limit: Option<E::Balance>,
@@ -793,7 +793,7 @@ where
793793
/// contains all events that are associated with this transaction.
794794
pub async fn runtime_call<'a>(
795795
&mut self,
796-
signer: &Signer<C>,
796+
signer: &Keypair,
797797
pallet_name: &'a str,
798798
call_name: &'a str,
799799
call_data: Vec<Value>,
@@ -828,7 +828,7 @@ where
828828
/// invoked message.
829829
pub async fn call_dry_run<RetType>(
830830
&mut self,
831-
signer: &Signer<C>,
831+
signer: &Keypair,
832832
message: &Message<E, RetType>,
833833
value: E::Balance,
834834
storage_deposit_limit: Option<E::Balance>,
@@ -839,7 +839,7 @@ where
839839
let exec_result = self
840840
.api
841841
.call_dry_run(
842-
Signer::account_id(signer).clone(),
842+
Signer::<C>::account_id(signer),
843843
message,
844844
value,
845845
storage_deposit_limit,
@@ -940,6 +940,6 @@ where
940940
}
941941

942942
/// Returns true if the give event is System::Extrinsic failed.
943-
fn is_extrinsic_failed_event(event: &EventDetails) -> bool {
943+
fn is_extrinsic_failed_event<C: Config>(event: &EventDetails<C>) -> bool {
944944
event.pallet_name() == "System" && event.variant_name() == "ExtrinsicFailed"
945945
}

crates/e2e/src/lib.rs

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
mod builders;
2323
mod client;
24-
mod default_accounts;
2524
mod node_proc;
2625
mod xts;
2726

@@ -37,7 +36,6 @@ pub use client::{
3736
InstantiationResult,
3837
UploadResult,
3938
};
40-
pub use default_accounts::*;
4139
pub use env_logger;
4240
pub use ink_e2e_macro::test;
4341
pub use node_proc::{
@@ -46,9 +44,11 @@ pub use node_proc::{
4644
};
4745
pub use sp_core::H256;
4846
pub use sp_keyring::AccountKeyring;
49-
pub use subxt::{
47+
pub use subxt;
48+
pub use subxt_signer::sr25519::{
5049
self,
51-
tx::PairSigner,
50+
dev::*,
51+
Keypair,
5252
};
5353
pub use tokio;
5454

@@ -57,44 +57,13 @@ use pallet_contracts_primitives::{
5757
ContractExecResult,
5858
ContractInstantiateResult,
5959
};
60-
use sp_core::sr25519;
6160
use std::{
6261
cell::RefCell,
6362
sync::Once,
6463
};
6564
use xts::ContractsApi;
6665

67-
/// Default set of commonly used types by Substrate runtimes.
68-
#[cfg(feature = "std")]
69-
pub enum SubstrateConfig {}
70-
71-
#[cfg(feature = "std")]
72-
impl subxt::Config for SubstrateConfig {
73-
type Index = u32;
74-
type Hash = sp_core::H256;
75-
type Hasher = subxt::config::substrate::BlakeTwo256;
76-
type AccountId = subxt::config::substrate::AccountId32;
77-
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
78-
type Header = subxt::config::substrate::SubstrateHeader<
79-
u32,
80-
subxt::config::substrate::BlakeTwo256,
81-
>;
82-
type Signature = sp_runtime::MultiSignature;
83-
type ExtrinsicParams = subxt::config::substrate::SubstrateExtrinsicParams<Self>;
84-
}
85-
86-
/// Default set of commonly used types by Polkadot nodes.
87-
#[cfg(feature = "std")]
88-
pub type PolkadotConfig = subxt::config::WithExtrinsicParams<
89-
SubstrateConfig,
90-
subxt::config::polkadot::PolkadotExtrinsicParams<SubstrateConfig>,
91-
>;
92-
93-
/// Signer that is used throughout the E2E testing.
94-
///
95-
/// The E2E testing can only be used with nodes that support `sr25519`
96-
/// cryptography.
97-
pub type Signer<C> = PairSigner<C, sr25519::Pair>;
66+
pub use subxt::PolkadotConfig;
9867

9968
/// We use this to only initialize `env_logger` once.
10069
pub static INIT: Once = Once::new();

0 commit comments

Comments
 (0)