mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Bump Substrate (#871)
* Bump Substrate * Change usage of "Module" to "Pallet" Related Substrate PR: https://github.com/paritytech/substrate/pull/8372 * Add `OnSetCode` config param Related Substrate PR: https://github.com/paritytech/substrate/pull/8496 * Update Aura Slot duration time type Related Substrate PR: https://github.com/paritytech/substrate/pull/8386 * Add `OnSetCode` to mock runtimes * Add support for multiple justifications Related Substrate PR: https://github.com/paritytech/substrate/pull/7640 * Use updated justification type in more places * Make GenesisConfig type non-optional Related Substrate PR: https://github.com/paritytech/substrate/pull/8275 * Update service to use updated telemetry Related Substrate PR: https://github.com/paritytech/substrate/pull/8143 * Appease Clippy
This commit is contained in:
committed by
Bastian Köcher
parent
d9c553374c
commit
c6ae74725b
@@ -19,7 +19,7 @@
|
||||
//! before invoking module calls.
|
||||
|
||||
use super::{
|
||||
Call, Config as CurrencyExchangeConfig, InclusionProofVerifier, Instance, Module as CurrencyExchangeModule,
|
||||
Call, Config as CurrencyExchangeConfig, InclusionProofVerifier, Instance, Pallet as CurrencyExchangePallet,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
@@ -30,8 +30,8 @@ const SEED: u32 = 0;
|
||||
const WORST_TX_SIZE_FACTOR: u32 = 1000;
|
||||
const WORST_PROOF_SIZE_FACTOR: u32 = 1000;
|
||||
|
||||
/// Module we're benchmarking here.
|
||||
pub struct Module<T: Config<I>, I: Instance>(CurrencyExchangeModule<T, I>);
|
||||
/// Pallet we're benchmarking here.
|
||||
pub struct Pallet<T: Config<I>, I: Instance>(CurrencyExchangePallet<T, I>);
|
||||
|
||||
/// Proof benchmarking parameters.
|
||||
pub struct ProofParams<Recipient> {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub trait Config<I = DefaultInstance>: frame_system::Config {
|
||||
}
|
||||
|
||||
decl_error! {
|
||||
pub enum Error for Module<T: Config<I>, I: Instance> {
|
||||
pub enum Error for Pallet<T: Config<I>, I: Instance> {
|
||||
/// Invalid peer blockchain transaction provided.
|
||||
InvalidTransaction,
|
||||
/// Peer transaction has invalid amount.
|
||||
@@ -125,13 +125,13 @@ decl_module! {
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance> as Bridge {
|
||||
trait Store for Pallet<T: Config<I>, I: Instance = DefaultInstance> as Bridge {
|
||||
/// All transfers that have already been claimed.
|
||||
Transfers: map hasher(blake2_128_concat) <T::PeerMaybeLockFundsTransaction as MaybeLockFundsTransaction>::Id => ();
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: Instance> Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> Pallet<T, I> {
|
||||
/// Returns true if currency exchange module is able to import given transaction proof in
|
||||
/// its current state.
|
||||
pub fn filter_transaction_proof(
|
||||
@@ -326,8 +326,8 @@ mod tests {
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
Exchange: pallet_bridge_currency_exchange::{Module},
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Exchange: pallet_bridge_currency_exchange::{Pallet},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +361,7 @@ mod tests {
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
}
|
||||
|
||||
impl Config for TestRuntime {
|
||||
|
||||
@@ -153,7 +153,7 @@ pub trait Config<I = DefaultInstance>: frame_system::Config {
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance> as Dispatch {}
|
||||
trait Store for Pallet<T: Config<I>, I: Instance = DefaultInstance> as Dispatch {}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
@@ -189,7 +189,7 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Pallet<T, I> {
|
||||
type Message =
|
||||
MessagePayload<T::SourceChainAccountId, T::TargetChainAccountPublic, T::TargetChainSignature, T::EncodedCall>;
|
||||
|
||||
@@ -455,8 +455,8 @@ mod tests {
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
Dispatch: call_dispatch::{Module, Call, Event<T>},
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Dispatch: call_dispatch::{Pallet, Call, Event<T>},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,6 +490,7 @@ mod tests {
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
}
|
||||
|
||||
impl Config for TestRuntime {
|
||||
@@ -534,7 +535,7 @@ mod tests {
|
||||
fn prepare_message(
|
||||
origin: CallOrigin<AccountId, TestAccountPublic, TestSignature>,
|
||||
call: Call,
|
||||
) -> <Module<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
) -> <Pallet<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
MessagePayload {
|
||||
spec_version: TEST_SPEC_VERSION,
|
||||
weight: TEST_WEIGHT,
|
||||
@@ -545,20 +546,20 @@ mod tests {
|
||||
|
||||
fn prepare_root_message(
|
||||
call: Call,
|
||||
) -> <Module<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
) -> <Pallet<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
prepare_message(CallOrigin::SourceRoot, call)
|
||||
}
|
||||
|
||||
fn prepare_target_message(
|
||||
call: Call,
|
||||
) -> <Module<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
) -> <Pallet<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
let origin = CallOrigin::TargetAccount(1, TestAccountPublic(1), TestSignature(1));
|
||||
prepare_message(origin, call)
|
||||
}
|
||||
|
||||
fn prepare_source_message(
|
||||
call: Call,
|
||||
) -> <Module<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
) -> <Pallet<TestRuntime> as MessageDispatch<<TestRuntime as Config>::MessageId>>::Message {
|
||||
let origin = CallOrigin::SourceAccount(1);
|
||||
prepare_message(origin, call)
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ pub trait PruningStrategy: Default {
|
||||
/// Every value that is returned from this function, must be greater or equal to the
|
||||
/// previous value. Otherwise it will be ignored (we can't revert pruning).
|
||||
///
|
||||
/// Module may prune both finalized and unfinalized blocks. But it can't give any
|
||||
/// Pallet may prune both finalized and unfinalized blocks. But it can't give any
|
||||
/// guarantees on when it will happen. Example: if some unfinalized block at height N
|
||||
/// has scheduled validators set change, then the module won't prune any blocks with
|
||||
/// number >= N even if strategy allows that.
|
||||
@@ -457,7 +457,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance> as Bridge {
|
||||
trait Store for Pallet<T: Config<I>, I: Instance = DefaultInstance> as Bridge {
|
||||
/// Best known block.
|
||||
BestBlock: (HeaderId, U256);
|
||||
/// Best finalized block.
|
||||
@@ -505,7 +505,7 @@ decl_storage! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: Instance> Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> Pallet<T, I> {
|
||||
/// Returns number and hash of the best block known to the bridge module.
|
||||
/// The caller should only submit `import_header` transaction that makes
|
||||
/// (or leads to making) other header the best one.
|
||||
@@ -542,7 +542,7 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: Instance> frame_support::unsigned::ValidateUnsigned for Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> frame_support::unsigned::ValidateUnsigned for Pallet<T, I> {
|
||||
type Call = Call<T, I>;
|
||||
|
||||
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
||||
|
||||
@@ -44,8 +44,8 @@ frame_support::construct_runtime! {
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
Ethereum: pallet_ethereum::{Module, Call},
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Ethereum: pallet_ethereum::{Pallet, Call},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ impl frame_system::Config for TestRuntime {
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
@@ -53,7 +53,7 @@ use sp_runtime::RuntimeDebug;
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
|
||||
/// Module containing weights for this pallet.
|
||||
/// Pallet containing weights for this pallet.
|
||||
pub mod weights;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
@@ -191,19 +191,19 @@ pub mod pallet {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
/// Change `ModuleOwner`.
|
||||
/// Change `PalletOwner`.
|
||||
///
|
||||
/// May only be called either by root, or by `ModuleOwner`.
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_owner(origin: OriginFor<T>, new_owner: Option<T::AccountId>) -> DispatchResultWithPostInfo {
|
||||
ensure_owner_or_root::<T, I>(origin)?;
|
||||
match new_owner {
|
||||
Some(new_owner) => {
|
||||
ModuleOwner::<T, I>::put(&new_owner);
|
||||
PalletOwner::<T, I>::put(&new_owner);
|
||||
log::info!(target: "runtime::bridge-grandpa", "Setting pallet Owner to: {:?}", new_owner);
|
||||
}
|
||||
None => {
|
||||
ModuleOwner::<T, I>::kill();
|
||||
PalletOwner::<T, I>::kill();
|
||||
log::info!(target: "runtime::bridge-grandpa", "Removed Owner of pallet.");
|
||||
}
|
||||
}
|
||||
@@ -213,7 +213,7 @@ pub mod pallet {
|
||||
|
||||
/// Halt or resume all pallet operations.
|
||||
///
|
||||
/// May only be called either by root, or by `ModuleOwner`.
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||
pub fn set_operational(origin: OriginFor<T>, operational: bool) -> DispatchResultWithPostInfo {
|
||||
ensure_owner_or_root::<T, I>(origin)?;
|
||||
@@ -265,7 +265,7 @@ pub mod pallet {
|
||||
/// runtime methods may still be used to do that (i.e. democracy::referendum to update halt
|
||||
/// flag directly or call the `halt_operations`).
|
||||
#[pallet::storage]
|
||||
pub(super) type ModuleOwner<T: Config<I>, I: 'static = ()> = StorageValue<_, T::AccountId, OptionQuery>;
|
||||
pub(super) type PalletOwner<T: Config<I>, I: 'static = ()> = StorageValue<_, T::AccountId, OptionQuery>;
|
||||
|
||||
/// If true, all pallet transactions are failed immediately.
|
||||
#[pallet::storage]
|
||||
@@ -293,7 +293,7 @@ pub mod pallet {
|
||||
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
|
||||
fn build(&self) {
|
||||
if let Some(ref owner) = self.owner {
|
||||
<ModuleOwner<T, I>>::put(owner);
|
||||
<PalletOwner<T, I>>::put(owner);
|
||||
}
|
||||
|
||||
if let Some(init_data) = self.init_data.clone() {
|
||||
@@ -426,11 +426,11 @@ pub mod pallet {
|
||||
<IsHalted<T, I>>::put(is_halted);
|
||||
}
|
||||
|
||||
/// Ensure that the origin is either root, or `ModuleOwner`.
|
||||
/// Ensure that the origin is either root, or `PalletOwner`.
|
||||
fn ensure_owner_or_root<T: Config<I>, I: 'static>(origin: T::Origin) -> Result<(), BadOrigin> {
|
||||
match origin.into() {
|
||||
Ok(RawOrigin::Root) => Ok(()),
|
||||
Ok(RawOrigin::Signed(ref signer)) if Some(signer) == <ModuleOwner<T, I>>::get().as_ref() => Ok(()),
|
||||
Ok(RawOrigin::Signed(ref signer)) if Some(signer) == <PalletOwner<T, I>>::get().as_ref() => Ok(()),
|
||||
_ => Err(BadOrigin),
|
||||
}
|
||||
}
|
||||
@@ -574,22 +574,22 @@ mod tests {
|
||||
is_halted: false,
|
||||
};
|
||||
|
||||
Module::<TestRuntime>::initialize(origin, init_data.clone()).map(|_| init_data)
|
||||
Pallet::<TestRuntime>::initialize(origin, init_data.clone()).map(|_| init_data)
|
||||
}
|
||||
|
||||
fn submit_finality_proof(header: u8) -> frame_support::dispatch::DispatchResultWithPostInfo {
|
||||
let header = test_header(header.into());
|
||||
let justification = make_default_justification(&header);
|
||||
|
||||
Module::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification)
|
||||
Pallet::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification)
|
||||
}
|
||||
|
||||
fn next_block() {
|
||||
use frame_support::traits::OnInitialize;
|
||||
|
||||
let current_number = frame_system::Module::<TestRuntime>::block_number();
|
||||
frame_system::Module::<TestRuntime>::set_block_number(current_number + 1);
|
||||
let _ = Module::<TestRuntime>::on_initialize(current_number);
|
||||
let current_number = frame_system::Pallet::<TestRuntime>::block_number();
|
||||
frame_system::Pallet::<TestRuntime>::set_block_number(current_number + 1);
|
||||
let _ = Pallet::<TestRuntime>::on_initialize(current_number);
|
||||
}
|
||||
|
||||
fn change_log(delay: u64) -> Digest<TestHash> {
|
||||
@@ -625,7 +625,7 @@ mod tests {
|
||||
|
||||
// Reset storage so we can initialize the pallet again
|
||||
BestFinalized::<TestRuntime>::kill();
|
||||
ModuleOwner::<TestRuntime>::put(2);
|
||||
PalletOwner::<TestRuntime>::put(2);
|
||||
assert_ok!(init_with_origin(Origin::signed(2)));
|
||||
})
|
||||
}
|
||||
@@ -637,7 +637,7 @@ mod tests {
|
||||
BestFinalized::<TestRuntime>::get(),
|
||||
BridgedBlockHash::<TestRuntime, ()>::default()
|
||||
);
|
||||
assert_eq!(Module::<TestRuntime>::best_finalized(), test_header(0));
|
||||
assert_eq!(Pallet::<TestRuntime>::best_finalized(), test_header(0));
|
||||
|
||||
let init_data = init_with_origin(Origin::root()).unwrap();
|
||||
|
||||
@@ -665,56 +665,56 @@ mod tests {
|
||||
#[test]
|
||||
fn pallet_owner_may_change_owner() {
|
||||
run_test(|| {
|
||||
ModuleOwner::<TestRuntime>::put(2);
|
||||
PalletOwner::<TestRuntime>::put(2);
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(2), false),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(2), false),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(2), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(2), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pallet_may_be_halted_by_root() {
|
||||
run_test(|| {
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pallet_may_be_halted_by_owner() {
|
||||
run_test(|| {
|
||||
ModuleOwner::<TestRuntime>::put(2);
|
||||
PalletOwner::<TestRuntime>::put(2);
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), true));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), true));
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), false),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), false),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
});
|
||||
@@ -755,7 +755,7 @@ mod tests {
|
||||
let justification = make_justification_for_header(params);
|
||||
|
||||
assert_err!(
|
||||
Module::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification,),
|
||||
Pallet::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification,),
|
||||
<Error<TestRuntime>>::InvalidJustification
|
||||
);
|
||||
})
|
||||
@@ -771,7 +771,7 @@ mod tests {
|
||||
justification.round = 42;
|
||||
|
||||
assert_err!(
|
||||
Module::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification,),
|
||||
Pallet::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification,),
|
||||
<Error<TestRuntime>>::InvalidJustification
|
||||
);
|
||||
})
|
||||
@@ -790,13 +790,13 @@ mod tests {
|
||||
is_halted: false,
|
||||
};
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::initialize(Origin::root(), init_data));
|
||||
assert_ok!(Pallet::<TestRuntime>::initialize(Origin::root(), init_data));
|
||||
|
||||
let header = test_header(1);
|
||||
let justification = make_default_justification(&header);
|
||||
|
||||
assert_err!(
|
||||
Module::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification,),
|
||||
Pallet::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification,),
|
||||
<Error<TestRuntime>>::InvalidAuthoritySet
|
||||
);
|
||||
})
|
||||
@@ -830,7 +830,7 @@ mod tests {
|
||||
let justification = make_default_justification(&header);
|
||||
|
||||
// Let's import our test header
|
||||
assert_ok!(Module::<TestRuntime>::submit_finality_proof(
|
||||
assert_ok!(Pallet::<TestRuntime>::submit_finality_proof(
|
||||
Origin::signed(1),
|
||||
header.clone(),
|
||||
justification
|
||||
@@ -863,7 +863,7 @@ mod tests {
|
||||
|
||||
// Should not be allowed to import this header
|
||||
assert_err!(
|
||||
Module::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification),
|
||||
Pallet::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification),
|
||||
<Error<TestRuntime>>::UnsupportedScheduledChange
|
||||
);
|
||||
})
|
||||
@@ -884,7 +884,7 @@ mod tests {
|
||||
|
||||
// Should not be allowed to import this header
|
||||
assert_err!(
|
||||
Module::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification),
|
||||
Pallet::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, justification),
|
||||
<Error<TestRuntime>>::UnsupportedScheduledChange
|
||||
);
|
||||
})
|
||||
@@ -894,7 +894,7 @@ mod tests {
|
||||
fn parse_finalized_storage_proof_rejects_proof_on_unknown_header() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::parse_finalized_storage_proof(
|
||||
Pallet::<TestRuntime>::parse_finalized_storage_proof(
|
||||
Default::default(),
|
||||
sp_trie::StorageProof::new(vec![]),
|
||||
|_| (),
|
||||
@@ -917,7 +917,7 @@ mod tests {
|
||||
<ImportedHeaders<TestRuntime>>::insert(hash, header);
|
||||
|
||||
assert_ok!(
|
||||
Module::<TestRuntime>::parse_finalized_storage_proof(hash, storage_proof, |_| (),),
|
||||
Pallet::<TestRuntime>::parse_finalized_storage_proof(hash, storage_proof, |_| (),),
|
||||
(),
|
||||
);
|
||||
});
|
||||
@@ -942,7 +942,7 @@ mod tests {
|
||||
let mut invalid_justification = make_default_justification(&header);
|
||||
invalid_justification.round = 42;
|
||||
|
||||
Module::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, invalid_justification)
|
||||
Pallet::<TestRuntime>::submit_finality_proof(Origin::signed(1), header, invalid_justification)
|
||||
};
|
||||
|
||||
initialize_substrate_bridge();
|
||||
|
||||
@@ -41,8 +41,8 @@ construct_runtime! {
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
Grandpa: grandpa::{Module},
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Grandpa: grandpa::{Pallet},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ impl frame_system::Config for TestRuntime {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Module that provides RPC methods specific to messages pallet.
|
||||
//! Pallet that provides RPC methods specific to messages pallet.
|
||||
|
||||
use crate::error::{Error, FutureResult};
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ pub const MESSAGE_FEE: u64 = 10_000_000_000;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
/// Module we're benchmarking here.
|
||||
pub struct Module<T: Config<I>, I: crate::Instance>(crate::Module<T, I>);
|
||||
/// Pallet we're benchmarking here.
|
||||
pub struct Pallet<T: Config<I>, I: crate::Instance>(crate::Pallet<T, I>);
|
||||
|
||||
/// Proof size requirements.
|
||||
pub enum ProofSize {
|
||||
@@ -142,7 +142,7 @@ benchmarks_instance! {
|
||||
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
T::MaxMessagesToPruneAtOnce::get() + 1,
|
||||
);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ benchmarks_instance! {
|
||||
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
T::MaxMessagesToPruneAtOnce::get() + 1,
|
||||
);
|
||||
}
|
||||
@@ -216,7 +216,7 @@ benchmarks_instance! {
|
||||
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
T::MaxMessagesToPruneAtOnce::get() + 1,
|
||||
);
|
||||
}
|
||||
@@ -261,7 +261,7 @@ benchmarks_instance! {
|
||||
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
21,
|
||||
);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ benchmarks_instance! {
|
||||
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 2, dispatch_weight)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
22,
|
||||
);
|
||||
}
|
||||
@@ -327,11 +327,11 @@ benchmarks_instance! {
|
||||
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
21,
|
||||
);
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_confirmed_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_confirmed_nonce(T::bench_lane_id()),
|
||||
20,
|
||||
);
|
||||
}
|
||||
@@ -361,7 +361,7 @@ benchmarks_instance! {
|
||||
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
21,
|
||||
);
|
||||
}
|
||||
@@ -393,7 +393,7 @@ benchmarks_instance! {
|
||||
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
21,
|
||||
);
|
||||
}
|
||||
@@ -404,7 +404,7 @@ benchmarks_instance! {
|
||||
//
|
||||
// This is base benchmark for all other confirmations delivery benchmarks.
|
||||
receive_delivery_proof_for_single_message {
|
||||
let relayers_fund_id = crate::Module::<T, I>::relayer_fund_account_id();
|
||||
let relayers_fund_id = crate::Pallet::<T, I>::relayer_fund_account_id();
|
||||
let relayer_id: T::AccountId = account("relayer", 0, SEED);
|
||||
let relayer_balance = T::account_balance(&relayer_id);
|
||||
T::endow_account(&relayers_fund_id);
|
||||
@@ -441,7 +441,7 @@ benchmarks_instance! {
|
||||
// as `weight(receive_delivery_proof_for_two_messages_by_single_relayer)
|
||||
// - weight(receive_delivery_proof_for_single_message)`.
|
||||
receive_delivery_proof_for_two_messages_by_single_relayer {
|
||||
let relayers_fund_id = crate::Module::<T, I>::relayer_fund_account_id();
|
||||
let relayers_fund_id = crate::Pallet::<T, I>::relayer_fund_account_id();
|
||||
let relayer_id: T::AccountId = account("relayer", 0, SEED);
|
||||
let relayer_balance = T::account_balance(&relayer_id);
|
||||
T::endow_account(&relayers_fund_id);
|
||||
@@ -476,7 +476,7 @@ benchmarks_instance! {
|
||||
// as `weight(receive_delivery_proof_for_two_messages_by_two_relayers)
|
||||
// - weight(receive_delivery_proof_for_two_messages_by_single_relayer)`.
|
||||
receive_delivery_proof_for_two_messages_by_two_relayers {
|
||||
let relayers_fund_id = crate::Module::<T, I>::relayer_fund_account_id();
|
||||
let relayers_fund_id = crate::Pallet::<T, I>::relayer_fund_account_id();
|
||||
let relayer1_id: T::AccountId = account("relayer1", 1, SEED);
|
||||
let relayer1_balance = T::account_balance(&relayer1_id);
|
||||
let relayer2_id: T::AccountId = account("relayer2", 2, SEED);
|
||||
@@ -540,7 +540,7 @@ benchmarks_instance! {
|
||||
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
|
||||
T::MaxMessagesToPruneAtOnce::get() + 1,
|
||||
);
|
||||
}
|
||||
@@ -579,7 +579,7 @@ benchmarks_instance! {
|
||||
)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
20 + i as MessageNonce,
|
||||
);
|
||||
}
|
||||
@@ -616,7 +616,7 @@ benchmarks_instance! {
|
||||
)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
21,
|
||||
);
|
||||
}
|
||||
@@ -653,7 +653,7 @@ benchmarks_instance! {
|
||||
)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
21,
|
||||
);
|
||||
}
|
||||
@@ -696,11 +696,11 @@ benchmarks_instance! {
|
||||
)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
|
||||
20 + i as MessageNonce,
|
||||
);
|
||||
assert_eq!(
|
||||
crate::Module::<T, I>::inbound_latest_confirmed_nonce(T::bench_lane_id()),
|
||||
crate::Pallet::<T, I>::inbound_latest_confirmed_nonce(T::bench_lane_id()),
|
||||
20,
|
||||
);
|
||||
}
|
||||
@@ -713,7 +713,7 @@ benchmarks_instance! {
|
||||
.try_into()
|
||||
.expect("Value of MaxUnrewardedRelayerEntriesAtInboundLane is too large");
|
||||
|
||||
let relayers_fund_id = crate::Module::<T, I>::relayer_fund_account_id();
|
||||
let relayers_fund_id = crate::Pallet::<T, I>::relayer_fund_account_id();
|
||||
let relayer_id: T::AccountId = account("relayer", 0, SEED);
|
||||
let relayer_balance = T::account_balance(&relayer_id);
|
||||
T::endow_account(&relayers_fund_id);
|
||||
@@ -749,7 +749,7 @@ benchmarks_instance! {
|
||||
.try_into()
|
||||
.expect("Value of MaxUnconfirmedMessagesAtInboundLane is too large ");
|
||||
|
||||
let relayers_fund_id = crate::Module::<T, I>::relayer_fund_account_id();
|
||||
let relayers_fund_id = crate::Pallet::<T, I>::relayer_fund_account_id();
|
||||
let confirmation_relayer_id = account("relayer", 0, SEED);
|
||||
let relayers: BTreeMap<T::AccountId, T::OutboundMessageFee> = (1..=i)
|
||||
.map(|j| {
|
||||
|
||||
@@ -59,7 +59,7 @@ where
|
||||
|
||||
fn initialize(relayer_fund_account: &T::AccountId) -> usize {
|
||||
assert!(
|
||||
frame_system::Module::<T>::account_exists(relayer_fund_account),
|
||||
frame_system::Pallet::<T>::account_exists(relayer_fund_account),
|
||||
"The relayer fund account ({:?}) must exist for the message lanes pallet to work correctly.",
|
||||
relayer_fund_account,
|
||||
);
|
||||
@@ -189,7 +189,7 @@ mod tests {
|
||||
use crate::mock::{run_test, AccountId as TestAccountId, Balance as TestBalance, TestRuntime};
|
||||
use bp_messages::source_chain::RelayerRewards;
|
||||
|
||||
type Balances = pallet_balances::Module<TestRuntime>;
|
||||
type Balances = pallet_balances::Pallet<TestRuntime>;
|
||||
|
||||
const RELAYER_1: TestAccountId = 1;
|
||||
const RELAYER_2: TestAccountId = 2;
|
||||
|
||||
@@ -161,7 +161,7 @@ type MessagesDeliveryProofOf<T, I> = <<T as Config<I>>::TargetHeaderChain as Tar
|
||||
>>::MessagesDeliveryProof;
|
||||
|
||||
decl_error! {
|
||||
pub enum Error for Module<T: Config<I>, I: Instance> {
|
||||
pub enum Error for Pallet<T: Config<I>, I: Instance> {
|
||||
/// All pallet operations are halted.
|
||||
Halted,
|
||||
/// Message has been treated as invalid by chain verifier.
|
||||
@@ -188,14 +188,14 @@ decl_error! {
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance> as BridgeMessages {
|
||||
trait Store for Pallet<T: Config<I>, I: Instance = DefaultInstance> as BridgeMessages {
|
||||
/// Optional pallet owner.
|
||||
///
|
||||
/// Pallet owner has a right to halt all pallet operations and then resume it. If it is
|
||||
/// `None`, then there are no direct ways to halt/resume pallet operations, but other
|
||||
/// runtime methods may still be used to do that (i.e. democracy::referendum to update halt
|
||||
/// flag directly or call the `halt_operations`).
|
||||
pub ModuleOwner get(fn module_owner): Option<T::AccountId>;
|
||||
pub PalletOwner get(fn module_owner): Option<T::AccountId>;
|
||||
/// If true, all pallet transactions are failed immediately.
|
||||
pub IsHalted get(fn is_halted) config(): bool;
|
||||
/// Map of lane id => inbound lane data.
|
||||
@@ -210,7 +210,7 @@ decl_storage! {
|
||||
config(owner): Option<T::AccountId>;
|
||||
build(|config| {
|
||||
if let Some(ref owner) = config.owner {
|
||||
<ModuleOwner<T, I>>::put(owner);
|
||||
<PalletOwner<T, I>>::put(owner);
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -246,19 +246,19 @@ decl_module! {
|
||||
T::DbWeight::get().reads(reads as u64)
|
||||
}
|
||||
|
||||
/// Change `ModuleOwner`.
|
||||
/// Change `PalletOwner`.
|
||||
///
|
||||
/// May only be called either by root, or by `ModuleOwner`.
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[weight = (T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational)]
|
||||
pub fn set_owner(origin, new_owner: Option<T::AccountId>) {
|
||||
ensure_owner_or_root::<T, I>(origin)?;
|
||||
match new_owner {
|
||||
Some(new_owner) => {
|
||||
ModuleOwner::<T, I>::put(&new_owner);
|
||||
PalletOwner::<T, I>::put(&new_owner);
|
||||
log::info!(target: "runtime::bridge-messages", "Setting pallet Owner to: {:?}", new_owner);
|
||||
},
|
||||
None => {
|
||||
ModuleOwner::<T, I>::kill();
|
||||
PalletOwner::<T, I>::kill();
|
||||
log::info!(target: "runtime::bridge-messages", "Removed Owner of pallet.");
|
||||
},
|
||||
}
|
||||
@@ -266,7 +266,7 @@ decl_module! {
|
||||
|
||||
/// Halt or resume all pallet operations.
|
||||
///
|
||||
/// May only be called either by root, or by `ModuleOwner`.
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
#[weight = (T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational)]
|
||||
pub fn set_operational(origin, operational: bool) {
|
||||
ensure_owner_or_root::<T, I>(origin)?;
|
||||
@@ -281,7 +281,7 @@ decl_module! {
|
||||
|
||||
/// Update pallet parameter.
|
||||
///
|
||||
/// May only be called either by root, or by `ModuleOwner`.
|
||||
/// May only be called either by root, or by `PalletOwner`.
|
||||
///
|
||||
/// The weight is: single read for permissions check + 2 writes for parameter value and event.
|
||||
#[weight = (T::DbWeight::get().reads_writes(1, 2), DispatchClass::Operational)]
|
||||
@@ -602,7 +602,7 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: Instance> Module<T, I> {
|
||||
impl<T: Config<I>, I: Instance> Pallet<T, I> {
|
||||
/// Get payload of given outbound message.
|
||||
pub fn outbound_message_payload(lane: LaneId, nonce: MessageNonce) -> Option<MessagePayload> {
|
||||
OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, nonce }).map(|message_data| message_data.payload)
|
||||
@@ -686,11 +686,11 @@ pub mod storage_keys {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that the origin is either root, or `ModuleOwner`.
|
||||
/// Ensure that the origin is either root, or `PalletOwner`.
|
||||
fn ensure_owner_or_root<T: Config<I>, I: Instance>(origin: T::Origin) -> Result<(), BadOrigin> {
|
||||
match origin.into() {
|
||||
Ok(RawOrigin::Root) => Ok(()),
|
||||
Ok(RawOrigin::Signed(ref signer)) if Some(signer) == Module::<T, I>::module_owner().as_ref() => Ok(()),
|
||||
Ok(RawOrigin::Signed(ref signer)) if Some(signer) == Pallet::<T, I>::module_owner().as_ref() => Ok(()),
|
||||
_ => Err(BadOrigin),
|
||||
}
|
||||
}
|
||||
@@ -854,7 +854,7 @@ mod tests {
|
||||
};
|
||||
use bp_messages::UnrewardedRelayersState;
|
||||
use frame_support::{assert_noop, assert_ok};
|
||||
use frame_system::{EventRecord, Module as System, Phase};
|
||||
use frame_system::{EventRecord, Pallet as System, Phase};
|
||||
use hex_literal::hex;
|
||||
use sp_runtime::DispatchError;
|
||||
|
||||
@@ -866,7 +866,7 @@ mod tests {
|
||||
fn send_regular_message() {
|
||||
get_ready_for_events();
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::send_message(
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
@@ -891,7 +891,7 @@ mod tests {
|
||||
System::<TestRuntime>::set_block_number(1);
|
||||
System::<TestRuntime>::reset_events();
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
@@ -916,56 +916,56 @@ mod tests {
|
||||
#[test]
|
||||
fn pallet_owner_may_change_owner() {
|
||||
run_test(|| {
|
||||
ModuleOwner::<TestRuntime>::put(2);
|
||||
PalletOwner::<TestRuntime>::put(2);
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(2), false),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(2), false),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(2), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(2), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pallet_may_be_halted_by_root() {
|
||||
run_test(|| {
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), true));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pallet_may_be_halted_by_owner() {
|
||||
run_test(|| {
|
||||
ModuleOwner::<TestRuntime>::put(2);
|
||||
PalletOwner::<TestRuntime>::put(2);
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), true));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), true));
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), false),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), false),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
});
|
||||
@@ -977,7 +977,7 @@ mod tests {
|
||||
get_ready_for_events();
|
||||
|
||||
let parameter = TestMessagesParameter::TokenConversionRate(10.into());
|
||||
assert_ok!(Module::<TestRuntime>::update_pallet_parameter(
|
||||
assert_ok!(Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::root(),
|
||||
parameter.clone(),
|
||||
));
|
||||
@@ -997,11 +997,11 @@ mod tests {
|
||||
#[test]
|
||||
fn pallet_parameter_may_be_updated_by_owner() {
|
||||
run_test(|| {
|
||||
ModuleOwner::<TestRuntime>::put(2);
|
||||
PalletOwner::<TestRuntime>::put(2);
|
||||
get_ready_for_events();
|
||||
|
||||
let parameter = TestMessagesParameter::TokenConversionRate(10.into());
|
||||
assert_ok!(Module::<TestRuntime>::update_pallet_parameter(
|
||||
assert_ok!(Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::signed(2),
|
||||
parameter.clone(),
|
||||
));
|
||||
@@ -1022,17 +1022,17 @@ mod tests {
|
||||
fn pallet_parameter_cant_be_updated_by_arbitrary_submitter() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::update_pallet_parameter(
|
||||
Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::signed(2),
|
||||
TestMessagesParameter::TokenConversionRate(10.into()),
|
||||
),
|
||||
DispatchError::BadOrigin,
|
||||
);
|
||||
|
||||
ModuleOwner::<TestRuntime>::put(2);
|
||||
PalletOwner::<TestRuntime>::put(2);
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::update_pallet_parameter(
|
||||
Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::signed(1),
|
||||
TestMessagesParameter::TokenConversionRate(10.into()),
|
||||
),
|
||||
@@ -1075,7 +1075,7 @@ mod tests {
|
||||
IsHalted::<DefaultInstance>::put(true);
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::send_message(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
@@ -1085,7 +1085,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::receive_messages_proof(
|
||||
Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(2, REGULAR_PAYLOAD)]).into(),
|
||||
@@ -1096,7 +1096,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
@@ -1124,7 +1124,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
// messages with this payload are rejected by target chain verifier
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::send_message(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
PAYLOAD_REJECTED_BY_TARGET_CHAIN,
|
||||
@@ -1140,7 +1140,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
// messages with zero fee are rejected by lane verifier
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::send_message(Origin::signed(1), TEST_LANE_ID, REGULAR_PAYLOAD, 0),
|
||||
Pallet::<TestRuntime>::send_message(Origin::signed(1), TEST_LANE_ID, REGULAR_PAYLOAD, 0),
|
||||
Error::<TestRuntime, DefaultInstance>::MessageRejectedByLaneVerifier,
|
||||
);
|
||||
});
|
||||
@@ -1151,7 +1151,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
TestMessageDeliveryAndDispatchPayment::reject_payments();
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::send_message(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
@@ -1165,7 +1165,7 @@ mod tests {
|
||||
#[test]
|
||||
fn receive_messages_proof_works() {
|
||||
run_test(|| {
|
||||
assert_ok!(Module::<TestRuntime>::receive_messages_proof(
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
|
||||
@@ -1191,7 +1191,7 @@ mod tests {
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
Module::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
|
||||
Pallet::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
|
||||
UnrewardedRelayersState {
|
||||
unrewarded_relayer_entries: 2,
|
||||
messages_in_oldest_entry: 1,
|
||||
@@ -1206,7 +1206,7 @@ mod tests {
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
assert_ok!(Module::<TestRuntime>::receive_messages_proof(
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
message_proof,
|
||||
@@ -1224,7 +1224,7 @@ mod tests {
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
Module::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
|
||||
Pallet::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
|
||||
UnrewardedRelayersState {
|
||||
unrewarded_relayer_entries: 2,
|
||||
messages_in_oldest_entry: 1,
|
||||
@@ -1238,7 +1238,7 @@ mod tests {
|
||||
fn receive_messages_proof_rejects_invalid_dispatch_weight() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::receive_messages_proof(
|
||||
Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
|
||||
@@ -1254,7 +1254,7 @@ mod tests {
|
||||
fn receive_messages_proof_rejects_invalid_proof() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Pallet::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Err(()).into(),
|
||||
@@ -1270,7 +1270,7 @@ mod tests {
|
||||
fn receive_messages_proof_rejects_proof_with_too_many_messages() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Pallet::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
|
||||
@@ -1298,13 +1298,13 @@ mod tests {
|
||||
#[test]
|
||||
fn receive_messages_delivery_proof_rewards_relayers() {
|
||||
run_test(|| {
|
||||
assert_ok!(Module::<TestRuntime>::send_message(
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
1000,
|
||||
));
|
||||
assert_ok!(Module::<TestRuntime>::send_message(
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
@@ -1312,7 +1312,7 @@ mod tests {
|
||||
));
|
||||
|
||||
// this reports delivery of message 1 => reward is paid to TEST_RELAYER_A
|
||||
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
@@ -1337,7 +1337,7 @@ mod tests {
|
||||
));
|
||||
|
||||
// this reports delivery of both message 1 and message 2 => reward is paid only to TEST_RELAYER_B
|
||||
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
@@ -1369,7 +1369,7 @@ mod tests {
|
||||
fn receive_messages_delivery_proof_rejects_invalid_proof() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
TestMessagesDeliveryProof(Err(())),
|
||||
Default::default(),
|
||||
@@ -1384,7 +1384,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
// when number of relayers entires is invalid
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
@@ -1406,7 +1406,7 @@ mod tests {
|
||||
|
||||
// when number of messages is invalid
|
||||
assert_noop!(
|
||||
Module::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
@@ -1434,7 +1434,7 @@ mod tests {
|
||||
let mut invalid_message = message(1, REGULAR_PAYLOAD);
|
||||
invalid_message.data.payload = Vec::new();
|
||||
|
||||
assert_ok!(Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
assert_ok!(Pallet::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![invalid_message]).into(),
|
||||
@@ -1455,7 +1455,7 @@ mod tests {
|
||||
let mut invalid_message = message(2, REGULAR_PAYLOAD);
|
||||
invalid_message.data.payload = Vec::new();
|
||||
|
||||
assert_ok!(Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
assert_ok!(Pallet::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![
|
||||
@@ -1522,7 +1522,7 @@ mod tests {
|
||||
let message3 = message(2, TestPayload(0, Weight::MAX / 2));
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Pallet::<TestRuntime, DefaultInstance>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
// this may cause overflow if source chain storage is invalid
|
||||
@@ -1542,7 +1542,7 @@ mod tests {
|
||||
receive_messages_delivery_proof();
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime, DefaultInstance>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 100,),
|
||||
Pallet::<TestRuntime, DefaultInstance>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 100,),
|
||||
Error::<TestRuntime, DefaultInstance>::MessageIsAlreadyDelivered,
|
||||
);
|
||||
});
|
||||
@@ -1552,7 +1552,7 @@ mod tests {
|
||||
fn increase_message_fee_fails_if_message_is_not_yet_sent() {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Module::<TestRuntime, DefaultInstance>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 100,),
|
||||
Pallet::<TestRuntime, DefaultInstance>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 100,),
|
||||
Error::<TestRuntime, DefaultInstance>::MessageIsNotYetSent,
|
||||
);
|
||||
});
|
||||
@@ -1566,7 +1566,7 @@ mod tests {
|
||||
TestMessageDeliveryAndDispatchPayment::reject_payments();
|
||||
|
||||
assert_noop!(
|
||||
Module::<TestRuntime, DefaultInstance>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 100,),
|
||||
Pallet::<TestRuntime, DefaultInstance>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 100,),
|
||||
Error::<TestRuntime, DefaultInstance>::FailedToWithdrawMessageFee,
|
||||
);
|
||||
});
|
||||
@@ -1577,7 +1577,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
send_regular_message();
|
||||
|
||||
assert_ok!(Module::<TestRuntime, DefaultInstance>::increase_message_fee(
|
||||
assert_ok!(Pallet::<TestRuntime, DefaultInstance>::increase_message_fee(
|
||||
Origin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
|
||||
@@ -64,9 +64,9 @@ frame_support::construct_runtime! {
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Module, Call, Event<T>},
|
||||
Messages: pallet_bridge_messages::{Module, Call, Event<T>},
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Event<T>},
|
||||
Messages: pallet_bridge_messages::{Pallet, Call, Event<T>},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ impl frame_system::Config for TestRuntime {
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -112,7 +113,7 @@ impl pallet_balances::Config for TestRuntime {
|
||||
type DustRemoval = ();
|
||||
type Event = Event;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = frame_system::Module<TestRuntime>;
|
||||
type AccountStore = frame_system::Pallet<TestRuntime>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,13 @@ decl_module! {
|
||||
}
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Config> as ShiftSessionManager {
|
||||
trait Store for Pallet<T: Config> as ShiftSessionManager {
|
||||
/// Validators of first two sessions.
|
||||
InitialValidators: Option<Vec<T::ValidatorId>>;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Module<T> {
|
||||
impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Pallet<T> {
|
||||
fn end_session(_: sp_staking::SessionIndex) {}
|
||||
fn start_session(_: sp_staking::SessionIndex) {}
|
||||
fn new_session(session_index: sp_staking::SessionIndex) -> Option<Vec<T::ValidatorId>> {
|
||||
@@ -52,7 +52,7 @@ impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Module<T> {
|
||||
// then for every session we select (deterministically) 2/3 of these initial
|
||||
// validators to serve validators of new session
|
||||
let available_validators = InitialValidators::<T>::get().unwrap_or_else(|| {
|
||||
let validators = <pallet_session::Module<T>>::validators();
|
||||
let validators = <pallet_session::Pallet<T>>::validators();
|
||||
InitialValidators::<T>::put(validators.clone());
|
||||
validators
|
||||
});
|
||||
@@ -61,7 +61,7 @@ impl<T: Config> pallet_session::SessionManager<T::ValidatorId> for Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Module<T> {
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Select validators for session.
|
||||
fn select_validators(
|
||||
session_index: sp_staking::SessionIndex,
|
||||
@@ -110,8 +110,8 @@ mod tests {
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
Session: pallet_session::{Module},
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Session: pallet_session::{Pallet},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,7 @@ mod tests {
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -193,7 +194,7 @@ mod tests {
|
||||
|
||||
BasicExternalities::execute_with_storage(&mut t, || {
|
||||
for (ref k, ..) in &keys {
|
||||
frame_system::Module::<TestRuntime>::inc_providers(k);
|
||||
frame_system::Pallet::<TestRuntime>::inc_providers(k);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -209,19 +210,19 @@ mod tests {
|
||||
let all_accs = vec![1, 2, 3, 4, 5];
|
||||
|
||||
// at least 1 validator is selected
|
||||
assert_eq!(Module::<TestRuntime>::select_validators(0, &[1]), vec![1],);
|
||||
assert_eq!(Pallet::<TestRuntime>::select_validators(0, &[1]), vec![1],);
|
||||
|
||||
// at session#0, shift is also 0
|
||||
assert_eq!(Module::<TestRuntime>::select_validators(0, &all_accs), vec![1, 2, 3],);
|
||||
assert_eq!(Pallet::<TestRuntime>::select_validators(0, &all_accs), vec![1, 2, 3],);
|
||||
|
||||
// at session#1, shift is also 1
|
||||
assert_eq!(Module::<TestRuntime>::select_validators(1, &all_accs), vec![2, 3, 4],);
|
||||
assert_eq!(Pallet::<TestRuntime>::select_validators(1, &all_accs), vec![2, 3, 4],);
|
||||
|
||||
// at session#3, we're wrapping
|
||||
assert_eq!(Module::<TestRuntime>::select_validators(3, &all_accs), vec![4, 5, 1],);
|
||||
assert_eq!(Pallet::<TestRuntime>::select_validators(3, &all_accs), vec![4, 5, 1],);
|
||||
|
||||
// at session#5, we're starting from the beginning again
|
||||
assert_eq!(Module::<TestRuntime>::select_validators(5, &all_accs), vec![1, 2, 3],);
|
||||
assert_eq!(Pallet::<TestRuntime>::select_validators(5, &all_accs), vec![1, 2, 3],);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user