Skip to content

Commit

Permalink
remove mock runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthDesai committed Nov 20, 2024
1 parent 77d47fb commit 011fdc6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 373 deletions.
46 changes: 35 additions & 11 deletions solo-chains/runtime/dancelight/src/bridge_to_ethereum_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
pub const SLOTS_PER_EPOCH: u32 = snowbridge_pallet_ethereum_client::config::SLOTS_PER_EPOCH as u32;
#[cfg(not(feature = "runtime-benchmarks"))]
use crate::symbiotic_message_processor::SymbioticMessageProcessor;
#[cfg(not(test))]
use crate::EthereumBeaconClient;
use frame_support::weights::ConstantMultiplier;
use parity_scale_codec::Encode;
use snowbridge_router_primitives::inbound::{
Expand All @@ -30,8 +32,8 @@ use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash
use {
crate::{
parameter_types, weights, xcm_config, AccountId, AggregateMessageOrigin, Balance, Balances,
EthereumBeaconClient, EthereumInboundQueue, EthereumOutboundQueue, EthereumSystem,
FixedU128, GetAggregateMessageOrigin, Keccak256, MessageQueue, Runtime, RuntimeEvent,
EthereumInboundQueue, EthereumOutboundQueue, EthereumSystem, FixedU128,
GetAggregateMessageOrigin, Keccak256, MessageQueue, Runtime, RuntimeEvent,
TransactionByteFee, TreasuryAccount, WeightToFee, UNITS,
},
pallet_xcm::EnsureXcm,
Expand Down Expand Up @@ -160,14 +162,14 @@ impl snowbridge_pallet_system::Config for Runtime {
#[cfg(feature = "runtime-benchmarks")]
mod benchmark_helper {
use snowbridge_beacon_primitives::BeaconHeader;
use snowbridge_core::Channel;
use snowbridge_pallet_system::Channels;
use snowbridge_router_primitives::inbound::envelope::Envelope;
use snowbridge_router_primitives::inbound::MessageProcessor;
use sp_core::H256;
use {
crate::EthereumBeaconClient, crate::Runtime, crate::RuntimeOrigin, xcm::latest::Location,
};
use snowbridge_pallet_system::Channels;
use snowbridge_core::Channel;
use snowbridge_router_primitives::inbound::MessageProcessor;

pub struct EthSystemBenchHelper;

Expand All @@ -188,10 +190,13 @@ mod benchmark_helper {
let submit_message = snowbridge_pallet_inbound_queue_fixtures::register_token::make_register_token_message();
let envelope: Envelope = Envelope::try_from(&submit_message.message.event_log).unwrap();

Channels::<Runtime>::set(envelope.channel_id, Some(Channel {
agent_id: Default::default(),
para_id: Default::default()
}));
Channels::<Runtime>::set(
envelope.channel_id,
Some(Channel {
agent_id: Default::default(),
para_id: Default::default(),
}),
);

EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
}
Expand All @@ -200,10 +205,26 @@ mod benchmark_helper {
pub struct DoNothingMessageProcessor;

impl MessageProcessor for DoNothingMessageProcessor {
fn can_process_message(_: &Channel, _: &Envelope) -> bool { true }
fn can_process_message(_: &Channel, _: &Envelope) -> bool {
true
}

fn process_message(_: Channel, _: Envelope) -> Result<(), sp_runtime::DispatchError> { Ok(()) }
fn process_message(_: Channel, _: Envelope) -> Result<(), sp_runtime::DispatchError> {
Ok(())
}
}
}

#[cfg(test)]
mod test_helpers {
use snowbridge_core::inbound::{Log, Proof, VerificationError, Verifier};

pub struct MockVerifier;

impl Verifier for MockVerifier {
fn verify(_: &Log, _: &Proof) -> Result<(), VerificationError> {
Ok(())
}
}
}

Expand Down Expand Up @@ -238,7 +259,10 @@ impl ConvertMessage for DoNothingConvertMessage {

impl snowbridge_pallet_inbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
#[cfg(not(test))]
type Verifier = EthereumBeaconClient;
#[cfg(test)]
type Verifier = test_helpers::MockVerifier;
type Token = Balances;
type XcmSender = DoNothingRouter;
type GatewayAddress = EthereumGatewayAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
use crate::symbiotic_message_processor::{Command, Payload, MAGIC_BYTES};
use crate::tests::inbound_queue_tests::mock::{
mock_ext, AccountId, ExternalValidators as MockExternalValidators, InboundQueue,
Test as TestRuntime, MOCK_CHANNEL_ID,
};
use crate::tests::common::ExtBuilder;
use crate::{AccountId, EthereumInboundQueue, ExternalValidators, Runtime};
use alloy_sol_types::SolEvent;
use frame_system::pallet_prelude::OriginFor;
use keyring::AccountKeyring;
use parity_scale_codec::Encode;
use snowbridge_beacon_primitives::types::deneb;
use snowbridge_beacon_primitives::{ExecutionProof, VersionedExecutionPayloadHeader};
use snowbridge_core::inbound::{Log, Message, Proof};
use snowbridge_core::{
inbound::{Log, Message, Proof},
Channel, ChannelId,
};
use snowbridge_router_primitives::inbound::envelope::OutboundMessageAccepted;
use sp_core::H256;
use sp_runtime::DispatchError;

const MOCK_CHANNEL_ID: [u8; 32] = [0; 32];

#[test]
fn test_inbound_queue_message_passing() {
mock_ext().execute_with(|| {
ExtBuilder::default().build().execute_with(|| {
let current_nonce = 1;

snowbridge_pallet_system::Channels::<Runtime>::set(ChannelId::from(MOCK_CHANNEL_ID), Some(Channel {
agent_id: Default::default(),
para_id: Default::default()
}));

let dummy_proof = Proof { receipt_proof: (vec![], vec![]), execution_proof: ExecutionProof {
header: Default::default(),
ancestry_proof: None,
Expand Down Expand Up @@ -51,16 +59,16 @@ fn test_inbound_queue_message_passing() {
payload: vec![],
};

assert_eq!(InboundQueue::submit(OriginFor::<TestRuntime>::signed(AccountId::new([0; 32])), Message {
assert_eq!(EthereumInboundQueue::submit(OriginFor::<Runtime>::signed(AccountId::new([0; 32])), Message {
event_log: Log {
address: <TestRuntime as snowbridge_pallet_inbound_queue::Config>::GatewayAddress::get(),
address: <Runtime as snowbridge_pallet_inbound_queue::Config>::GatewayAddress::get(),
topics: event_with_empty_payload.encode_topics().into_iter().map(|word| H256::from(word.0.0)).collect(),
data: event_with_empty_payload.encode_data(),
},
proof: dummy_proof.clone(),
}), Err(DispatchError::Other("No handler for message found")));

assert_eq!(MockExternalValidators::validators(), MockExternalValidators::whitelisted_validators());
assert_eq!(ExternalValidators::validators(), ExternalValidators::whitelisted_validators());

let payload_validators = vec![
AccountKeyring::Charlie.to_account_id(),
Expand All @@ -70,7 +78,7 @@ fn test_inbound_queue_message_passing() {

let payload = Payload {
magic_bytes: MAGIC_BYTES,
message: crate::symbiotic_message_processor::Message::V1(Command::<TestRuntime>::ReceiveValidators {
message: crate::symbiotic_message_processor::Message::V1(Command::<Runtime>::ReceiveValidators {
validators: payload_validators.clone()
}),
};
Expand All @@ -82,17 +90,17 @@ fn test_inbound_queue_message_passing() {
payload: payload.encode(),
};

assert_eq!(InboundQueue::submit(OriginFor::<TestRuntime>::signed(AccountId::new([0; 32])), Message {
assert_eq!(EthereumInboundQueue::submit(OriginFor::<Runtime>::signed(AccountId::new([0; 32])), Message {
event_log: Log {
address: <TestRuntime as snowbridge_pallet_inbound_queue::Config>::GatewayAddress::get(),
address: <Runtime as snowbridge_pallet_inbound_queue::Config>::GatewayAddress::get(),
topics: event_with_valid_payload.encode_topics().into_iter().map(|word| H256::from(word.0.0)).collect(),
data: event_with_valid_payload.encode_data(),
},
proof: dummy_proof.clone(),
}), Ok(()));


let expected_validators = [MockExternalValidators::whitelisted_validators(), payload_validators].concat();
assert_eq!(MockExternalValidators::validators(), expected_validators);
let expected_validators = [ExternalValidators::whitelisted_validators(), payload_validators].concat();
assert_eq!(ExternalValidators::validators(), expected_validators);
});
}
Loading

0 comments on commit 011fdc6

Please sign in to comment.