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

Daily Smoketests #1287

Merged
merged 39 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
870cff9
test smoketests
claravanstaden Sep 13, 2024
b8c6806
remove dir
claravanstaden Sep 13, 2024
9031b55
check dirs
claravanstaden Sep 13, 2024
65fb99a
fix
claravanstaden Sep 13, 2024
b255a82
fix
claravanstaden Sep 13, 2024
a7fbbaa
fix
claravanstaden Sep 13, 2024
cac67ff
fix
claravanstaden Sep 13, 2024
50ca037
check
claravanstaden Sep 13, 2024
3f861f7
create dir
claravanstaden Sep 13, 2024
6c2b6ec
test
claravanstaden Sep 13, 2024
9adf842
remove dir
claravanstaden Sep 13, 2024
c8c80e6
cleanup
claravanstaden Sep 13, 2024
0192354
remove polkadot-sdk checkout
claravanstaden Sep 13, 2024
0a500e8
run start-services
claravanstaden Sep 13, 2024
9c0c65a
add rust-src
claravanstaden Sep 13, 2024
ef721c6
test on Snowfork branch
claravanstaden Sep 16, 2024
c1a1ec0
complete e2e services test
claravanstaden Sep 16, 2024
edfd756
remove extra sh
claravanstaden Sep 16, 2024
d828427
change to stable branch
claravanstaden Oct 3, 2024
7b38d79
Merge branch 'main' into smoketests-on-snowbridge
claravanstaden Oct 3, 2024
cc3d539
bump
claravanstaden Oct 3, 2024
7fd8ff7
see whats cookin
claravanstaden Oct 3, 2024
8d2dc16
adds dir
claravanstaden Oct 3, 2024
1116d52
test
claravanstaden Oct 3, 2024
10e1980
run tests
claravanstaden Oct 3, 2024
44cd232
print out env
claravanstaden Oct 4, 2024
bd5286d
whoops
claravanstaden Oct 4, 2024
617294a
check var
claravanstaden Oct 4, 2024
09339ea
see whats up
claravanstaden Oct 7, 2024
0ff2179
add things back
claravanstaden Oct 7, 2024
4d3266c
remove 0x from contract address
claravanstaden Oct 7, 2024
984d573
fix test
claravanstaden Oct 7, 2024
7897a1a
Merge branch 'main' into smoketests-on-snowbridge
claravanstaden Oct 7, 2024
16f9327
cleanup
claravanstaden Oct 8, 2024
e0a553f
remove comment
claravanstaden Oct 8, 2024
2ed32c6
fix penpal
claravanstaden Oct 9, 2024
4203813
Merge branch 'clara/set-penpal-storage' into smoketests-on-snowbridge
claravanstaden Oct 9, 2024
f0b3c1c
fix printed messages
claravanstaden Oct 9, 2024
f717954
revert cron time and switch to main branch
claravanstaden Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: bridge

on:
push:
branches:
- main
workflow_dispatch:
schedule:
# Runs at 8:00 AM every day
- cron: '0 8 * * *'

jobs:
smoketests:
runs-on: snowbridge-runner
env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: 1
RUSTFLAGS: -C debuginfo=1
outputs:
success: ${{ steps.run_e2e_stack.outcome == 'success' }}
steps:
- uses: actions/checkout@v2
with:
repository: snowfork/snowbridge
ref: main
- run: rm -rf polkadot-sdk
- uses: actions/checkout@v2
with:
repository: paritytech/polkadot-sdk
ref: stable2409
path: ./polkadot-sdk
- uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Set build directory environment variable
run: echo "OUTPUT_DIR=${GITHUB_WORKSPACE}/tmp" >> $GITHUB_ENV
- name: Set log directory environment variable
run: echo "LOG_DIR=${GITHUB_WORKSPACE}/log-tmp" >> $GITHUB_ENV
- name: polkadot-sdk dir
run: echo "POLKADOT_SDK_DIR=./polkadot-sdk" >> $GITHUB_ENV
- name: Create directories
run: mkdir -p $OUTPUT_DIR && mkdir -p $LOG_DIR
- uses: actions/cache@v1
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: run E2E stack
id: run_e2e_stack
run: |
nix develop -c sh -c '
./scripts/init-smoketests.sh &&
cd web/packages/test &&
(./scripts/start-services.sh > "${{ env.LOG_DIR }}/start-services.log" 2>&1 &) &&
sleep 10 &&
./scripts/check-relayer.sh &&
./scripts/run-smoketests.sh'
continue-on-error: true
- name: Save start-services log file
uses: actions/upload-artifact@v3
with:
name: start-services.log
path: "${{ env.LOG_DIR }}/start-services.log"
- name: Save beacon-relay log file
uses: actions/upload-artifact@v3
with:
name: beacon-relay.log
path: "${{ env.OUTPUT_DIR }}/beacon-relay.log"
- run: ls
- name: check E2E test outcome
if: ${{ steps.run_e2e_stack.outcome != 'success' }}
run: |
echo "E2E tests failed"
exit 1
37 changes: 37 additions & 0 deletions scripts/init-smoketests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -eux

echo "Checkout lodestar"
pushd ..
if [ ! -d "lodestar" ]; then
git clone https://github.com/ChainSafe/lodestar
fi
if [ ! -L "snowbridge/lodestar" ]; then
(cd snowbridge && ln -sf ../lodestar lodestar)
fi
pushd lodestar
git fetch && git checkout $LODESTAR_VERSION
popd
popd

echo "Setting up git hooks"
git config --local core.hooksPath hooks/

echo "Installing Rust nightly toolchain"
rustup default stable
rustup target add wasm32-unknown-unknown
rustup component add rust-src
rustup install --profile minimal $RUST_NIGHTLY_VERSION
rustup component add --toolchain $RUST_NIGHTLY_VERSION rustfmt
rustup show

echo "Installing sszgen"
go install github.com/ferranbt/fastssz/[email protected]

echo "Installing cargo fuzz"
cargo install cargo-fuzz

echo "Installing web packages"
(cd web && pnpm install)

1 change: 1 addition & 0 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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ subxt-codegen = { version = "0.37.0" }
subxt-signer = { version = "0.37.0" }
ethers = { git = "https://github.com/gakonst/ethers-rs", default-features = false, features = ["abigen", "ws", "rustls"] }
lazy_static = "1.4.0"

sp-crypto-hashing = "0.1.0"
4 changes: 3 additions & 1 deletion smoketest/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub const PENPAL_SOVEREIGN: [u8; 32] =

lazy_static! {
// SS58: 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL
pub static ref ALICE: Pair = Pair::from_string("//Alice", None)
.expect("cannot create keypair");
pub static ref FERDIE: Pair = Pair::from_string("//Ferdie", None)
.expect("cannot create keypair");
pub static ref FERDIE_PUBLIC: [u8; 32] = (*FERDIE).public().into();
Expand Down Expand Up @@ -139,7 +141,7 @@ lazy_static! {
};
pub static ref GATEWAY_PROXY_CONTRACT: [u8; 20] = {
if let Ok(val) = env::var("GATEWAY_PROXY_CONTRACT") {
<[u8; 20]>::from_hex(val).unwrap()
<[u8; 20]>::from_hex(val.strip_prefix("0x").unwrap_or(&val)).unwrap()
}
else {
DEFAULT_GATEWAY_PROXY_CONTRACT
Expand Down
115 changes: 108 additions & 7 deletions smoketest/tests/send_token_to_penpal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use snowbridge_smoketest::{
Junction::{AccountKey20, GlobalConsensus},
NetworkId,
},
junctions::Junctions::X2,
junctions::Junctions::{Here, X2},
location::Location,
},
},
Expand All @@ -29,6 +29,11 @@ use subxt::{
utils::{AccountId32, MultiAddress},
OnlineClient,
};
use sp_crypto_hashing::twox_128;
use penpal::{api::runtime_types as penpalTypes};
use penpalTypes::{
penpal_runtime::RuntimeCall as PenpalRuntimeCall,
};

#[tokio::test]
async fn send_token_to_penpal() {
Expand All @@ -50,7 +55,9 @@ async fn send_token_to_penpal() {
let receipt = weth.deposit().value(value).send().await.unwrap().await.unwrap().unwrap();
assert_eq!(receipt.status.unwrap().as_u64(), 1u64);

set_reserve_asset_storage(&mut penpal_client.clone()).await;
ensure_penpal_asset_exists(&mut penpal_client.clone()).await;
ensure_dot_asset_exists(&mut penpal_client.clone()).await;

// Approve token spend
weth.approve(gateway_addr, value.into())
Expand Down Expand Up @@ -99,6 +106,10 @@ async fn send_token_to_penpal() {
.expect("block subscription")
.take(wait_for_blocks);

let expected_dot_id = Location {
parents: 1,
interior: Here,
};
let expected_asset_id = Location {
parents: 2,
interior: X2([
Expand Down Expand Up @@ -137,23 +148,33 @@ async fn send_token_to_penpal() {
let penpal_expected_owner: AccountId32 = (*FERDIE_PUBLIC).into();

issued_event_found = false;
let mut issued_fee_event_found = false;
while let Some(Ok(block)) = penpal_blocks.next().await {
println!("Polling penpal block {} for issued event.", block.number());

let events = block.events().await.unwrap();
for issued in events.find::<PenpalIssued>() {
println!("Created event found in penpal block {}.", block.number());
let issued = issued.unwrap();
assert_eq!(issued.asset_id.encode(), expected_asset_id.encode());
assert_eq!(issued.owner, penpal_expected_owner);
assert_eq!(issued.amount, amount);
issued_event_found = true;
// DOT fee deposited
if issued.asset_id.encode() == expected_dot_id.encode() {
println!("Issued DOT event found in penpal block {}.", block.number());
assert_eq!(issued.owner, penpal_expected_owner);
issued_fee_event_found = true
}
// Weth deposited
if issued.asset_id.encode() == expected_asset_id.encode() {
println!("Issued Weth event found in penpal block {}.", block.number());
assert_eq!(issued.owner, penpal_expected_owner);
assert_eq!(issued.amount, amount);
issued_event_found = true;
}
}
if issued_event_found {
if issued_event_found && issued_fee_event_found {
break
}
}
assert!(issued_event_found);
assert!(issued_fee_event_found);
}

async fn ensure_penpal_asset_exists(penpal_client: &mut OnlineClient<PenpalConfig>) {
Expand Down Expand Up @@ -202,3 +223,83 @@ async fn ensure_penpal_asset_exists(penpal_client: &mut OnlineClient<PenpalConfi
.await
.expect("asset created");
}

async fn ensure_dot_asset_exists(penpal_client: &mut OnlineClient<PenpalConfig>) {
use penpal::api::runtime_types::staging_xcm::v4::{
junctions::Junctions::Here,
location::Location,
};
let dot_asset_id = Location {
parents: 1,
interior: Here,
};

let dot_asset_address = penpal::api::storage().foreign_assets().asset(&dot_asset_id);
let result = penpal_client
.storage()
.at_latest()
.await
.unwrap()
.fetch(&dot_asset_address)
.await
.unwrap();

if result.is_some() {
println!("DOT asset exists on penpal.");
return
}

println!("creating DOT on penpal.");
let admin = MultiAddress::Id(ASSET_HUB_SOVEREIGN.into());
let signer: PairSigner<PenpalConfig, _> = PairSigner::new((*FERDIE).clone());

let create_asset_call = penpal::api::tx().foreign_assets().create(dot_asset_id, admin, 1);
penpal_client
.tx()
.sign_and_submit_then_watch_default(&create_asset_call, &signer)
.await
.unwrap()
.wait_for_finalized_success()
.await
.expect("asset created");
}
async fn set_reserve_asset_storage(penpal_client: &mut OnlineClient<PenpalConfig>) {
use penpal::api::runtime_types::staging_xcm::v4::{
junction::{
Junction::GlobalConsensus,
NetworkId,
},
junctions::Junctions::X1,
location::Location,
};
let storage_key: Vec<u8> = twox_128(b":CustomizableAssetFromSystemAssetHub:").to_vec();
let reserve_location: Vec<u8> = Location {
parents: 2,
interior: X1([
GlobalConsensus(NetworkId::Ethereum { chain_id: ETHEREUM_CHAIN_ID }),
]),
}.encode();

println!("setting CustomizableAssetFromSystemAssetHub storage on penpal.");
let signer: PairSigner<PenpalConfig, _> = PairSigner::new((*ALICE).clone());

let items = vec![(
storage_key,
reserve_location,
)];

let sudo_call = penpal::api::sudo::calls::TransactionApi::sudo(
&penpal::api::sudo::calls::TransactionApi,
PenpalRuntimeCall::System(crate::penpalTypes::frame_system::pallet::Call::set_storage {
items
}),
);
penpal_client
.tx()
.sign_and_submit_then_watch_default(&sudo_call, &signer)
.await
.unwrap()
.wait_for_finalized_success()
.await
.expect("reserve location set");
}