Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Rust >= 1.70, update subxt and contract-build #1855

Merged
merged 15 commits into from
Jul 26, 2023
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ variables:
GIT_DEPTH: 100
CARGO_INCREMENTAL: 0
CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
CI_IMAGE: "paritytech/ci-unified:bullseye-1.69.0-2023-03-21"
CI_IMAGE: "paritytech/ci-unified:bullseye-1.71.0-2023-05-23"
PURELY_STD_CRATES: "ink/codegen metadata engine e2e e2e/macro ink/ir"
ALSO_WASM_CRATES: "env storage storage/traits allocator prelude primitives ink ink/macro"
ALL_CRATES: "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ serde_json = { version = "1.0.81" }
sha2 = { version = "0.10" }
sha3 = { version = "0.10" }
static_assertions = { version = "1.1" }
subxt = { version = "0.29.0" }
subxt = { version = "0.30.1" }
subxt-signer = { version = "0.30.1" }
syn = { version = "2" }
synstructure = { version = "0.13.0" }
tokio = { version = "1.18.2" }
Expand Down
1 change: 1 addition & 0 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
scale = { package = "parity-scale-codec", workspace = true }
subxt = { workspace = true }
subxt-signer = { workspace = true, features = ["subxt", "sr25519"] }

# Substrate
pallet-contracts-primitives = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ 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) {
Expand Down
56 changes: 27 additions & 29 deletions crates/e2e/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use super::{
sr25519,
ContractInstantiateResult,
ContractsApi,
Signer,
Keypair,
};
use crate::contract_results::{
CallDryRunResult,
Expand All @@ -46,7 +46,6 @@ use ink_env::{
},
Environment,
};
use sp_core::Pair;
#[cfg(feature = "std")]
use std::{
collections::BTreeMap,
Expand All @@ -64,7 +63,7 @@ use subxt::{
Value,
ValueDef,
},
tx::PairSigner,
tx::Signer,
};

pub type Error<E> = crate::error::Error<
Expand Down Expand Up @@ -98,12 +97,11 @@ where
impl<C, E> Client<C, E>
where
C: subxt::Config,
C::AccountId: From<sp_runtime::AccountId32>
+ scale::Codec
+ serde::de::DeserializeOwned
+ Debug,
C::AccountId:
From<sr25519::PublicKey> + scale::Codec + serde::de::DeserializeOwned + Debug,
C::Address: From<sr25519::PublicKey>,
C::Signature: From<sr25519::Signature>,
<C::ExtrinsicParams as ExtrinsicParams<C::Index, C::Hash>>::OtherParams: Default,
<C::ExtrinsicParams as ExtrinsicParams<C::Hash>>::OtherParams: Default,

E: Environment,
E::AccountId: Debug,
Expand Down Expand Up @@ -139,37 +137,37 @@ where
/// number of times.
pub async fn create_and_fund_account(
&self,
origin: &Signer<C>,
origin: &Keypair,
amount: E::Balance,
) -> Signer<C>
) -> Keypair
where
E::Balance: Clone,
C::AccountId: Clone + core::fmt::Display + Debug,
C::AccountId: From<sp_core::crypto::AccountId32>,
{
let (pair, _, _) = <sr25519::Pair as Pair>::generate_with_phrase(None);
let pair_signer = PairSigner::<C, _>::new(pair);
let account_id = pair_signer.account_id().to_owned();
let (_, phrase, _) =
<sp_core::sr25519::Pair as sp_core::Pair>::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 = <Keypair as Signer<C>>::account_id(&keypair);
let origin_account_id = origin.public_key().to_account_id();

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
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
Expand All @@ -183,7 +181,7 @@ where
pub async fn instantiate<Contract, Args, R>(
&mut self,
contract_name: &str,
signer: &Signer<C>,
signer: &Keypair,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand All @@ -209,7 +207,7 @@ where
pub async fn instantiate_dry_run<Contract, Args, R>(
&mut self,
contract_name: &str,
signer: &Signer<C>,
signer: &Keypair,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand Down Expand Up @@ -256,7 +254,7 @@ where
/// Executes an `instantiate_with_code` call and captures the resulting events.
async fn exec_instantiate<Contract, Args, R>(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
code: Vec<u8>,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
Expand Down Expand Up @@ -368,7 +366,7 @@ where
pub async fn upload(
&mut self,
contract_name: &str,
signer: &Signer<C>,
signer: &Keypair,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<E, ExtrinsicEvents<C>>, Error<E>> {
let code = self.load_code(contract_name);
Expand All @@ -382,7 +380,7 @@ where
/// Executes an `upload` call and captures the resulting events.
pub async fn exec_upload(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
code: Vec<u8>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<E, ExtrinsicEvents<C>>, Error<E>> {
Expand Down Expand Up @@ -453,7 +451,7 @@ where
/// contains all events that are associated with this transaction.
pub async fn call<Args, RetType>(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
message: &CallBuilderFinal<E, Args, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand Down Expand Up @@ -519,7 +517,7 @@ where
/// contains all events that are associated with this transaction.
pub async fn runtime_call<'a>(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
pallet_name: &'a str,
call_name: &'a str,
call_data: Vec<Value>,
Expand Down Expand Up @@ -554,7 +552,7 @@ where
/// invoked message.
pub async fn call_dry_run<Args, RetType>(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
message: &CallBuilderFinal<E, Args, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand All @@ -570,7 +568,7 @@ where
let exec_result = self
.api
.call_dry_run(
Signer::account_id(signer).clone(),
Signer::<C>::account_id(signer),
dest,
exec_input,
value,
Expand Down
50 changes: 0 additions & 50 deletions crates/e2e/src/default_accounts.rs

This file was deleted.

15 changes: 4 additions & 11 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
mod builders;
mod client;
mod contract_results;
mod default_accounts;
mod error;
pub mod events;
mod node_proc;
Expand All @@ -39,17 +38,18 @@ pub use contract_results::{
InstantiationResult,
UploadResult,
};
pub use default_accounts::*;
pub use ink_e2e_macro::test;
pub use node_proc::{
TestNodeProcess,
TestNodeProcessBuilder,
};
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;
pub use tracing_subscriber;
Expand All @@ -58,7 +58,6 @@ use pallet_contracts_primitives::{
ContractExecResult,
ContractInstantiateResult,
};
use sp_core::sr25519;
use std::{
cell::RefCell,
sync::Once,
Expand All @@ -67,12 +66,6 @@ use xts::ContractsApi;

pub use subxt::PolkadotConfig;

/// Signer that is used throughout the E2E testing.
///
/// The E2E testing can only be used with nodes that support `sr25519`
/// cryptography.
pub type Signer<C> = PairSigner<C, sr25519::Pair>;

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

Expand Down
Loading