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:
Alexander Theißen
2020-04-14 16:05:11 +02:00
committed by GitHub
parent 57659b8cf4
commit af7563314f
2 changed files with 114 additions and 6 deletions
+40
View File
@@ -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(|| {