mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
Add base-weight to System::Extrinsic* events (#12329)
* Add base-weight to events Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
committed by
GitHub
parent
3317eb76d5
commit
26ea6e1e48
+173
-139
@@ -169,6 +169,10 @@ fn deposit_event_should_work() {
|
||||
}]
|
||||
);
|
||||
|
||||
let normal_base = <Test as crate::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
|
||||
System::reset_events();
|
||||
System::initialize(&2, &[0u8; 32].into(), &Default::default());
|
||||
System::deposit_event(SysEvent::NewAccount { account: 32 });
|
||||
@@ -194,14 +198,17 @@ fn deposit_event_should_work() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: SysEvent::ExtrinsicSuccess { dispatch_info: Default::default() }.into(),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo { weight: normal_base, ..Default::default() }
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: Default::default()
|
||||
dispatch_info: DispatchInfo { weight: normal_base, ..Default::default() }
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
@@ -223,6 +230,9 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
|
||||
System::initialize(&1, &[0u8; 32].into(), &Default::default());
|
||||
System::note_finished_initialize();
|
||||
|
||||
let normal_base = <Test as crate::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
let pre_info = DispatchInfo { weight: Weight::from_ref_time(1000), ..Default::default() };
|
||||
System::note_applied_extrinsic(&Ok(Some(300).into()), pre_info);
|
||||
System::note_applied_extrinsic(&Ok(Some(1000).into()), pre_info);
|
||||
@@ -267,144 +277,168 @@ fn deposit_event_uses_actual_weight_and_pays_fee() {
|
||||
}),
|
||||
pre_info,
|
||||
);
|
||||
// Also works for operational.
|
||||
let operational_base = <Test as crate::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Operational)
|
||||
.base_extrinsic;
|
||||
assert!(normal_base != operational_base, "Test pre-condition violated");
|
||||
let pre_info = DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000),
|
||||
class: DispatchClass::Operational,
|
||||
..Default::default()
|
||||
};
|
||||
System::note_applied_extrinsic(&Ok(Some(300).into()), pre_info);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(300),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(2),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(3),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000),
|
||||
pays_fee: Pays::Yes,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(4),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(5),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(6),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(500),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(7),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(999),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(8),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000),
|
||||
pays_fee: Pays::Yes,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(9),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(800),
|
||||
pays_fee: Pays::Yes,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(10),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(800),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![]
|
||||
},
|
||||
]
|
||||
);
|
||||
let got = System::events();
|
||||
let want = vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(300).saturating_add(normal_base),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000).saturating_add(normal_base),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(2),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000).saturating_add(normal_base),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(3),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000).saturating_add(normal_base),
|
||||
pays_fee: Pays::Yes,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(4),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000).saturating_add(normal_base),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(5),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000).saturating_add(normal_base),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(6),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(500).saturating_add(normal_base),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(7),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(999).saturating_add(normal_base),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(8),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(1000).saturating_add(normal_base),
|
||||
pays_fee: Pays::Yes,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(9),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(800).saturating_add(normal_base),
|
||||
pays_fee: Pays::Yes,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(10),
|
||||
event: SysEvent::ExtrinsicFailed {
|
||||
dispatch_error: DispatchError::BadOrigin.into(),
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(800).saturating_add(normal_base),
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(11),
|
||||
event: SysEvent::ExtrinsicSuccess {
|
||||
dispatch_info: DispatchInfo {
|
||||
weight: Weight::from_ref_time(300).saturating_add(operational_base),
|
||||
class: DispatchClass::Operational,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
.into(),
|
||||
topics: vec![],
|
||||
},
|
||||
];
|
||||
for (i, event) in want.into_iter().enumerate() {
|
||||
assert_eq!(got[i], event, "Event mismatch at index {}", i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user