Skip to content

Commit

Permalink
Fix e2e environment and smoketests (#1273)
Browse files Browse the repository at this point in the history
* package updates

* fix gyp build and npm updates

* remove nonces and nowait

* revert packages

* revert helpers

* fix init script

* required package update

* add back fixes

* fix helper

* more fixes

* fmt

* fix helper

* fix errors

* Refactoring with call_polkadot_js_api (#1274)

* all tests pass

* deposit and approve

---------

Co-authored-by: Ron <yrong1997@gmail.com>
  • Loading branch information
alistair-singh and yrong authored Aug 29, 2024
1 parent 235d9ea commit 3291185
Show file tree
Hide file tree
Showing 21 changed files with 5,477 additions and 4,026 deletions.
Binary file modified control/runtimes/asset-hub-polkadot/asset-hub-metadata.bin
Binary file not shown.
Binary file modified control/runtimes/bridge-hub-polkadot/bridge-hub-metadata.bin
Binary file not shown.
Binary file modified control/runtimes/polkadot/polkadot-metadata.bin
Binary file not shown.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
ps

# typescript
python3
python311
nodePackages.pnpm
nodejs_20
(yarn.override { nodejs = nodejs_20; })
Expand Down
4 changes: 3 additions & 1 deletion scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ echo "Checkout lodestar Snowfork fork"
pushd ..
if [ ! -d "lodestar" ]; then
git clone https://github.com/ChainSafe/lodestar
cd snowbridge && ln -sf ../lodestar lodestar
fi
if [ ! -L "snowbridge/lodestar" ]; then
(cd snowbridge && ln -sf ../lodestar lodestar)
fi
pushd lodestar
git fetch && git checkout $LODESTAR_VERSION
Expand Down
8 changes: 4 additions & 4 deletions smoketest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion smoketest/make-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ forge bind --module --overwrite \
# Install subxt
command -v subxt || cargo install subxt-cli \
--git https://github.com/paritytech/subxt.git \
--tag v0.35.3
--tag v0.37.0

if ! lsof -Pi :11144 -sTCP:LISTEN -t >/dev/null; then
echo "substrate nodes not running, please start with the e2e setup and rerun this script"
Expand Down
26 changes: 26 additions & 0 deletions smoketest/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -xe

cargo test --no-run

tests=(
register_token

send_token
send_token_to_penpal
transfer_token

set_pricing_params
set_token_transfer_fees

create_agent
create_channel
transfer_native_from_agent

upgrade_gateway
)

for test in ${tests[@]}; do
cargo test --test $test -- --nocapture
done
22 changes: 18 additions & 4 deletions smoketest/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ use penpalTypes::{
};
use std::{ops::Deref, sync::Arc, time::Duration};
use subxt::{
blocks::ExtrinsicEvents,
config::DefaultExtrinsicParams,
events::StaticEvent,
ext::sp_core::{sr25519::Pair, Pair as PairT, H160},
tx::{PairSigner, Payload},
utils::H256,
Config, OnlineClient, PolkadotConfig,
};

Expand Down Expand Up @@ -180,10 +180,15 @@ pub async fn wait_for_ethereum_event<Ev: EthEvent>(ethereum_client: &Box<Arc<Pro
assert!(ethereum_event_found);
}

pub struct SudoResult {
pub block_hash: H256,
pub extrinsic_hash: H256,
}

pub async fn send_sudo_xcm_transact(
penpal_client: &Box<OnlineClient<PenpalConfig>>,
message: Box<VersionedXcm>,
) -> Result<ExtrinsicEvents<PenpalConfig>, Box<dyn std::error::Error>> {
) -> Result<SudoResult, Box<dyn std::error::Error>> {
let dest = Box::new(VersionedLocation::V3(MultiLocation {
parents: 1,
interior: Junctions::X1(Junction::Parachain(BRIDGE_HUB_PARA_ID)),
Expand All @@ -203,11 +208,20 @@ pub async fn send_sudo_xcm_transact(
.sign_and_submit_then_watch_default(&sudo_call, &signer)
.await
.expect("send through xcm call.")
.wait_for_finalized_success()
.wait_for_finalized()
.await
.expect("xcm call failed");

Ok(result)
let block_hash = result.block_hash();
let extrinsic_hash = result.extrinsic_hash();

let sudo_result = SudoResult { block_hash, extrinsic_hash };

if let Err(err) = result.wait_for_success().await {
Err(Box::new(err))
} else {
Ok(sudo_result)
}
}

pub async fn initialize_wallet(
Expand Down
4 changes: 2 additions & 2 deletions smoketest/tests/create_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async fn create_agent() {

println!(
"xcm call issued at block hash {:?}, transaction hash {:?}",
result.block_hash(),
result.extrinsic_hash()
result.block_hash,
result.extrinsic_hash
);

wait_for_bridgehub_event::<CreateAgent>(&test_clients.bridge_hub_client).await;
Expand Down
4 changes: 2 additions & 2 deletions smoketest/tests/create_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async fn create_channel() {

println!(
"xcm call issued at block hash {:?}, transaction hash {:?}",
result.block_hash(),
result.extrinsic_hash()
result.block_hash,
result.extrinsic_hash
);

wait_for_bridgehub_event::<CreateChannel>(&test_clients.bridge_hub_client).await;
Expand Down
40 changes: 18 additions & 22 deletions smoketest/tests/send_token_to_penpal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ use snowbridge_smoketest::{
parachains::{
assethub::api::{
foreign_assets::events::Issued as AssetHubIssued,
runtime_types::{
staging_xcm::v3::multilocation::MultiLocation,
xcm::v3::{
junction::{
Junction::{AccountKey20, GlobalConsensus},
NetworkId,
},
junctions::Junctions::X2,
runtime_types::staging_xcm::v4::{
junction::{
Junction::{AccountKey20, GlobalConsensus},
NetworkId,
},
junctions::Junctions::X2,
location::Location,
},
},
penpal::{self, api::foreign_assets::events::Issued as PenpalIssued},
Expand Down Expand Up @@ -98,12 +96,12 @@ async fn send_token_to_penpal() {
.expect("block subscription")
.take(wait_for_blocks);

let expected_asset_id: MultiLocation = MultiLocation {
let expected_asset_id = Location {
parents: 2,
interior: X2(
interior: X2([
GlobalConsensus(NetworkId::Ethereum { chain_id: ETHEREUM_CHAIN_ID }),
AccountKey20 { network: None, key: WETH_CONTRACT.into() },
),
]),
};
let assethub_expected_owner: AccountId32 = PENPAL_SOVEREIGN.into();

Expand Down Expand Up @@ -156,22 +154,20 @@ async fn send_token_to_penpal() {
}

async fn ensure_penpal_asset_exists(penpal_client: &mut OnlineClient<PenpalConfig>) {
use penpal::api::runtime_types::{
staging_xcm::v3::multilocation::MultiLocation,
xcm::v3::{
junction::{
Junction::{AccountKey20, GlobalConsensus},
NetworkId,
},
junctions::Junctions::X2,
use penpal::api::runtime_types::staging_xcm::v4::{
junction::{
Junction::{AccountKey20, GlobalConsensus},
NetworkId,
},
junctions::Junctions::X2,
location::Location,
};
let penpal_asset_id = MultiLocation {
let penpal_asset_id = Location {
parents: 2,
interior: X2(
interior: X2([
GlobalConsensus(NetworkId::Ethereum { chain_id: ETHEREUM_CHAIN_ID }),
AccountKey20 { network: None, key: WETH_CONTRACT.into() },
),
]),
};

let penpal_asset_address = penpal::api::storage().foreign_assets().asset(&penpal_asset_id);
Expand Down
4 changes: 2 additions & 2 deletions smoketest/tests/transfer_native_from_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ async fn transfer_native_from_agent() {

println!(
"xcm call issued at block hash {:?}, transaction hash {:?}",
result.block_hash(),
result.extrinsic_hash()
result.block_hash,
result.extrinsic_hash
);

wait_for_bridgehub_event::<TransferNativeFromAgent>(&test_clients.bridge_hub_client).await;
Expand Down
17 changes: 12 additions & 5 deletions smoketest/tests/upgrade_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ use snowbridge_smoketest::{
relaychain,
relaychain::api::runtime_types::{
pallet_xcm::pallet::Call,
rococo_runtime::RuntimeCall,
sp_weights::weight_v2::Weight,
staging_xcm::v3::multilocation::MultiLocation,
westend_runtime::RuntimeCall,
xcm::{
double_encoded::DoubleEncoded,
v2::OriginKind,
v3::{junction::Junction, junctions::Junctions, Instruction, WeightLimit, Xcm},
v3::{
junction::Junction, junctions::Junctions, Instruction, OriginKind, WeightLimit,
Xcm,
},
VersionedLocation, VersionedXcm,
},
},
Expand Down Expand Up @@ -111,12 +113,17 @@ async fn upgrade_gateway() {
.sign_and_submit_then_watch_default(&sudo_call, &signer)
.await
.expect("send through sudo call.")
.wait_for_finalized_success()
.wait_for_finalized()
.await
.expect("sudo call success");
.expect("sudo call in block");

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

result
.wait_for_success()
.await
.expect("sudo call success");

let wait_for_blocks = 5;
let mut blocks = bridgehub
.blocks()
Expand Down
13 changes: 13 additions & 0 deletions web/packages/operations/src/transfer_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
toEthereum,
toPolkadot,
} from "@snowbridge/api"
import { WETH9__factory } from "@snowbridge/contract-types"
import { Wallet } from "ethers"

const monitor = async () => {
Expand Down Expand Up @@ -55,6 +56,18 @@ const monitor = async () => {
(t) => t.id === "WETH"
)!.address

console.log("# Deposit and Approve WETH")
{
const weth9 = WETH9__factory.connect(WETH_CONTRACT, ETHEREUM_ACCOUNT)
const depositResult = await weth9.deposit({ value: amount })
const depositReceipt = await depositResult.wait()

const approveResult = await weth9.approve(config.GATEWAY_CONTRACT, amount)
const approveReceipt = await approveResult.wait()

console.log('deposit tx', depositReceipt?.hash, 'approve tx', approveReceipt?.hash)
}

console.log("# Ethereum to Asset Hub")
{
const plan = await toPolkadot.validateSend(
Expand Down
14 changes: 7 additions & 7 deletions web/packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"directory": "web/packages/test"
},
"devDependencies": {
"@polkadot/api": "^11.2.1",
"@polkadot/api-cli": "^0.56.11",
"@polkadot/keyring": "^12.6.2",
"@polkadot/types": "^11.2.1",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@polkadot/api": "^12.4.2",
"@polkadot/types": "^12.4.2",
"@polkadot/api-cli": "^0.57.4",
"@polkadot/keyring": "^13.0.2",
"@polkadot/util": "^13.0.2",
"@polkadot/util-crypto": "^13.0.2",
"@types/keccak": "^3.0.1",
"@types/node": "^18.16.8",
"@types/yargs": "^17.0.24",
"@zombienet/cli": "^1.3.93",
"@zombienet/cli": "^1.3.109",
"bignumber.js": "^9.1.1",
"bn.js": "^5.2.1",
"c-kzg": "^1.1.3",
Expand Down
2 changes: 1 addition & 1 deletion web/packages/test/scripts/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build_binaries() {
# Check that all 3 binaries are available and no changes made in the polkadot and substrate dirs
if [[ ! -e "target/release/polkadot" || ! -e "target/release/polkadot-execute-worker" || ! -e "target/release/polkadot-prepare-worker" || "$changes_detected" -eq 1 ]]; then
echo "Building polkadot binary, due to changes detected in polkadot or substrate, or binaries not found"
cargo build --release --locked --bin polkadot --bin polkadot-execute-worker --bin polkadot-prepare-worker $features
EPOCH_DURATION=10 cargo build --release --locked --bin polkadot --bin polkadot-execute-worker --bin polkadot-prepare-worker $features
else
echo "No changes detected in polkadot or substrate and binaries are available, not rebuilding relaychain binaries."
fi
Expand Down
4 changes: 1 addition & 3 deletions web/packages/test/scripts/configure-substrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ open_hrmp_channel() {
echo " params:"
echo "--------------------------------------------------"

npx polkadot-js-api \
call_polkadot_js_api \
--ws "${relay_url?}" \
--seed "${relay_chain_seed?}" \
--sudo \
--noWait \
--nonce -1 \
tx.hrmp.forceOpenHrmpChannel \
${sender_para_id} \
${recipient_para_id} \
Expand Down
Loading

0 comments on commit 3291185

Please sign in to comment.