Skip to content

Commit

Permalink
[v4.x.x] fix E2E tests for newer rust toolchain & contracts node (#…
Browse files Browse the repository at this point in the history
…1884)

* Manual backport of #1883: Use `contract-build` `3.2.0`

* ink-e2e Test Failures in substrate-contracts-node (v0.27.0) due to Unsupported --ws-port Argument (#1850)

* Update ink-e2e to the latest substrate-contracts-node

* Apply rust-fmt

* Change logging, to be up-to-date with master branch

* Apply rustfmt-nightly

(cherry picked from commit 6d7810e)

* Remove --ws-port arg

* Update substrate deps

* Manual backports of #1795 and #1855 to update subxt

* Update subxt in example

* Backport: fix e2e test, account for contract initial free balance (#1777)

* Use latest CI image

* 🦖 fix spellcheck for new version, add words to dict (#1836)

* Fix call-runtime tests

* enable call-runtime tests

* ui tests

* `[ink_e2e]` update `Determinism` enum to match Substrate definition (#1781)

* `[ink_e2e]` update `Determinism` enum to match Substrate definition

* fmt

* Fix multi_contract_caller example for new deposit behaviour

* Reenable examples-test step

* Fix integration test

* Remove riscv +stable

* Fix riscv build

---------

Co-authored-by: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
  • Loading branch information
ascjones and varex83 authored Aug 23, 2023
1 parent 1b2e7cf commit 5a2a29d
Show file tree
Hide file tree
Showing 34 changed files with 224 additions and 211 deletions.
4 changes: 4 additions & 0 deletions .config/cargo_spellcheck.dic
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ FFI
Gnosis
GPL
KECCAK
L1
L2
Polkadot
PSP22
RPC
SHA
UI/S
Expand Down Expand Up @@ -62,6 +65,7 @@ scalability
scalable
stdin
stdout
subber
tuple
unordered
untyped
Expand Down
6 changes: 2 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +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 is changed to "-:staging" when the CI image gets rebuilt
# read more https://github.com/paritytech/scripts/pull/244
CI_IMAGE: "paritytech/ink-ci-linux:a1f03f4b-20230420"
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 Expand Up @@ -451,7 +449,7 @@ examples-contract-build-riscv:
if [ "$example" = "integration-tests/custom_allocator/" ]; then continue; fi;
if [ "$example" = "integration-tests/call-runtime/" ]; then continue; fi;
pushd $example &&
cargo +stable build --no-default-features --target $RISCV_TARGET -Zbuild-std="core,alloc" &&
cargo build --no-default-features --target $RISCV_TARGET -Zbuild-std="core,alloc" &&
popd;
done

Expand Down
13 changes: 7 additions & 6 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ 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 = "23.0.0"
sp-core = "20.0.0"
sp-keyring = "23.0.0"
sp-runtime = "23.0.0"
sp-weights = "19.0.0"
pallet-contracts-primitives = "24.0.0"
sp-core = "21.0.0"
sp-keyring = "24.0.0"
sp-runtime = "24.0.0"
sp-weights = "20.0.0"

[dev-dependencies]
# Required for the doctest of `MessageBuilder::call`
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ proc-macro = true
[dependencies]
ink_ir = { version = "4.2.1", path = "../../ink/ir" }
cargo_metadata = "0.15.3"
contract-build = "2.0.2"
contract-build = "3.2.0"
derive_more = "0.99.17"
env_logger = "0.10.0"
log = "0.4.17"
Expand Down
6 changes: 5 additions & 1 deletion crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
// limitations under the License.

use crate::ir;
use contract_build::ManifestPath;
use contract_build::{
ManifestPath,
Target,
};
use core::cell::RefCell;
use derive_more::From;
use proc_macro2::TokenStream as TokenStream2;
Expand Down Expand Up @@ -289,6 +292,7 @@ fn build_contract(path_to_cargo_toml: &str) -> String {
lint: false,
output_type: OutputType::HumanReadable,
skip_wasm_validation: false,
target: Target::Wasm,
};

match contract_build::execute(args) {
Expand Down
69 changes: 34 additions & 35 deletions crates/e2e/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,7 +51,8 @@ use subxt::{
ValueDef,
},
},
tx::PairSigner,
tx::Signer,
Config,
};

/// Result of a contract instantiation.
Expand All @@ -61,7 +61,7 @@ pub struct InstantiationResult<C: subxt::Config, E: Environment> {
pub account_id: E::AccountId,
/// The result of the dry run, contains debug messages
/// if there were any.
pub dry_run: ContractInstantiateResult<C::AccountId, E::Balance>,
pub dry_run: ContractInstantiateResult<C::AccountId, E::Balance, ()>,
/// Events that happened with the contract instantiation.
pub events: ExtrinsicEvents<C>,
}
Expand Down Expand Up @@ -191,7 +191,7 @@ where
pub struct CallDryRunResult<E: Environment, V> {
/// The result of the dry run, contains debug messages
/// if there were any.
pub exec_result: ContractExecResult<E::Balance>,
pub exec_result: ContractExecResult<E::Balance, ()>,
_marker: PhantomData<V>,
}

Expand Down Expand Up @@ -271,15 +271,15 @@ where
/// No contract with the given name found in scope.
ContractNotFound(String),
/// The `instantiate_with_code` dry run failed.
InstantiateDryRun(ContractInstantiateResult<C::AccountId, E::Balance>),
InstantiateDryRun(ContractInstantiateResult<C::AccountId, E::Balance, ()>),
/// The `instantiate_with_code` extrinsic failed.
InstantiateExtrinsic(subxt::error::DispatchError),
/// The `upload` dry run failed.
UploadDryRun(CodeUploadResult<E::Hash, E::Balance>),
/// The `upload` extrinsic failed.
UploadExtrinsic(subxt::error::DispatchError),
/// The `call` dry run failed.
CallDryRun(ContractExecResult<E::Balance>),
CallDryRun(ContractExecResult<E::Balance, ()>),
/// The `call` extrinsic failed.
CallExtrinsic(subxt::error::DispatchError),
/// Error fetching account balance.
Expand Down Expand Up @@ -383,12 +383,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 @@ -424,37 +423,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 @@ -468,7 +467,7 @@ where
pub async fn instantiate<ContractRef, Args, R>(
&mut self,
contract_name: &str,
signer: &Signer<C>,
signer: &Keypair,
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand All @@ -488,11 +487,11 @@ where
pub async fn instantiate_dry_run<ContractRef, Args, R>(
&mut self,
contract_name: &str,
signer: &Signer<C>,
signer: &Keypair,
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> ContractInstantiateResult<C::AccountId, E::Balance>
) -> ContractInstantiateResult<C::AccountId, E::Balance, ()>
where
Args: scale::Encode,
{
Expand Down Expand Up @@ -535,7 +534,7 @@ where
/// Executes an `instantiate_with_code` call and captures the resulting events.
async fn exec_instantiate<ContractRef, Args, R>(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
code: Vec<u8>,
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
value: E::Balance,
Expand Down Expand Up @@ -646,7 +645,7 @@ where
pub async fn upload(
&mut self,
contract_name: &str,
signer: &Signer<C>,
signer: &Keypair,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<C, E>, Error<C, E>> {
let code = self.load_code(contract_name);
Expand All @@ -660,7 +659,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<C, E>, Error<C, E>> {
Expand Down Expand Up @@ -731,7 +730,7 @@ where
/// contains all events that are associated with this transaction.
pub async fn call<RetType>(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
message: Message<E, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand Down Expand Up @@ -793,7 +792,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 @@ -828,7 +827,7 @@ where
/// invoked message.
pub async fn call_dry_run<RetType>(
&mut self,
signer: &Signer<C>,
signer: &Keypair,
message: &Message<E, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand All @@ -839,7 +838,7 @@ where
let exec_result = self
.api
.call_dry_run(
Signer::account_id(signer).clone(),
Signer::<C>::account_id(signer),
message,
value,
storage_deposit_limit,
Expand Down Expand Up @@ -940,6 +939,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<C: Config>(event: &EventDetails<C>) -> bool {
event.pallet_name() == "System" && event.variant_name() == "ExtrinsicFailed"
}
41 changes: 5 additions & 36 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

mod builders;
mod client;
mod default_accounts;
mod node_proc;
mod xts;

Expand All @@ -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::{
Expand All @@ -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;

Expand All @@ -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<Self::AccountId, u32>;
type Header = subxt::config::substrate::SubstrateHeader<
u32,
subxt::config::substrate::BlakeTwo256,
>;
type Signature = sp_runtime::MultiSignature;
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::config::polkadot::PolkadotExtrinsicParams<SubstrateConfig>,
>;

/// 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>;
pub use subxt::PolkadotConfig;

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

0 comments on commit 5a2a29d

Please sign in to comment.