Skip to content

Commit

Permalink
Adds runtime tests (#1114)
Browse files Browse the repository at this point in the history
* adds runtime tests

* fix beacon feature bug

* commit changes

* inbound queue test

* scratchpad

* revert unnessary changes and create new beacon fixtures crate

* tests

* fmt

* taplo

* more tests

* adds own run to block

* Fix the breaking test

* updates polkadot-sdk

* update polkadot-sdk

* simply test code

* update polkadot-sdk

---------

Co-authored-by: claravanstaden <Cats 4 life!>
Co-authored-by: ron <yrong1997@gmail.com>
  • Loading branch information
claravanstaden and yrong authored Jan 26, 2024
1 parent 3b17d2a commit 252df12
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 14 deletions.
16 changes: 16 additions & 0 deletions parachain/Cargo.lock

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

1 change: 1 addition & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository = "https://github.com/snowfork/snowbridge.git"
resolver = "2"
members = [
"pallets/ethereum-client",
"pallets/ethereum-client/fixtures",
"pallets/inbound-queue",
"pallets/inbound-queue/fixtures",
"pallets/outbound-queue",
Expand Down
4 changes: 4 additions & 0 deletions parachain/pallets/ethereum-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sp-io = { path = "../../../polkadot-sdk/substrate/primitives/io", default-featur

snowbridge-core = { path = "../../primitives/core", default-features = false }
snowbridge-ethereum = { path = "../../primitives/ethereum", default-features = false }
snowbridge-pallet-ethereum-client-fixtures = { path = "./fixtures", optional = true }
primitives = { package = "snowbridge-beacon-primitives", path = "../../primitives/beacon", default-features = false }
static_assertions = { version = "1.1.0", default-features = false }
bp-runtime = { path = "../../../polkadot-sdk/bridges/primitives/runtime", default-features = false }
Expand All @@ -47,6 +48,7 @@ sp-keyring = { path = "../../../polkadot-sdk/substrate/primitives/keyring" }
serde_json = "1.0.111"
hex-literal = "0.4.1"
pallet-timestamp = { path = "../../../polkadot-sdk/substrate/frame/timestamp" }
snowbridge-pallet-ethereum-client-fixtures = { path = "./fixtures" }
sp-io = { path = "../../../polkadot-sdk/substrate/primitives/io" }
serde = "1.0.195"

Expand All @@ -73,6 +75,7 @@ std = [
"serde",
"snowbridge-core/std",
"snowbridge-ethereum/std",
"snowbridge-pallet-ethereum-client-fixtures/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
Expand All @@ -87,6 +90,7 @@ runtime-benchmarks = [
"hex-literal",
"pallet-timestamp?/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"snowbridge-pallet-ethereum-client-fixtures/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
Expand Down
44 changes: 44 additions & 0 deletions parachain/pallets/ethereum-client/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "snowbridge-pallet-ethereum-client-fixtures"
description = "Snowbridge Ethereum Client Test Fixtures"
version = "0.9.0"
authors = ["Snowfork <contact@snowfork.com>"]
edition.workspace = true
repository.workspace = true
license = "Apache-2.0"
categories = ["cryptography::cryptocurrencies"]

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
hex-literal = { version = "0.4.1" }
sp-core = { path = "../../../../polkadot-sdk/substrate/primitives/core", default-features = false }
sp-std = { path = "../../../../polkadot-sdk/substrate/primitives/std", default-features = false }
frame-benchmarking = { path = "../../../../polkadot-sdk/substrate/frame/benchmarking", default-features = false, optional = true }
frame-support = { path = "../../../../polkadot-sdk/substrate/frame/support", default-features = false }
frame-system = { path = "../../../../polkadot-sdk/substrate/frame/system", default-features = false }
snowbridge-core = { path = "../../../primitives/core", default-features = false }
snowbridge-beacon-primitives = { path = "../../../primitives/beacon", default-features = false }

[features]
default = ["std"]
std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"snowbridge-beacon-primitives/std",
"snowbridge-core/std",
"sp-core/std",
"sp-std/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
]
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
// Generated, do not edit!
// See README.md for instructions to generate
use crate::{CheckpointUpdate, ExecutionHeaderUpdate, Update};
#![cfg_attr(not(feature = "std"), no_std)]

use hex_literal::hex;
use primitives::{
types::deneb, updates::AncestryProof, BeaconHeader, NextSyncCommitteeUpdate, SyncAggregate,
SyncCommittee, VersionedExecutionPayloadHeader,
use snowbridge_beacon_primitives::{
types::deneb, updates::AncestryProof, BeaconHeader, ExecutionHeaderUpdate,
NextSyncCommitteeUpdate, SyncAggregate, SyncCommittee, VersionedExecutionPayloadHeader,
};
use sp_core::U256;
use sp_std::{boxed::Box, vec};

const SC_SIZE: usize = 512;
const SC_BITS_SIZE: usize = 64;
type CheckpointUpdate = snowbridge_beacon_primitives::CheckpointUpdate<SC_SIZE>;
type Update = snowbridge_beacon_primitives::Update<SC_SIZE, SC_BITS_SIZE>;

pub fn make_checkpoint() -> Box<CheckpointUpdate> {
Box::new(CheckpointUpdate {
header: BeaconHeader {
Expand Down Expand Up @@ -536,11 +544,11 @@ pub fn make_checkpoint() -> Box<CheckpointUpdate> {
aggregate_pubkey: hex!("8fbd66eeec2ff69ef0b836f04b1d67d88bcd4dfd495061964ad757c77abe822a39fa1cd8ed0d4d9bc9276cea73fd745c").into(),
},
current_sync_committee_branch: vec![
hex!("3ade38d498a062b50880a9409e1ca3a7fd4315d91eeb3bb83e56ac6bfe8d6a59").into(),
hex!("93880225bf99a0c5ec22b266ff829837754e9c5edf37a68c05b8f803fd82fa45").into(),
hex!("4c60656ec9a95fcf11030ad309c716b5b15beb7f60a0bcfc7c9d4eff505472ff").into(),
hex!("22d1645fceb4bf9a695043dda19a53e784ec70df6a6b1bd66ea30eba1cca5f2f").into(),
hex!("a8fc6cad84ceefc633ec56c2d031d525e1cb4b51c70eb252919fce5bba9a1fde").into(),
hex!("3ade38d498a062b50880a9409e1ca3a7fd4315d91eeb3bb83e56ac6bfe8d6a59").into(),
hex!("93880225bf99a0c5ec22b266ff829837754e9c5edf37a68c05b8f803fd82fa45").into(),
hex!("4c60656ec9a95fcf11030ad309c716b5b15beb7f60a0bcfc7c9d4eff505472ff").into(),
hex!("22d1645fceb4bf9a695043dda19a53e784ec70df6a6b1bd66ea30eba1cca5f2f").into(),
hex!("a8fc6cad84ceefc633ec56c2d031d525e1cb4b51c70eb252919fce5bba9a1fde").into(),
],
validators_root: hex!("270d43e74ce340de4bca2b1936beca0f4f5408d9e78aec4850920baf659d5b69").into(),
block_roots_root: hex!("d160b7687041891b73e54b06fc4e04f82d0fa8fdd76705895e216c6b24709dfe").into(),
Expand Down
3 changes: 1 addition & 2 deletions parachain/pallets/ethereum-client/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
use super::*;
mod fixtures;
mod util;

use crate::Pallet as EthereumBeaconClient;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;

use fixtures::*;
use snowbridge_pallet_ethereum_client_fixtures::*;

use primitives::{
fast_aggregate_verify, prepare_aggregate_pubkey, prepare_aggregate_signature,
Expand Down
5 changes: 5 additions & 0 deletions parachain/runtime/test-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sp-core = { path = "../../../polkadot-sdk/substrate/primitives/core", default-fe
sp-genesis-builder = { path = "../../../polkadot-sdk/substrate/primitives/genesis-builder", default-features = false }
sp-inherents = { path = "../../../polkadot-sdk/substrate/primitives/inherents", default-features = false }
sp-io = { path = "../../../polkadot-sdk/substrate/primitives/io", default-features = false }
sp-keyring = { path = "../../../polkadot-sdk/substrate/primitives/keyring" }
sp-offchain = { path = "../../../polkadot-sdk/substrate/primitives/offchain", default-features = false }
sp-runtime = { path = "../../../polkadot-sdk/substrate/primitives/runtime", default-features = false }
sp-session = { path = "../../../polkadot-sdk/substrate/primitives/session", default-features = false }
Expand Down Expand Up @@ -81,6 +82,7 @@ snowbridge-core = { path = "../../primitives/core", default-features = false }
snowbridge-beacon-primitives = { path = "../../primitives/beacon", default-features = false }
snowbridge-router-primitives = { path = "../../primitives/router", default-features = false }
snowbridge-pallet-ethereum-client = { path = "../../pallets/ethereum-client", default-features = false }
snowbridge-pallet-ethereum-client-fixtures = { path = "../../pallets/ethereum-client/fixtures", default-features = false }
snowbridge-pallet-inbound-queue = { path = "../../pallets/inbound-queue", default-features = false }
snowbridge-pallet-outbound-queue = { path = "../../pallets/outbound-queue", default-features = false }
snowbridge-outbound-queue-runtime-api = { path = "../../pallets/outbound-queue/runtime-api", default-features = false }
Expand Down Expand Up @@ -138,6 +140,7 @@ std = [
"snowbridge-beacon-primitives/std",
"snowbridge-core/std",
"snowbridge-outbound-queue-runtime-api/std",
"snowbridge-pallet-ethereum-client-fixtures/std",
"snowbridge-pallet-ethereum-client/std",
"snowbridge-pallet-inbound-queue/std",
"snowbridge-pallet-outbound-queue/std",
Expand Down Expand Up @@ -188,6 +191,7 @@ runtime-benchmarks = [
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"snowbridge-pallet-ethereum-client-fixtures/runtime-benchmarks",
"snowbridge-pallet-ethereum-client/runtime-benchmarks",
"snowbridge-pallet-inbound-queue/runtime-benchmarks",
"snowbridge-pallet-outbound-queue/runtime-benchmarks",
Expand All @@ -197,3 +201,4 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
fast-runtime = []
Loading

0 comments on commit 252df12

Please sign in to comment.