Skip to content

Commit

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

* commit changes

* revert unnessary changes and create new beacon fixtures crate

* tests

* Std Feature gating

* update cargo lock

* more tests

* update cargo.lock

* simply test code

---------

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 e151ad1 commit f3cac5e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ impl snowbridge_pallet_outbound_queue::Config for Runtime {
type Channels = EthereumSystem;
}

#[cfg(any(feature = "fast-runtime", feature = "runtime-benchmarks"))]
#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
parameter_types! {
pub const ChainForkVersions: ForkVersions = ForkVersions {
genesis: Fork {
Expand All @@ -611,7 +611,7 @@ parameter_types! {
};
}

#[cfg(all(not(feature = "fast-runtime"), not(feature = "runtime-benchmarks")))]
#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
parameter_types! {
pub const ChainForkVersions: ForkVersions = ForkVersions {
genesis: Fork {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@

#![cfg(test)]

use bp_polkadot_core::Signature;
use bridge_hub_rococo_runtime::{
xcm_config::XcmConfig, MessageQueueServiceWeight, Runtime, RuntimeEvent, SessionKeys,
bridge_to_bulletin_config::OnBridgeHubRococoRefundRococoBulletinMessages,
bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages,
xcm_config::XcmConfig, BridgeRejectObsoleteHeadersAndMessages, Executive,
MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, SignedExtra,
UncheckedExtrinsic,
};
use codec::Decode;
use codec::{Decode, Encode};
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, NotHoldingFees};
use frame_support::parameter_types;
use parachains_common::{AccountId, AuraId, Balance};
use snowbridge_pallet_ethereum_client::WeightInfo;
use sp_core::H160;
use sp_keyring::AccountKeyring::Alice;
use sp_runtime::{
generic::{Era, SignedPayload},
AccountId32,
};

parameter_types! {
pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000;
Expand Down Expand Up @@ -107,3 +116,62 @@ fn max_message_queue_service_weight_is_more_than_beacon_extrinsic_weights() {
max_message_queue_weight.all_gt(force_checkpoint);
max_message_queue_weight.all_gt(submit_checkpoint);
}

#[test]
fn ethereum_client_consensus_extrinsics_work() {
snowbridge_runtime_test_common::ethereum_extrinsic(
collator_session_keys(),
1013,
construct_and_apply_extrinsic,
);
}

#[test]
fn ethereum_to_polkadot_message_extrinsics_work() {
snowbridge_runtime_test_common::ethereum_to_polkadot_message_extrinsics_work(
collator_session_keys(),
1013,
construct_and_apply_extrinsic,
);
}

fn construct_extrinsic(
sender: sp_keyring::AccountKeyring,
call: RuntimeCall,
) -> UncheckedExtrinsic {
let account_id = AccountId32::from(sender.public());
let extra: SignedExtra = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(Era::immortal()),
frame_system::CheckNonce::<Runtime>::from(
frame_system::Pallet::<Runtime>::account(&account_id).nonce,
),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
BridgeRejectObsoleteHeadersAndMessages::default(),
(
OnBridgeHubRococoRefundBridgeHubWestendMessages::default(),
OnBridgeHubRococoRefundRococoBulletinMessages::default(),
),
);
let payload = SignedPayload::new(call.clone(), extra.clone()).unwrap();
let signature = payload.using_encoded(|e| sender.sign(e));
UncheckedExtrinsic::new_signed(
call,
account_id.into(),
Signature::Sr25519(signature.clone()),
extra,
)
}

fn construct_and_apply_extrinsic(
origin: sp_keyring::AccountKeyring,
call: RuntimeCall,
) -> sp_runtime::DispatchOutcome {
let xt = construct_extrinsic(origin, call);
let r = Executive::apply_extrinsic(xt);
r.unwrap()
}
6 changes: 5 additions & 1 deletion cumulus/parachains/runtimes/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use polkadot_parachain_primitives::primitives::{
HeadData, HrmpChannelId, RelayChainBlockNumber, XcmpMessageFormat,
};
use sp_consensus_aura::{SlotDuration, AURA_ENGINE_ID};
use sp_core::Encode;
use sp_core::{Encode, U256};
use sp_runtime::{traits::Header, BuildStorage, Digest, DigestItem};
use xcm::{
latest::{Asset, Location, XcmContext, XcmHash},
Expand Down Expand Up @@ -300,6 +300,10 @@ where
<Runtime as frame_system::Config>::RuntimeOrigin::root()
}

pub fn block_number() -> U256 {
frame_system::Pallet::<Runtime>::block_number().into()
}

pub fn origin_of(
account_id: AccountIdOf<Runtime>,
) -> <Runtime as frame_system::Config>::RuntimeOrigin {
Expand Down

0 comments on commit f3cac5e

Please sign in to comment.