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

Adds runtime tests #1114

Merged
merged 16 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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",
Copy link
Contributor

@yrong yrong Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the fixture crate is only for tests so unnecessary here?

"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",
]
Comment on lines +38 to +44
Copy link
Contributor

@yrong yrong Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime-benchmarks seems also unnecessary here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referenced the inbound fixtures crate you added. 😅 https://github.com/Snowfork/snowbridge/blob/main/parachain/pallets/inbound-queue/fixtures/Cargo.toml#L38 Is it necessary in that crate?

Copy link
Contributor

@yrong yrong Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems also unnecessary in that crate because IIUC we're using the fixture from local setup for the benchmark?

IMO the benefit of introducing the runtime-benchmarks feature is to differentiate the fixture between public network(goerli/sepolia) and local setup(hacked mainnet), As we know the fork version is different and we may want to use the real data(from public network) for the benchmark.

But it's nitpicky and not the scope of this PR, so feel free to ignore it.

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
Loading