Skip to content

Commit

Permalink
Fix e2e tests: Upgrade Subxt (#1134)
Browse files Browse the repository at this point in the history
* fix tests

* fix tests

* try to fix tests

* update bindings

* update smoketests subxt

* fmt

* try to fix tests

* fiddling

* Update smoke test

* Wait more time

* Update subxt with forked

* Build subxt-cli with forked

* revert using the snowbridge fork of subxt

* revert funding account

---------

Co-authored-by: Alistair Singh <[email protected]>
Co-authored-by: claravanstaden <Cats 4 life!>
Co-authored-by: ron <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent 4a90854 commit aab91ae
Show file tree
Hide file tree
Showing 13 changed files with 2,420 additions and 1,006 deletions.
3,306 changes: 2,361 additions & 945 deletions smoketest/Cargo.lock

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions smoketest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = "0.3.27"
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread", "time"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["bit-vec", "derive", "full"] }
futures = "0.3.30"
tokio = { version = "1.35.0", features = ["macros", "rt-multi-thread", "time"] }
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["bit-vec", "derive", "full"] }
hex = "0.4.3"
hex-literal = "0.4.1"
serde = { version = "1.0", features = ["derive"] }
subxt = { git = "https://github.com/paritytech/subxt.git", tag = "v0.27.1" }
subxt = { git = "https://github.com/paritytech/subxt.git", tag = "v0.33.0", features = ["substrate-compat"]}
subxt-macro = { git = "https://github.com/paritytech/subxt.git", tag = "v0.33.0" }
subxt-metadata = { git = "https://github.com/paritytech/subxt.git", tag = "v0.33.0" }
subxt-codegen = { git = "https://github.com/paritytech/subxt.git", tag = "v0.33.0" }
subxt-signer = { git = "https://github.com/paritytech/subxt.git", tag = "v0.33.0" }
ethers = { git = "https://github.com/gakonst/ethers-rs", default-features = false, features = ["abigen", "ws"] }
sp-core = "16.0.0"
sp-core = "28.0.0"
lazy_static = "1.4.0"

[dev-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions smoketest/make-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if ! lsof -Pi :11144 -sTCP:LISTEN -t >/dev/null; then
fi

# Fetch metadata from BridgeHub and generate client
subxt codegen --url ws://localhost:11144 > src/parachains/bridgehub.rs
subxt codegen --url ws://localhost:12144 > src/parachains/assethub.rs
subxt codegen --url ws://localhost:13144 > src/parachains/penpal.rs
subxt codegen --url ws://localhost:9944 > src/parachains/relaychain.rs
subxt codegen --url ws://localhost:11144 >src/parachains/bridgehub.rs
subxt codegen --url ws://localhost:12144 >src/parachains/assethub.rs
subxt codegen --url ws://localhost:13144 >src/parachains/penpal.rs
subxt codegen --url ws://localhost:9944 >src/parachains/relaychain.rs
16 changes: 10 additions & 6 deletions smoketest/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use hex_literal::hex;
use lazy_static::lazy_static;
use std::{env, string::ToString};
use subxt::ext::sp_core::{sr25519::Pair, Pair as PairT};

// Todo: load all configs from env in consistent with set-env.sh
pub const ASSET_HUB_PARA_ID: u32 = 1000;
Expand Down Expand Up @@ -42,13 +43,16 @@ pub const SNOWBRIDGE_SOVEREIGN: [u8; 32] =
pub const PENPAL_SOVEREIGN: [u8; 32] =
hex!("7369626cd0070000000000000000000000000000000000000000000000000000");

// SS58: DE14BzQ1bDXWPKeLoAqdLAm1GpyAWaWF1knF74cEZeomTBM
pub const FERDIE: [u8; 32] =
hex!("1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c");

pub const BOB: [u8; 32] = hex!("8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48");

lazy_static! {
// SS58: 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL
pub static ref FERDIE: Pair = Pair::from_string("//Ferdie", None)
.expect("cannot create keypair");
pub static ref FERDIE_PUBLIC: [u8; 32] = (*FERDIE).public().into();
// SS58: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty
pub static ref BOB: Pair = Pair::from_string("//Bob", None)
.expect("cannot create keypair");
pub static ref BOB_PUBLIC: [u8; 32] = (*BOB).public().into();

pub static ref REGISTER_TOKEN_FEE: u64 = env::var("REGISTER_TOKEN_FEE")
.unwrap_or("200000000000000000".to_string())
.parse()
Expand Down
26 changes: 14 additions & 12 deletions smoketest/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
Instruction as RelaychainInstruction, WeightLimit as RelaychainWeightLimit,
Xcm as RelaychainXcm,
},
VersionedMultiLocation as RelaychainVersionedMultiLocation,
VersionedLocation as RelaychainVersionedLocation,
VersionedXcm as RelaychainVersionedXcm,
},
},
Expand All @@ -46,45 +46,47 @@ use penpalTypes::{
VersionedXcm,
},
};
use sp_core::{sr25519::Pair, Pair as PairT, H160};
use sp_core::H160;
use std::{ops::Deref, sync::Arc, time::Duration};
use subxt::{
blocks::ExtrinsicEvents,
config::DefaultExtrinsicParams,
events::StaticEvent,
ext::sp_core::{sr25519::Pair, Pair as PairT},
tx::{PairSigner, TxPayload},
Config, OnlineClient, PolkadotConfig, SubstrateConfig,
Config, OnlineClient, PolkadotConfig,
};

/// Custom config that works with Penpal
pub enum PenpalConfig {}

impl Config for PenpalConfig {
type Index = <PolkadotConfig as Config>::Index;
type Hash = <PolkadotConfig as Config>::Hash;
type AccountId = <PolkadotConfig as Config>::AccountId;
type Address = <PolkadotConfig as Config>::Address;
type AssetId = <PolkadotConfig as Config>::AssetId;
type Signature = <PolkadotConfig as Config>::Signature;
type Hasher = <PolkadotConfig as Config>::Hasher;
type Header = <PolkadotConfig as Config>::Header;
type ExtrinsicParams = <SubstrateConfig as Config>::ExtrinsicParams;
type ExtrinsicParams = DefaultExtrinsicParams<PenpalConfig>;
}

/// Custom config that works with Statemint
pub enum AssetHubConfig {}

impl Config for AssetHubConfig {
type Index = <PolkadotConfig as Config>::Index;
type Hash = <PolkadotConfig as Config>::Hash;
type AccountId = <PolkadotConfig as Config>::AccountId;
type Address = <PolkadotConfig as Config>::Address;
type Signature = <PolkadotConfig as Config>::Signature;
type Hasher = <PolkadotConfig as Config>::Hasher;
type Header = <PolkadotConfig as Config>::Header;
type ExtrinsicParams = <SubstrateConfig as Config>::ExtrinsicParams;
type ExtrinsicParams = DefaultExtrinsicParams<AssetHubConfig>;
type AssetId = <PolkadotConfig as Config>::AssetId;
}

pub struct TestClients {
pub asset_hub_client: Box<OnlineClient<PolkadotConfig>>,
pub asset_hub_client: Box<OnlineClient<AssetHubConfig>>,
pub bridge_hub_client: Box<OnlineClient<PolkadotConfig>>,
pub penpal_client: Box<OnlineClient<PenpalConfig>>,
pub relaychain_client: Box<OnlineClient<PolkadotConfig>>,
Expand All @@ -97,7 +99,7 @@ pub async fn initial_clients() -> Result<TestClients, Box<dyn std::error::Error>
.await
.expect("can not connect to bridgehub");

let asset_hub_client: OnlineClient<PolkadotConfig> = OnlineClient::from_url(ASSET_HUB_WS_URL)
let asset_hub_client: OnlineClient<AssetHubConfig> = OnlineClient::from_url(ASSET_HUB_WS_URL)
.await
.expect("can not connect to bridgehub");

Expand Down Expand Up @@ -194,7 +196,7 @@ pub async fn send_sudo_xcm_transact(
RuntimeCall::PolkadotXcm(Call::send { dest, message }),
);

let owner: Pair = Pair::from_string("//Alice", None).expect("cannot create keypair");
let owner = Pair::from_string("//Alice", None).expect("cannot create keypair");

let signer: PairSigner<PenpalConfig, _> = PairSigner::new(owner);

Expand Down Expand Up @@ -282,14 +284,14 @@ pub async fn governance_bridgehub_call_from_relay_chain(
) -> Result<(), Box<dyn std::error::Error>> {
let test_clients = initial_clients().await.expect("initialize clients");

let sudo: Pair = Pair::from_string("//Alice", None).expect("cannot create sudo keypair");
let sudo = Pair::from_string("//Alice", None).expect("cannot create sudo keypair");

let signer: PairSigner<PolkadotConfig, _> = PairSigner::new(sudo);

let weight = 180000000000;
let proof_size = 900000;

let dest = Box::new(RelaychainVersionedMultiLocation::V3(RelaychainMultiLocation {
let dest = Box::new(RelaychainVersionedLocation::V3(RelaychainMultiLocation {
parents: 0,
interior: RelaychainJunctions::X1(RelaychainJunction::Parachain(BRIDGE_HUB_PARA_ID)),
}));
Expand Down
2 changes: 1 addition & 1 deletion smoketest/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn construct_xcm_message(encoded_call: Vec<u8>) -> Box<VersionedXcm> {
}

// WithdrawAsset is not allowed in bridgehub but keep it here
pub async fn construct_xcm_message_with_fee(encoded_call: Vec<u8>) -> Box<VersionedXcm> {
pub fn construct_xcm_message_with_fee(encoded_call: Vec<u8>) -> Box<VersionedXcm> {
let buy_execution_fee = MultiAsset {
id: Concrete(MultiLocation { parents: 1, interior: Junctions::Here }),
fun: Fungible(BRIDGE_HUB_FEE_REQUIRED),
Expand Down
2 changes: 1 addition & 1 deletion smoketest/tests/create_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn create_agent() {
.await
.expect("construct inner call.");

let message = construct_xcm_message_with_fee(encoded_call).await;
let message = construct_xcm_message_with_fee(encoded_call);

let result = send_sudo_xcm_transact(&test_clients.penpal_client, message)
.await
Expand Down
2 changes: 1 addition & 1 deletion smoketest/tests/create_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn create_channel() {
.await
.expect("construct inner call.");

let message = construct_xcm_message_with_fee(encoded_call).await;
let message = construct_xcm_message_with_fee(encoded_call);

let result = send_sudo_xcm_transact(&test_clients.penpal_client, message)
.await
Expand Down
4 changes: 2 additions & 2 deletions smoketest/tests/send_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn send_token() {
.send_token(
weth.address(),
ASSET_HUB_PARA_ID,
i_gateway::MultiAddress { kind: 1, data: BOB.into() },
i_gateway::MultiAddress { kind: 1, data: (*BOB_PUBLIC).into() },
destination_fee,
amount,
)
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn send_token() {
AccountKey20 { network: None, key: WETH_CONTRACT.into() },
),
};
let expected_owner: AccountId32 = BOB.into();
let expected_owner: AccountId32 = (*BOB_PUBLIC).into();

let mut issued_event_found = false;
while let Some(Ok(block)) = blocks.next().await {
Expand Down
9 changes: 4 additions & 5 deletions smoketest/tests/send_token_to_penpal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use snowbridge_smoketest::{
penpal::{self, api::foreign_assets::events::Issued as PenpalIssued},
},
};
use sp_core::{sr25519::Pair, Encode, Pair as PairT};
use sp_core::Encode;
use subxt::{
tx::PairSigner,
utils::{AccountId32, MultiAddress},
Expand Down Expand Up @@ -74,7 +74,7 @@ async fn send_token_to_penpal() {
.send_token(
weth.address(),
PENPAL_PARA_ID,
i_gateway::MultiAddress { kind: 1, data: FERDIE.into() },
i_gateway::MultiAddress { kind: 1, data: (*FERDIE_PUBLIC).into() },
4_000_000_000,
amount,
)
Expand Down Expand Up @@ -133,7 +133,7 @@ async fn send_token_to_penpal() {
.expect("block subscription")
.take(wait_for_blocks);

let penpal_expected_owner: AccountId32 = FERDIE.into();
let penpal_expected_owner: AccountId32 = (*FERDIE_PUBLIC).into();

issued_event_found = false;
while let Some(Ok(block)) = penpal_blocks.next().await {
Expand Down Expand Up @@ -191,8 +191,7 @@ async fn ensure_penpal_asset_exists(penpal_client: &mut OnlineClient<PenpalConfi

println!("creating WETH on penpal.");
let admin = MultiAddress::Id(ASSET_HUB_SOVEREIGN.into());
let keypair: Pair = Pair::from_string("//Ferdie", None).expect("cannot create keypair");
let signer: PairSigner<PenpalConfig, _> = PairSigner::new(keypair);
let signer: PairSigner<PenpalConfig, _> = PairSigner::new((*FERDIE).clone());

let create_asset_call = penpal::api::tx().foreign_assets().create(penpal_asset_id, admin, 1);
penpal_client
Expand Down
3 changes: 1 addition & 2 deletions smoketest/tests/transfer_native_from_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ async fn transfer_native_from_agent() {
)
.await
.expect("construct inner call."),
)
.await;
);

let result = send_sudo_xcm_transact(&test_clients.penpal_client, message)
.await
Expand Down
30 changes: 10 additions & 20 deletions smoketest/tests/transfer_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ use snowbridge_smoketest::{
junctions::Junctions,
multiasset::{AssetId, Fungibility, MultiAsset, MultiAssets},
},
VersionedMultiAssets, VersionedMultiLocation,
VersionedAssets, VersionedLocation,
},
},
{self},
},
};
use sp_core::{sr25519::Pair, Pair as PairT};
use std::{sync::Arc, time::Duration};
use subxt::{tx::PairSigner, OnlineClient};
use subxt::OnlineClient;
use subxt_signer::sr25519::dev;

const DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e");

Expand All @@ -53,12 +53,8 @@ async fn transfer_token() {
let assethub: OnlineClient<AssetHubConfig> =
OnlineClient::from_url(ASSET_HUB_WS_URL).await.unwrap();

let keypair: Pair = Pair::from_string("//Ferdie", None).expect("cannot create keypair");

let signer: PairSigner<AssetHubConfig, _> = PairSigner::new(keypair);

let amount: u128 = 1_000_000_000;
let assets = VersionedMultiAssets::V3(MultiAssets(vec![MultiAsset {
let assets = VersionedAssets::V3(MultiAssets(vec![MultiAsset {
id: AssetId::Concrete(MultiLocation {
parents: 2,
interior: Junctions::X2(
Expand All @@ -69,39 +65,33 @@ async fn transfer_token() {
fun: Fungibility::Fungible(amount),
}]));

let destination = VersionedMultiLocation::V3(MultiLocation {
let destination = VersionedLocation::V3(MultiLocation {
parents: 2,
interior: Junctions::X1(Junction::GlobalConsensus(NetworkId::Ethereum {
chain_id: ETHEREUM_CHAIN_ID,
})),
});

let beneficiary = VersionedMultiLocation::V3(MultiLocation {
let beneficiary = VersionedLocation::V3(MultiLocation {
parents: 0,
interior: Junctions::X1(Junction::AccountKey20 {
network: None,
key: DESTINATION_ADDRESS.into(),
}),
});

let signer = dev::bob();

let token_transfer_call =
TransactionApi.reserve_transfer_assets(destination, beneficiary, assets, 0);

let result = assethub
let _ = assethub
.tx()
.sign_and_submit_then_watch_default(&token_transfer_call, &signer)
.await
.expect("send through call.")
.wait_for_finalized_success()
.await
.expect("call success");

println!(
"reserve_transfer_assets call issued at assethub block hash {:?}",
result.block_hash()
);

let wait_for_blocks = 50;
let wait_for_blocks = 500;
let mut stream = ethereum_client.subscribe_blocks().await.unwrap().take(wait_for_blocks);

let mut transfer_event_found = false;
Expand Down
4 changes: 2 additions & 2 deletions smoketest/tests/upgrade_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use snowbridge_smoketest::{
double_encoded::DoubleEncoded,
v2::OriginKind,
v3::{junction::Junction, junctions::Junctions, Instruction, WeightLimit, Xcm},
VersionedMultiLocation, VersionedXcm,
VersionedLocation, VersionedXcm,
},
},
},
Expand Down Expand Up @@ -93,7 +93,7 @@ async fn upgrade_gateway() {
let weight = 3000000000;
let proof_size = 18000;

let dest = Box::new(VersionedMultiLocation::V3(MultiLocation {
let dest = Box::new(VersionedLocation::V3(MultiLocation {
parents: 0,
interior: Junctions::X1(Junction::Parachain(BRIDGE_HUB_PARA_ID)),
}));
Expand Down

0 comments on commit aab91ae

Please sign in to comment.