mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
Add tests for weight refund (#5624)
* Add tests for weight refund * Update frame/system/src/lib.rs Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fixed formatting * Format fixes Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
57659b8cf4
commit
af7563314f
@@ -1913,6 +1913,46 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signed_ext_check_weight_refund_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let info = DispatchInfo { weight: 512, ..Default::default() };
|
||||
let post_info = PostDispatchInfo { actual_weight: Some(128), };
|
||||
let len = 0_usize;
|
||||
|
||||
AllExtrinsicsWeight::put(256);
|
||||
|
||||
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
|
||||
assert_eq!(AllExtrinsicsWeight::get().unwrap(), info.weight + 256);
|
||||
|
||||
assert!(
|
||||
CheckWeight::<Test>::post_dispatch(pre, &info, &post_info, len, &Ok(()))
|
||||
.is_ok()
|
||||
);
|
||||
assert_eq!(AllExtrinsicsWeight::get().unwrap(), post_info.actual_weight.unwrap() + 256);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signed_ext_check_weight_actual_weight_higher_than_max_is_capped() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let info = DispatchInfo { weight: 512, ..Default::default() };
|
||||
let post_info = PostDispatchInfo { actual_weight: Some(700), };
|
||||
let len = 0_usize;
|
||||
|
||||
AllExtrinsicsWeight::put(128);
|
||||
|
||||
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
|
||||
assert_eq!(AllExtrinsicsWeight::get().unwrap(), info.weight + 128);
|
||||
|
||||
assert!(
|
||||
CheckWeight::<Test>::post_dispatch(pre, &info, &post_info, len, &Ok(()))
|
||||
.is_ok()
|
||||
);
|
||||
assert_eq!(AllExtrinsicsWeight::get().unwrap(), info.weight + 128);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signed_ext_check_weight_fee_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
|
||||
Reference in New Issue
Block a user