mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Use construct_runtime in tests (#8059)
* impl some more * add serde * remove unused * fix staking fuzz * fix system bench Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
committed by
GitHub
parent
4b1460f61f
commit
0ed683ca13
@@ -110,7 +110,7 @@ mod tests {
|
||||
let normal = DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let len = 0_usize;
|
||||
let ext = (
|
||||
crate::CheckWeight::<Test>::default(),
|
||||
crate::CheckWeight::<Test>::new(),
|
||||
CheckMortality::<Test>::from(Era::mortal(16, 256)),
|
||||
);
|
||||
System::set_block_number(17);
|
||||
|
||||
@@ -15,24 +15,27 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::*;
|
||||
use crate::{self as frame_system, *};
|
||||
use sp_std::cell::RefCell;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
testing::Header,
|
||||
};
|
||||
use frame_support::{
|
||||
impl_outer_origin, parameter_types,
|
||||
weights::PostDispatchInfo,
|
||||
testing::Header, BuildStorage,
|
||||
};
|
||||
use frame_support::parameter_types;
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test where system = super {}
|
||||
}
|
||||
type UncheckedExtrinsic = mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = mocking::MockBlock<Test>;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Default)]
|
||||
pub struct Test;
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
const MAX_BLOCK_WEIGHT: Weight = 1024;
|
||||
@@ -81,20 +84,6 @@ impl OnKilledAccount<u64> for RecordKilled {
|
||||
fn on_killed_account(who: &u64) { KILLED.with(|r| r.borrow_mut().push(*who)) }
|
||||
}
|
||||
|
||||
#[derive(Debug, codec::Encode, codec::Decode)]
|
||||
pub struct Call;
|
||||
|
||||
impl Dispatchable for Call {
|
||||
type Origin = Origin;
|
||||
type Config = ();
|
||||
type Info = DispatchInfo;
|
||||
type PostInfo = PostDispatchInfo;
|
||||
fn dispatch(self, _origin: Self::Origin)
|
||||
-> sp_runtime::DispatchResultWithInfo<Self::PostInfo> {
|
||||
panic!("Do not use dummy implementation for dispatch.");
|
||||
}
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type BaseCallFilter = ();
|
||||
type BlockWeights = RuntimeBlockWeights;
|
||||
@@ -108,11 +97,11 @@ impl Config for Test {
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = Event<Self>;
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type DbWeight = DbWeight;
|
||||
type Version = Version;
|
||||
type PalletInfo = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = u32;
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = RecordKilled;
|
||||
@@ -120,14 +109,15 @@ impl Config for Test {
|
||||
type SS58Prefix = ();
|
||||
}
|
||||
|
||||
pub type System = Module<Test>;
|
||||
pub type SysEvent = <Test as Config>::Event;
|
||||
pub type SysEvent = frame_system::Event<Test>;
|
||||
|
||||
pub const CALL: &<Test as Config>::Call = &Call;
|
||||
/// A simple call, which one doesn't matter.
|
||||
pub const CALL: &<Test as Config>::Call = &Call::System(frame_system::Call::set_heap_pages(0u64));
|
||||
|
||||
/// Create new externalities for `System` module tests.
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig::default().build_storage::<Test>().unwrap().into();
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig::default()
|
||||
.build_storage().unwrap().into();
|
||||
// Add to each test the initial weight of a block
|
||||
ext.execute_with(|| System::register_extra_weight_unchecked(
|
||||
<Test as crate::Config>::BlockWeights::get().base_block,
|
||||
|
||||
@@ -637,7 +637,7 @@ pub trait SignedPayload<T: SigningTypes>: Encode {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codec::Decode;
|
||||
use crate::mock::{Test as TestRuntime, Call};
|
||||
use crate::mock::{Test as TestRuntime, Call, CALL};
|
||||
use sp_core::offchain::{testing, TransactionPoolExt};
|
||||
use sp_runtime::testing::{UintAuthorityId, TestSignature, TestXt};
|
||||
|
||||
@@ -708,7 +708,7 @@ mod tests {
|
||||
public: account.public.clone()
|
||||
},
|
||||
|_payload, _signature| {
|
||||
Call
|
||||
CALL.clone()
|
||||
}
|
||||
);
|
||||
|
||||
@@ -749,7 +749,7 @@ mod tests {
|
||||
public: account.public.clone()
|
||||
},
|
||||
|_payload, _signature| {
|
||||
Call
|
||||
CALL.clone()
|
||||
}
|
||||
);
|
||||
|
||||
@@ -787,7 +787,7 @@ mod tests {
|
||||
public: account.public.clone()
|
||||
},
|
||||
|_payload, _signature| {
|
||||
Call
|
||||
CALL.clone()
|
||||
}
|
||||
);
|
||||
|
||||
@@ -827,7 +827,7 @@ mod tests {
|
||||
public: account.public.clone()
|
||||
},
|
||||
|_payload, _signature| {
|
||||
Call
|
||||
CALL.clone()
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ fn deposit_event_should_work() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Finalization,
|
||||
event: SysEvent::CodeUpdated,
|
||||
event: SysEvent::CodeUpdated.into(),
|
||||
topics: vec![],
|
||||
}
|
||||
]
|
||||
@@ -99,17 +99,17 @@ fn deposit_event_should_work() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: SysEvent::NewAccount(32),
|
||||
event: SysEvent::NewAccount(32).into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: SysEvent::KilledAccount(42),
|
||||
event: SysEvent::KilledAccount(42).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: SysEvent::ExtrinsicSuccess(Default::default()),
|
||||
event: SysEvent::ExtrinsicSuccess(Default::default()).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
@@ -117,12 +117,12 @@ fn deposit_event_should_work() {
|
||||
event: SysEvent::ExtrinsicFailed(
|
||||
DispatchError::BadOrigin.into(),
|
||||
Default::default()
|
||||
),
|
||||
).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Finalization,
|
||||
event: SysEvent::NewAccount(3),
|
||||
event: SysEvent::NewAccount(3).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
]
|
||||
@@ -173,7 +173,7 @@ fn deposit_event_uses_actual_weight() {
|
||||
weight: 300,
|
||||
.. Default::default()
|
||||
},
|
||||
),
|
||||
).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
@@ -183,7 +183,7 @@ fn deposit_event_uses_actual_weight() {
|
||||
weight: 1000,
|
||||
.. Default::default()
|
||||
},
|
||||
),
|
||||
).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
@@ -193,7 +193,7 @@ fn deposit_event_uses_actual_weight() {
|
||||
weight: 1000,
|
||||
.. Default::default()
|
||||
},
|
||||
),
|
||||
).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
@@ -204,7 +204,7 @@ fn deposit_event_uses_actual_weight() {
|
||||
weight: 999,
|
||||
.. Default::default()
|
||||
},
|
||||
),
|
||||
).into(),
|
||||
topics: vec![]
|
||||
},
|
||||
]
|
||||
@@ -232,9 +232,9 @@ fn deposit_event_topics() {
|
||||
];
|
||||
|
||||
// We deposit a few events with different sets of topics.
|
||||
System::deposit_event_indexed(&topics[0..3], SysEvent::NewAccount(1));
|
||||
System::deposit_event_indexed(&topics[0..1], SysEvent::NewAccount(2));
|
||||
System::deposit_event_indexed(&topics[1..2], SysEvent::NewAccount(3));
|
||||
System::deposit_event_indexed(&topics[0..3], SysEvent::NewAccount(1).into());
|
||||
System::deposit_event_indexed(&topics[0..1], SysEvent::NewAccount(2).into());
|
||||
System::deposit_event_indexed(&topics[1..2], SysEvent::NewAccount(3).into());
|
||||
|
||||
System::finalize();
|
||||
|
||||
@@ -244,17 +244,17 @@ fn deposit_event_topics() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Finalization,
|
||||
event: SysEvent::NewAccount(1),
|
||||
event: SysEvent::NewAccount(1).into(),
|
||||
topics: topics[0..3].to_vec(),
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Finalization,
|
||||
event: SysEvent::NewAccount(2),
|
||||
event: SysEvent::NewAccount(2).into(),
|
||||
topics: topics[0..1].to_vec(),
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Finalization,
|
||||
event: SysEvent::NewAccount(3),
|
||||
event: SysEvent::NewAccount(3).into(),
|
||||
topics: topics[1..2].to_vec(),
|
||||
}
|
||||
]
|
||||
@@ -375,7 +375,7 @@ fn set_code_with_real_wasm_blob() {
|
||||
System::events(),
|
||||
vec![EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: SysEvent::CodeUpdated,
|
||||
event: SysEvent::CodeUpdated.into(),
|
||||
topics: vec![],
|
||||
}],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user