mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Add some tests to check integrity of chain constants + bridge configuration (#1316)
* add some tests to check integrity of chain constants + bridge configuration * try to use named parameters where possible
This commit is contained in:
committed by
Bastian Köcher
parent
821b2e7184
commit
097a28418b
@@ -73,7 +73,9 @@ polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", bran
|
||||
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
bridge-runtime-common = { path = "../../runtime-common", features = ["integrity-test"] }
|
||||
libsecp256k1 = { version = "0.7", features = ["hmac"] }
|
||||
static_assertions = "1.1"
|
||||
|
||||
[build-dependencies]
|
||||
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -936,49 +936,6 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bp_runtime::Chain;
|
||||
use bridge_runtime_common::messages;
|
||||
|
||||
#[test]
|
||||
fn ensure_rialto_message_lane_weights_are_correct() {
|
||||
type Weights = pallet_bridge_messages::weights::MillauWeight<Runtime>;
|
||||
|
||||
pallet_bridge_messages::ensure_weights_are_correct::<Weights>(
|
||||
bp_rialto::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT,
|
||||
bp_rialto::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT,
|
||||
bp_rialto::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT,
|
||||
bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT,
|
||||
DbWeight::get(),
|
||||
);
|
||||
|
||||
let max_incoming_message_proof_size = bp_millau::EXTRA_STORAGE_PROOF_SIZE.saturating_add(
|
||||
messages::target::maximal_incoming_message_size(bp_rialto::Rialto::max_extrinsic_size()),
|
||||
);
|
||||
pallet_bridge_messages::ensure_able_to_receive_message::<Weights>(
|
||||
bp_rialto::Rialto::max_extrinsic_size(),
|
||||
bp_rialto::Rialto::max_extrinsic_weight(),
|
||||
max_incoming_message_proof_size,
|
||||
messages::target::maximal_incoming_message_dispatch_weight(
|
||||
bp_rialto::Rialto::max_extrinsic_weight(),
|
||||
),
|
||||
);
|
||||
|
||||
let max_incoming_inbound_lane_data_proof_size =
|
||||
bp_messages::InboundLaneData::<()>::encoded_size_hint(
|
||||
bp_rialto::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE,
|
||||
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as _,
|
||||
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX as _,
|
||||
)
|
||||
.unwrap_or(u32::MAX);
|
||||
pallet_bridge_messages::ensure_able_to_receive_confirmation::<Weights>(
|
||||
bp_rialto::Rialto::max_extrinsic_size(),
|
||||
bp_rialto::Rialto::max_extrinsic_weight(),
|
||||
max_incoming_inbound_lane_data_proof_size,
|
||||
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
|
||||
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
|
||||
DbWeight::get(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_size() {
|
||||
|
||||
@@ -291,15 +291,23 @@ impl MessagesParameter for RialtoToMillauMessagesParameter {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{AccountId, Call, ExistentialDeposit, Runtime, SystemCall, SystemConfig, VERSION};
|
||||
use crate::{
|
||||
AccountId, Call, DbWeight, ExistentialDeposit, MillauGrandpaInstance, Runtime, SystemCall,
|
||||
SystemConfig, WithMillauMessagesInstance, VERSION,
|
||||
};
|
||||
use bp_message_dispatch::CallOrigin;
|
||||
use bp_messages::{
|
||||
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
|
||||
MessageKey,
|
||||
};
|
||||
use bp_runtime::{derive_account_id, messages::DispatchFeePayment, SourceAccount};
|
||||
use bridge_runtime_common::messages::target::{
|
||||
FromBridgedChainEncodedMessageCall, FromBridgedChainMessagePayload,
|
||||
use bp_runtime::{derive_account_id, messages::DispatchFeePayment, Chain, SourceAccount};
|
||||
use bridge_runtime_common::{
|
||||
assert_complete_bridge_types,
|
||||
integrity::{
|
||||
assert_complete_bridge_constants, AssertBridgeMessagesPalletConstants,
|
||||
AssertBridgePalletNames, AssertChainConstants, AssertCompleteBridgeConstants,
|
||||
},
|
||||
messages::target::{FromBridgedChainEncodedMessageCall, FromBridgedChainMessagePayload},
|
||||
};
|
||||
use frame_support::{
|
||||
traits::Currency,
|
||||
@@ -377,4 +385,92 @@ mod tests {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_rialto_message_lane_weights_are_correct() {
|
||||
type Weights = pallet_bridge_messages::weights::MillauWeight<Runtime>;
|
||||
|
||||
pallet_bridge_messages::ensure_weights_are_correct::<Weights>(
|
||||
bp_rialto::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT,
|
||||
bp_rialto::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT,
|
||||
bp_rialto::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT,
|
||||
bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT,
|
||||
DbWeight::get(),
|
||||
);
|
||||
|
||||
let max_incoming_message_proof_size = bp_millau::EXTRA_STORAGE_PROOF_SIZE.saturating_add(
|
||||
messages::target::maximal_incoming_message_size(bp_rialto::Rialto::max_extrinsic_size()),
|
||||
);
|
||||
pallet_bridge_messages::ensure_able_to_receive_message::<Weights>(
|
||||
bp_rialto::Rialto::max_extrinsic_size(),
|
||||
bp_rialto::Rialto::max_extrinsic_weight(),
|
||||
max_incoming_message_proof_size,
|
||||
messages::target::maximal_incoming_message_dispatch_weight(
|
||||
bp_rialto::Rialto::max_extrinsic_weight(),
|
||||
),
|
||||
);
|
||||
|
||||
let max_incoming_inbound_lane_data_proof_size =
|
||||
bp_messages::InboundLaneData::<()>::encoded_size_hint(
|
||||
bp_rialto::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE,
|
||||
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as _,
|
||||
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX as _,
|
||||
)
|
||||
.unwrap_or(u32::MAX);
|
||||
pallet_bridge_messages::ensure_able_to_receive_confirmation::<Weights>(
|
||||
bp_rialto::Rialto::max_extrinsic_size(),
|
||||
bp_rialto::Rialto::max_extrinsic_weight(),
|
||||
max_incoming_inbound_lane_data_proof_size,
|
||||
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
|
||||
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
|
||||
DbWeight::get(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_bridge_integrity() {
|
||||
assert_complete_bridge_types!(
|
||||
runtime: Runtime,
|
||||
with_bridged_chain_grandpa_instance: MillauGrandpaInstance,
|
||||
with_bridged_chain_messages_instance: WithMillauMessagesInstance,
|
||||
bridge: WithMillauMessageBridge,
|
||||
this_chain: bp_rialto::Rialto,
|
||||
bridged_chain: bp_millau::Millau,
|
||||
this_chain_account_id_converter: bp_rialto::AccountIdConverter
|
||||
);
|
||||
|
||||
assert_complete_bridge_constants::<
|
||||
Runtime,
|
||||
MillauGrandpaInstance,
|
||||
WithMillauMessagesInstance,
|
||||
WithMillauMessageBridge,
|
||||
bp_rialto::Rialto,
|
||||
>(AssertCompleteBridgeConstants {
|
||||
this_chain_constants: AssertChainConstants {
|
||||
block_length: bp_rialto::BlockLength::get(),
|
||||
block_weights: bp_rialto::BlockWeights::get(),
|
||||
},
|
||||
messages_pallet_constants: AssertBridgeMessagesPalletConstants {
|
||||
max_unrewarded_relayers_in_bridged_confirmation_tx:
|
||||
bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
|
||||
max_unconfirmed_messages_in_bridged_confirmation_tx:
|
||||
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
|
||||
bridged_chain_id: bp_runtime::MILLAU_CHAIN_ID,
|
||||
},
|
||||
pallet_names: AssertBridgePalletNames {
|
||||
with_this_chain_messages_pallet_name: bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME,
|
||||
with_bridged_chain_grandpa_pallet_name: bp_millau::WITH_MILLAU_GRANDPA_PALLET_NAME,
|
||||
with_bridged_chain_messages_pallet_name:
|
||||
bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME,
|
||||
},
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
MillauToRialtoConversionRate::key().to_vec(),
|
||||
bp_runtime::storage_parameter_key(
|
||||
bp_rialto::MILLAU_TO_RIALTO_CONVERSION_RATE_PARAMETER_NAME
|
||||
)
|
||||
.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user