Skip to content

Commit

Permalink
Bump Substrate and subxt dependencies (#1549)
Browse files Browse the repository at this point in the history
* Bump Substrate dependencies

We also need to bump `subxt` to a version that uses the same versions of
our Substrate deps.

* Use `Fundamental` trait directly

Not sure why we're going through this hidden internal module

* Bump to `subxt@0.26` and accompanying Substrate deps

* Get E2E crate compiling again

* Clean up trait bounds

* Clean up signer generation

* Remove default feature

* Remove bound on struct

Co-authored-by: Andrew Jones <ascjones@gmail.com>
  • Loading branch information
HCastano and ascjones authored Jan 27, 2023
1 parent 33b04bc commit 7a04cf7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 59 deletions.
13 changes: 7 additions & 6 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ink_env = { version = "4.0.0-beta.1", path = "../env" }
ink_primitives = { version = "4.0.0-beta.1", path = "../primitives" }

contract-metadata = { version = "2.0.0-rc" }
funty = "2.0.0"
impl-serde = { version = "0.3.1", default-features = false }
jsonrpsee = { version = "0.16.0", features = ["ws-client"] }
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
Expand All @@ -29,14 +30,14 @@ 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", default-features = false, features = ["derive", "full"] }
subxt = "0.25.0"
subxt = "0.26.0"

# Substrate
pallet-contracts-primitives = "7.0.0"
sp-core = "7.0.0"
sp-keyring = "7.0.0"
sp-runtime = "7.0.0"
sp-weights = "4.0.0"
pallet-contracts-primitives = "12.0.0"
sp-core = "11.0.0"
sp-keyring = "12.0.0"
sp-runtime = "12.0.0"
sp-weights = "8.0.0"

[dev-dependencies]
# Required for the doctest of `MessageBuilder::call`
Expand Down
56 changes: 29 additions & 27 deletions crates/e2e/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,22 @@ use ink_env::Environment;
use ink_primitives::MessageResult;

use sp_core::Pair;
use sp_runtime::traits::{
IdentifyAccount,
Verify,
};
use std::{
collections::BTreeMap,
fmt::Debug,
path::Path,
};

use subxt::{
blocks::ExtrinsicEvents,
config::ExtrinsicParams,
events::EventDetails,
ext::{
bitvec::macros::internal::funty::Fundamental,
scale_value::{
Composite,
Value,
ValueDef,
},
},
tx::{
ExtrinsicParams,
PairSigner,
ext::scale_value::{
Composite,
Value,
ValueDef,
},
tx::PairSigner,
};

/// Result of a contract instantiation.
Expand Down Expand Up @@ -103,6 +95,7 @@ where
impl<C, E> core::fmt::Debug for InstantiationResult<C, E>
where
C: subxt::Config,
C::AccountId: Debug,
E: Environment,
<E as Environment>::AccountId: Debug,
<E as Environment>::Balance: Debug,
Expand Down Expand Up @@ -287,14 +280,10 @@ where
impl<C, E> Client<C, E>
where
C: subxt::Config,
C::AccountId: Into<C::Address> + serde::de::DeserializeOwned,
C::Address: From<C::AccountId>,
C::AccountId: serde::de::DeserializeOwned,
C::AccountId: scale::Codec + Debug,
C::Signature: From<sr25519::Signature>,
<C::Signature as Verify>::Signer: From<sr25519::Public>,
<C::ExtrinsicParams as ExtrinsicParams<C::Index, C::Hash>>::OtherParams: Default,
<C::Signature as Verify>::Signer:
From<sr25519::Public> + IdentifyAccount<AccountId = C::AccountId>,
sr25519::Signature: Into<C::Signature>,

E: Environment,
E::AccountId: Debug,
Expand Down Expand Up @@ -348,11 +337,12 @@ where
) -> Signer<C>
where
E::Balance: Clone,
C::AccountId: Clone + core::fmt::Display,
C::AccountId: Clone + core::fmt::Display + core::fmt::Debug,
C::AccountId: From<sp_core::crypto::AccountId32>,
{
let (pair, _, _) = <sr25519::Pair as Pair>::generate_with_phrase(None);
let account_id =
<C::Signature as Verify>::Signer::from(pair.public()).into_account();
let pair_signer = PairSigner::<C, _>::new(pair);
let account_id = pair_signer.account_id().to_owned();

for _ in 0..6 {
let transfer_result = self
Expand Down Expand Up @@ -380,7 +370,7 @@ where
}
}

PairSigner::new(pair)
pair_signer
}

/// This function extracts the metadata of the contract at the file path
Expand Down Expand Up @@ -540,6 +530,8 @@ where

/// Generate a unique salt based on the system time.
fn salt() -> Vec<u8> {
use funty::Fundamental as _;

std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_else(|err| panic!("unable to get unix time: {err}"))
Expand Down Expand Up @@ -660,7 +652,12 @@ where

let dry_run = self
.api
.call_dry_run(signer.account_id().clone(), &message, value, None)
.call_dry_run(
subxt::tx::Signer::account_id(signer).clone(),
&message,
value,
None,
)
.await;
log_info(&format!("call dry run: {:?}", &dry_run.result));
log_info(&format!(
Expand Down Expand Up @@ -732,7 +729,12 @@ where
.api
.client
.storage()
.fetch_or_default(&account_addr, None)
.at(None)
.await
.unwrap_or_else(|err| {
panic!("unable to fetch balance: {:?}", err);
})
.fetch_or_default(&account_addr)
.await
.unwrap_or_else(|err| {
panic!("unable to fetch balance: {err:?}");
Expand Down
5 changes: 1 addition & 4 deletions crates/e2e/src/default_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
use super::{
AccountKeyring,
IdentifyAccount,
PairSigner,
Verify,
};
use sp_core::sr25519;

Expand All @@ -33,9 +31,8 @@ macro_rules! default_account {
pub fn $fn_name<C>() -> PairSigner<C, sr25519::Pair>
where
C: subxt::Config,
<C::Signature as Verify>::Signer: From<sr25519::Public>,
C::Signature: From<sr25519::Signature>,
<C::Signature as Verify>::Signer: IdentifyAccount<AccountId = C::AccountId>,
C::AccountId: From<sp_core::crypto::AccountId32>
{
PairSigner::new(AccountKeyring::$keyring_fn_name.pair())
}
Expand Down
18 changes: 8 additions & 10 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ use pallet_contracts_primitives::{
ContractInstantiateResult,
};
use sp_core::sr25519;
use sp_runtime::traits::{
IdentifyAccount,
Verify,
};
use std::{
cell::RefCell,
sync::Once,
Expand All @@ -71,20 +67,22 @@ impl subxt::Config for SubstrateConfig {
type Index = u32;
type BlockNumber = u32;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = sp_runtime::AccountId32;
type Hasher = subxt::config::substrate::BlakeTwo256;
type AccountId = subxt::config::substrate::AccountId32;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header =
sp_runtime::generic::Header<Self::BlockNumber, sp_runtime::traits::BlakeTwo256>;
type Header = subxt::config::substrate::SubstrateHeader<
Self::BlockNumber,
subxt::config::substrate::BlakeTwo256,
>;
type Signature = sp_runtime::MultiSignature;
type ExtrinsicParams = subxt::tx::SubstrateExtrinsicParams<Self>;
type ExtrinsicParams = subxt::config::substrate::SubstrateExtrinsicParams<Self>;
}

/// Default set of commonly used types by Polkadot nodes.
#[cfg(feature = "std")]
pub type PolkadotConfig = subxt::config::WithExtrinsicParams<
SubstrateConfig,
subxt::tx::PolkadotExtrinsicParams<SubstrateConfig>,
subxt::config::polkadot::PolkadotExtrinsicParams<SubstrateConfig>,
>;

/// Signer that is used throughout the E2E testing.
Expand Down
18 changes: 6 additions & 12 deletions crates/e2e/src/xts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use super::{
sr25519,
ContractExecResult,
ContractInstantiateResult,
IdentifyAccount,
Signer,
Verify,
};
use ink_env::Environment;

Expand All @@ -41,7 +39,7 @@ use sp_core::{
use sp_weights::Weight;
use subxt::{
blocks::ExtrinsicEvents,
tx::ExtrinsicParams,
config::ExtrinsicParams,
OnlineClient,
};

Expand Down Expand Up @@ -176,14 +174,10 @@ pub struct ContractsApi<C: subxt::Config, E: Environment> {
impl<C, E> ContractsApi<C, E>
where
C: subxt::Config,
C::AccountId: Into<C::Address> + serde::de::DeserializeOwned,
<C::ExtrinsicParams as ExtrinsicParams<C::Index, C::Hash>>::OtherParams: Default,

C::AccountId: serde::de::DeserializeOwned,
C::AccountId: scale::Codec,
C::Signature: From<sr25519::Signature>,
<C::Signature as Verify>::Signer: From<sr25519::Public>,
<C::Signature as Verify>::Signer:
From<sr25519::Public> + IdentifyAccount<AccountId = C::AccountId>,
sr25519::Signature: Into<C::Signature>,
<C::ExtrinsicParams as ExtrinsicParams<C::Index, C::Hash>>::OtherParams: Default,

E: Environment,
E::Balance: scale::HasCompact + serde::Serialize,
Expand Down Expand Up @@ -251,7 +245,7 @@ where
) -> ContractInstantiateResult<C::AccountId, E::Balance> {
let code = Code::Upload(code);
let call_request = RpcInstantiateRequest::<C, E> {
origin: signer.account_id().clone(),
origin: subxt::tx::Signer::account_id(signer).clone(),
value,
gas_limit: None,
storage_deposit_limit,
Expand Down Expand Up @@ -337,7 +331,7 @@ where
storage_deposit_limit: Option<E::Balance>,
) -> CodeUploadResult<E::Hash, E::Balance> {
let call_request = RpcCodeUploadRequest::<C, E> {
origin: signer.account_id().clone(),
origin: subxt::tx::Signer::account_id(signer).clone(),
code,
storage_deposit_limit,
determinism: Determinism::Deterministic,
Expand Down

0 comments on commit 7a04cf7

Please sign in to comment.