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

Refactoring Inbound fixture #1125

Merged
merged 18 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ extend-exclude = [
"lodestar/**",
"go-ethereum/**",
"go.work.sum",
"parachain/Cargo.toml",
]
15 changes: 15 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 @@ -8,6 +8,7 @@ resolver = "2"
members = [
"pallets/ethereum-client",
"pallets/inbound-queue",
"pallets/inbound-queue/fixtures",
"pallets/outbound-queue",
"pallets/outbound-queue/merkle-tree",
"pallets/outbound-queue/runtime-api",
Expand Down
9 changes: 5 additions & 4 deletions parachain/pallets/inbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot-sdk
snowbridge-core = { path = "../../primitives/core", default-features = false }
snowbridge-ethereum = { path = "../../primitives/ethereum", default-features = false }
snowbridge-router-primitives = { path = "../../primitives/router", default-features = false }
snowbridge-beacon-primitives = { path = "../../primitives/beacon", default-features = false, optional = true }
snowbridge-beacon-primitives = { path = "../../primitives/beacon", default-features = false }
snowbridge-pallet-inbound-queue-fixtures = { path = "./fixtures", optional = true }

[dev-dependencies]
frame-benchmarking = { path = "../../../polkadot-sdk/substrate/frame/benchmarking" }
sp-keyring = { path = "../../../polkadot-sdk/substrate/primitives/keyring" }
snowbridge-beacon-primitives = { path = "../../primitives/beacon" }
snowbridge-pallet-ethereum-client = { path = "../ethereum-client" }
snowbridge-pallet-ethereum-client = { path = "../../pallets/ethereum-client" }
hex-literal = { version = "0.4.1" }

[features]
Expand All @@ -65,6 +65,7 @@ std = [
"pallet-balances/std",
"scale-info/std",
"serde",
"snowbridge-beacon-primitives/std",
"snowbridge-core/std",
"snowbridge-ethereum/std",
"snowbridge-router-primitives/std",
Expand All @@ -83,9 +84,9 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"hex-literal",
"pallet-balances/runtime-benchmarks",
"snowbridge-beacon-primitives",
"snowbridge-core/runtime-benchmarks",
"snowbridge-pallet-ethereum-client/runtime-benchmarks",
"snowbridge-pallet-inbound-queue-fixtures/runtime-benchmarks",
"snowbridge-router-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down
44 changes: 44 additions & 0 deletions parachain/pallets/inbound-queue/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "snowbridge-pallet-inbound-queue-fixtures"
description = "Snowbridge Inbound Queue Test Fixtures"
version = "0.9.0"
authors = ["Snowfork <[email protected]>"]
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",
]
14 changes: 14 additions & 0 deletions parachain/pallets/inbound-queue/fixtures/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![cfg_attr(not(feature = "std"), no_std)]
claravanstaden marked this conversation as resolved.
Show resolved Hide resolved

use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_core::inbound::Message;
use sp_core::RuntimeDebug;

pub mod register_asset;
pub mod send_token;

#[derive(Clone, RuntimeDebug)]
pub struct InboundQueueFixture {
pub execution_header: CompactExecutionHeader,
pub message: Message,
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// Generated, do not edit!
// See ethereum client README.md for instructions to generate

use crate::InboundQueueFixture;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_core::inbound::{Log, Message, Proof};
use sp_std::vec;

pub struct InboundQueueTest {
pub execution_header: CompactExecutionHeader,
pub message: Message,
}
pub type RegisterAsset = InboundQueueFixture;
claravanstaden marked this conversation as resolved.
Show resolved Hide resolved

pub fn make_create_message() -> InboundQueueTest {
InboundQueueTest {
pub fn make_register_asset_message() -> RegisterAsset {
RegisterAsset {
execution_header: CompactExecutionHeader{
parent_hash: hex!("d82ec63f5c5e6ba61d62f09c188f158e6449b94bdcc31941e68639eec3c4cf7a").into(),
block_number: 215,
state_root: hex!("8b65545fe5f3216b47b6339b9c91ca2b7f1032a970b04246d9e9fb4460ee34c3").into(),
parent_hash: hex!("3057299569c0526f0f45d505c11aad541b3d0a1d58ca1ecd0ec72e6615362b1c").into(),
block_number: 326,
state_root: hex!("e22da642f3054f0f8489dec3e99b877d1ba3abfc946074a50eadbb446830361a").into(),
receipts_root: hex!("7b1f61b9714c080ef0be014e01657a15f45f0304b477beebc7ca5596c8033095").into(),
},
message: Message {
Expand All @@ -29,7 +28,7 @@ pub fn make_create_message() -> InboundQueueTest {
data: hex!("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002e00a736aa00000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d00e40b54020000000000000000000000000000000000000000000000000000000000").into(),
},
proof: Proof {
block_hash: hex!("48498dbfbcfae53a7f4c289ee00747aceea925f6260c50ead5a33e1c55c40f98").into(),
block_hash: hex!("47593b0ddb170422509040562f3f3c3ef98d4cc7f47a2e5533d8a6b4ae9cd238").into(),
tx_index: 0,
data: (vec![
hex!("7b1f61b9714c080ef0be014e01657a15f45f0304b477beebc7ca5596c8033095").to_vec(),
Expand Down
41 changes: 41 additions & 0 deletions parachain/pallets/inbound-queue/fixtures/src/send_token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Generated, do not edit!
// See ethereum client README.md for instructions to generate

use crate::InboundQueueFixture;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_core::inbound::{Log, Message, Proof};
use sp_std::vec;

pub type SendToken = InboundQueueFixture;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think its a bit unnecessary to add this alias for each fixture.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should rather add a doc comment (only if necessary - the function name may be enough) saying that the returned fixture contains a send token message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the function name should be enough. Alias removed in 7faa581


pub fn make_send_token_message() -> SendToken {
SendToken {
execution_header: CompactExecutionHeader{
parent_hash: hex!("28deff91ce77038d14fbb699275329247c8fe06846f1ad536dacbc96d73409c5").into(),
block_number: 612,
state_root: hex!("1dec28a44eaa1feb8e46e137ee0fcaa1ef311c8fb5d8130fc82d81a79e1c141c").into(),
receipts_root: hex!("5eab8418f24f60e5f42818a9553d56275680519a08f0a75502b9c615f8ab4568").into(),
},
message: Message {
event_log: Log {
address: hex!("eda338e4dc46038493b885327842fd3e301cab39").into(),
topics: vec![
hex!("7153f9357c8ea496bba60bf82e67143e27b64462b49041f8e689e1b05728f84f").into(),
hex!("c173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539").into(),
hex!("c8eaf22f2cb07bac4679df0a660e7115ed87fcfd4e32ac269f6540265bbbd26f").into(),
],
data: hex!("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005f00a736aa00000000000187d1f7fdfee7f651fabc8bfcb6e086c278b77a7d001cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c000064a7b3b6e00d000000000000000000e40b5402000000000000000000000000").into(),
},
proof: Proof {
block_hash: hex!("547bee454fedd66dc371f1c3a1b7a1f5431d0595ce9bfb7a136f91a5d5ce4a2f").into(),
tx_index: 0,
data: (vec![
hex!("5eab8418f24f60e5f42818a9553d56275680519a08f0a75502b9c615f8ab4568").to_vec(),
], vec![
hex!("f90451822080b9044b02f90447018301bcb9b9010000800000000000000000000020000000000000000000004000000000000000000400000000000000000000001000000010000000000000000000000008000000200000000000000001000008000000000000000000000000000000008000080000000000200000000000000000000000000100000000000000000011000000000000020200000000000000000000000000003000000040080008000000000000000000040044000021000000002000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000200800000000000f9033cf89b9487d1f7fdfee7f651fabc8bfcb6e086c278b77a7df863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa000000000000000000000000090a987b944cb1dcce5564e5fdecd7a54d3de27fea000000000000000000000000057a2d4ff0c3866d96556884bf09fecdd7ccd530ca00000000000000000000000000000000000000000000000000de0b6b3a7640000f9015d94eda338e4dc46038493b885327842fd3e301cab39f884a024c5d2de620c6e25186ae16f6919eba93b6e2c1a33857cc419d9f3a00d6967e9a000000000000000000000000090a987b944cb1dcce5564e5fdecd7a54d3de27fea000000000000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7da000000000000000000000000000000000000000000000000000000000000003e8b8c000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000201cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07cf9013c94eda338e4dc46038493b885327842fd3e301cab39f863a07153f9357c8ea496bba60bf82e67143e27b64462b49041f8e689e1b05728f84fa0c173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539a0c8eaf22f2cb07bac4679df0a660e7115ed87fcfd4e32ac269f6540265bbbd26fb8c000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005f00a736aa00000000000187d1f7fdfee7f651fabc8bfcb6e086c278b77a7d001cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c000064a7b3b6e00d000000000000000000e40b5402000000000000000000000000").to_vec(),
]),
},
},
}
}
6 changes: 2 additions & 4 deletions parachain/pallets/inbound-queue/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod fixtures;

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
use super::*;
Expand All @@ -8,17 +6,17 @@ use crate::Pallet as InboundQueue;
use frame_benchmarking::v2::*;
use frame_support::assert_ok;
use frame_system::RawOrigin;
use snowbridge_pallet_inbound_queue_fixtures::register_asset::make_register_asset_message;

#[benchmarks]
mod benchmarks {
use super::*;
use crate::benchmarking::fixtures::make_create_message;

#[benchmark]
fn submit() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();

let create_message = make_create_message();
let create_message = make_register_asset_message();

T::Helper::initialize_storage(
create_message.message.proof.block_hash,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Generated, do not edit!
// See ethereum client README.md for instructions to generate

use crate::InboundQueueFixture;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_core::inbound::{Log, Message, Proof};
use sp_std::vec;

pub struct InboundQueueTest {
pub execution_header: CompactExecutionHeader,
pub message: Message,
}
pub type RegisterAsset = InboundQueueFixture;

pub fn make_create_message() -> InboundQueueTest {
InboundQueueTest {
pub fn make_register_asset_message() -> RegisterAsset {
RegisterAsset {
execution_header: CompactExecutionHeader{
parent_hash: hex!("{{InboundMessageTest.ExecutionHeader.ParentHash}}").into(),
block_number: {{InboundMessageTest.ExecutionHeader.BlockNumber}},
Expand Down
45 changes: 45 additions & 0 deletions parachain/templates/send_token.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Generated, do not edit!
// See ethereum client README.md for instructions to generate

use crate::InboundQueueFixture;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_core::inbound::{Log, Message, Proof};
use sp_std::vec;

pub type SendToken = InboundQueueFixture;

pub fn make_send_token_message() -> SendToken {
SendToken {
execution_header: CompactExecutionHeader{
parent_hash: hex!("{{InboundMessageTest.ExecutionHeader.ParentHash}}").into(),
block_number: {{InboundMessageTest.ExecutionHeader.BlockNumber}},
state_root: hex!("{{InboundMessageTest.ExecutionHeader.StateRoot}}").into(),
receipts_root: hex!("{{InboundMessageTest.ExecutionHeader.ReceiptsRoot}}").into(),
},
message: Message {
event_log: Log {
address: hex!("{{InboundMessageTest.Message.EventLog.Address}}").into(),
topics: vec![
{{#InboundMessageTest.Message.EventLog.Topics}}
hex!("{{.}}").into(),
{{/InboundMessageTest.Message.EventLog.Topics}}
],
data: hex!("{{InboundMessageTest.Message.EventLog.Data}}").into(),
},
proof: Proof {
block_hash: hex!("{{InboundMessageTest.Message.Proof.BlockHash}}").into(),
tx_index: {{InboundMessageTest.Message.Proof.TxIndex}},
data: (vec![
{{#InboundMessageTest.Message.Proof.Data.Keys}}
hex!("{{.}}").to_vec(),
{{/InboundMessageTest.Message.Proof.Data.Keys}}
], vec![
{{#InboundMessageTest.Message.Proof.Data.Values}}
hex!("{{.}}").to_vec(),
{{/InboundMessageTest.Message.Proof.Data.Values}}
]),
},
},
}
}
7 changes: 4 additions & 3 deletions relayer/chain/ethereum/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ func MakeMessageFromEvent(event *etypes.Log, receiptsTrie *etrie.Trie) (*paracha
}

log.WithFields(logrus.Fields{
"EventLog": m.EventLog,
"Proof": m.Proof,
"txHash": event.TxHash.Hex(),
"EventLog": m.EventLog,
"Proof": m.Proof,
"txHash": event.TxHash.Hex(),
"BlockNumber": event.BlockNumber,
}).Debug("Generated message from Ethereum log")

return &m, nil
Expand Down
Loading
Loading