mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 04:51:01 +00:00
6e8795afe6
* rename Event to RuntimeEvent * rename Call * rename in runtimes * small fix * rename Event * small fix & rename RuntimeCall back to Call for now * small fixes * more renaming * a bit more renaming * fmt * small fix * commit * prep for renaming associated types * fix * rename associated Event type * rename to RuntimeEvent * commit * merge conflict fixes & fmt * additional renaming * fix. * fix decl_event * rename in tests * remove warnings * remove accidental rename * . * commit * update .stderr * fix in test * update .stderr * TRYBUILD=overwrite * docs * fmt * small change in docs * rename PalletEvent to Event * rename Call to RuntimeCall * renamed at wrong places :P * rename Call * rename * rename associated type * fix * fix & fmt * commit * frame-support-test * passing tests * update docs * rustdoc fix * update .stderr * wrong code in docs * merge fix * fix in error message * update .stderr * docs & error message * . * merge fix * merge fix * fmt * fmt * merge fix * more fixing * fmt * remove unused * fmt * fix Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
165 lines
4.8 KiB
Rust
165 lines
4.8 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use std::vec;
|
|
|
|
use frame_support::{
|
|
construct_runtime, parameter_types,
|
|
sp_io::TestExternalities,
|
|
traits::{ConstU16, ConstU32, ConstU64, GenesisBuild},
|
|
BasicExternalities,
|
|
};
|
|
use sp_core::H256;
|
|
use sp_runtime::{
|
|
app_crypto::ecdsa::Public,
|
|
impl_opaque_keys,
|
|
testing::Header,
|
|
traits::{BlakeTwo256, ConvertInto, IdentityLookup, OpaqueKeys},
|
|
Perbill,
|
|
};
|
|
|
|
use crate as pallet_beefy;
|
|
|
|
pub use beefy_primitives::{crypto::AuthorityId as BeefyId, ConsensusLog, BEEFY_ENGINE_ID};
|
|
|
|
impl_opaque_keys! {
|
|
pub struct MockSessionKeys {
|
|
pub dummy: pallet_beefy::Pallet<Test>,
|
|
}
|
|
}
|
|
|
|
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
|
type Block = frame_system::mocking::MockBlock<Test>;
|
|
|
|
construct_runtime!(
|
|
pub enum Test where
|
|
Block = Block,
|
|
NodeBlock = Block,
|
|
UncheckedExtrinsic = UncheckedExtrinsic,
|
|
{
|
|
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
|
Beefy: pallet_beefy::{Pallet, Config<T>, Storage},
|
|
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
|
|
}
|
|
);
|
|
|
|
impl frame_system::Config for Test {
|
|
type BaseCallFilter = frame_support::traits::Everything;
|
|
type BlockWeights = ();
|
|
type BlockLength = ();
|
|
type DbWeight = ();
|
|
type Origin = Origin;
|
|
type Index = u64;
|
|
type BlockNumber = u64;
|
|
type Hash = H256;
|
|
type RuntimeCall = RuntimeCall;
|
|
type Hashing = BlakeTwo256;
|
|
type AccountId = u64;
|
|
type Lookup = IdentityLookup<Self::AccountId>;
|
|
type Header = Header;
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type BlockHashCount = ConstU64<250>;
|
|
type Version = ();
|
|
type PalletInfo = PalletInfo;
|
|
type AccountData = ();
|
|
type OnNewAccount = ();
|
|
type OnKilledAccount = ();
|
|
type SystemWeightInfo = ();
|
|
type SS58Prefix = ConstU16<42>;
|
|
type OnSetCode = ();
|
|
type MaxConsumers = ConstU32<16>;
|
|
}
|
|
|
|
impl pallet_beefy::Config for Test {
|
|
type BeefyId = BeefyId;
|
|
type MaxAuthorities = ConstU32<100>;
|
|
type OnNewValidatorSet = ();
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
|
|
}
|
|
|
|
impl pallet_session::Config for Test {
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type ValidatorId = u64;
|
|
type ValidatorIdOf = ConvertInto;
|
|
type ShouldEndSession = pallet_session::PeriodicSessions<ConstU64<1>, ConstU64<0>>;
|
|
type NextSessionRotation = pallet_session::PeriodicSessions<ConstU64<1>, ConstU64<0>>;
|
|
type SessionManager = MockSessionManager;
|
|
type SessionHandler = <MockSessionKeys as OpaqueKeys>::KeyTypeIdProviders;
|
|
type Keys = MockSessionKeys;
|
|
type WeightInfo = ();
|
|
}
|
|
|
|
pub struct MockSessionManager;
|
|
|
|
impl pallet_session::SessionManager<u64> for MockSessionManager {
|
|
fn end_session(_: sp_staking::SessionIndex) {}
|
|
fn start_session(_: sp_staking::SessionIndex) {}
|
|
fn new_session(idx: sp_staking::SessionIndex) -> Option<Vec<u64>> {
|
|
if idx == 0 || idx == 1 {
|
|
Some(vec![1, 2])
|
|
} else if idx == 2 {
|
|
Some(vec![3, 4])
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|
|
|
|
// Note, that we can't use `UintAuthorityId` here. Reason is that the implementation
|
|
// of `to_public_key()` assumes, that a public key is 32 bytes long. This is true for
|
|
// ed25519 and sr25519 but *not* for ecdsa. A compressed ecdsa public key is 33 bytes,
|
|
// with the first one containing information to reconstruct the uncompressed key.
|
|
pub fn mock_beefy_id(id: u8) -> BeefyId {
|
|
let mut buf: [u8; 33] = [id; 33];
|
|
// Set to something valid.
|
|
buf[0] = 0x02;
|
|
let pk = Public::from_raw(buf);
|
|
BeefyId::from(pk)
|
|
}
|
|
|
|
pub fn mock_authorities(vec: Vec<u8>) -> Vec<(u64, BeefyId)> {
|
|
vec.into_iter().map(|id| ((id as u64), mock_beefy_id(id))).collect()
|
|
}
|
|
|
|
pub fn new_test_ext(ids: Vec<u8>) -> TestExternalities {
|
|
new_test_ext_raw_authorities(mock_authorities(ids))
|
|
}
|
|
|
|
pub fn new_test_ext_raw_authorities(authorities: Vec<(u64, BeefyId)>) -> TestExternalities {
|
|
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
|
|
|
let session_keys: Vec<_> = authorities
|
|
.iter()
|
|
.map(|id| (id.0 as u64, id.0 as u64, MockSessionKeys { dummy: id.1.clone() }))
|
|
.collect();
|
|
|
|
BasicExternalities::execute_with_storage(&mut t, || {
|
|
for (ref id, ..) in &session_keys {
|
|
frame_system::Pallet::<Test>::inc_providers(id);
|
|
}
|
|
});
|
|
|
|
pallet_session::GenesisConfig::<Test> { keys: session_keys }
|
|
.assimilate_storage(&mut t)
|
|
.unwrap();
|
|
|
|
t.into()
|
|
}
|