Weight v1.5 Follow Ups (#12155)

* update api

* update

* remove unused

* remove `one` api

* fix unused

* fmt

* add saturating accrue

* remove `Weight::new()`

* use some macros

* div makes no sense

* Update weight_v2.rs

* missed some

* more patch

* fixes

* more fixes

* more fix

* more fix

* Update frame/support/src/weights/weight_v2.rs

* not needed

* fix weight file
This commit is contained in:
Shawn Tabrizi
2022-09-01 18:48:03 +01:00
committed by GitHub
parent 6be21e0397
commit 1df4561676
80 changed files with 965 additions and 960 deletions
+24 -12
View File
@@ -62,8 +62,10 @@ fn sudo_emits_events_correctly() {
System::set_block_number(1);
// Should emit event to indicate success when called with the root `key` and `call` is `Ok`.
let call =
Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: Weight::one() }));
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_ref_time(1),
}));
assert_ok!(Sudo::sudo(Origin::signed(1), call));
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
})
@@ -97,8 +99,10 @@ fn sudo_unchecked_weight_basics() {
assert_eq!(Logger::i32_log(), vec![42i32]);
// Controls the dispatched weight.
let call =
Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: Weight::one() }));
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_ref_time(1),
}));
let sudo_unchecked_weight_call =
SudoCall::sudo_unchecked_weight { call, weight: Weight::from_ref_time(1_000) };
let info = sudo_unchecked_weight_call.get_dispatch_info();
@@ -113,8 +117,10 @@ fn sudo_unchecked_weight_emits_events_correctly() {
System::set_block_number(1);
// Should emit event to indicate success when called with the root `key` and `call` is `Ok`.
let call =
Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: Weight::one() }));
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_ref_time(1),
}));
assert_ok!(Sudo::sudo_unchecked_weight(
Origin::signed(1),
call,
@@ -167,13 +173,17 @@ fn sudo_as_basics() {
assert!(Logger::account_log().is_empty());
// A non-privileged function should not work when called with a non-root `key`.
let call =
Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: Weight::one() }));
let call = Box::new(Call::Logger(LoggerCall::non_privileged_log {
i: 42,
weight: Weight::from_ref_time(1),
}));
assert_noop!(Sudo::sudo_as(Origin::signed(3), 2, call), Error::<Test>::RequireSudo);
// A non-privileged function will work when passed to `sudo_as` with the root `key`.
let call =
Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: Weight::one() }));
let call = Box::new(Call::Logger(LoggerCall::non_privileged_log {
i: 42,
weight: Weight::from_ref_time(1),
}));
assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call));
assert_eq!(Logger::i32_log(), vec![42i32]);
// The correct user makes the call within `sudo_as`.
@@ -188,8 +198,10 @@ fn sudo_as_emits_events_correctly() {
System::set_block_number(1);
// A non-privileged function will work when passed to `sudo_as` with the root `key`.
let call =
Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: Weight::one() }));
let call = Box::new(Call::Logger(LoggerCall::non_privileged_log {
i: 42,
weight: Weight::from_ref_time(1),
}));
assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call));
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone { sudo_result: Ok(()) }));
});