mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Weight v1.5: Opaque Struct (#12138)
* initial idea * update frame_support * update a bunch more * add ord * adjust RuntimeDbWeight * frame_system builds * re-export * frame_support tests pass * frame_executive compile * frame_executive builds * frame_system tests passing * pallet-utility tests pass * fix a bunch of pallets * more * phragmen * state-trie-migration * scheduler and referenda * pallet-election-provider-multi-phase * aura * staking * more * babe * balances * bunch more * sudo * transaction-payment * asset-tx-payment * last pallets * fix alliance merge * fix node template runtime * fix pallet-contracts cc @athei * fix node runtime * fix compile on runtime-benchmarks feature * comment * fix frame-support-test * fix more tests * weight regex * frame system works * fix a bunch * more * more * more * more * more * more fixes * update templates * fix contracts benchmarks * Update lib.rs * Update lib.rs * fix ui * make scalar saturating mul const * more const functions * scalar div * refactor using constant functions * move impl * fix overhead template * use compactas * Update lib.rs
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
//! Tests for the module.
|
||||
|
||||
use super::*;
|
||||
use frame_support::{assert_noop, assert_ok};
|
||||
use frame_support::{assert_noop, assert_ok, weights::Weight};
|
||||
use mock::{
|
||||
new_test_ext, Call, Event as TestEvent, Logger, LoggerCall, Origin, Sudo, SudoCall, System,
|
||||
Test,
|
||||
@@ -39,12 +39,18 @@ fn sudo_basics() {
|
||||
// Configure a default test environment and set the root `key` to 1.
|
||||
new_test_ext(1).execute_with(|| {
|
||||
// A privileged function should work when `sudo` is passed the root `key` as `origin`.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1_000 }));
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
|
||||
i: 42,
|
||||
weight: Weight::from_ref_time(1_000),
|
||||
}));
|
||||
assert_ok!(Sudo::sudo(Origin::signed(1), call));
|
||||
assert_eq!(Logger::i32_log(), vec![42i32]);
|
||||
|
||||
// A privileged function should not work when `sudo` is passed a non-root `key` as `origin`.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1_000 }));
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
|
||||
i: 42,
|
||||
weight: Weight::from_ref_time(1_000),
|
||||
}));
|
||||
assert_noop!(Sudo::sudo(Origin::signed(2), call), Error::<Test>::RequireSudo);
|
||||
});
|
||||
}
|
||||
@@ -56,7 +62,8 @@ 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: 1 }));
|
||||
let call =
|
||||
Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: Weight::one() }));
|
||||
assert_ok!(Sudo::sudo(Origin::signed(1), call));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
|
||||
})
|
||||
@@ -66,24 +73,36 @@ fn sudo_emits_events_correctly() {
|
||||
fn sudo_unchecked_weight_basics() {
|
||||
new_test_ext(1).execute_with(|| {
|
||||
// A privileged function should work when `sudo` is passed the root `key` as origin.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1_000 }));
|
||||
assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000));
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
|
||||
i: 42,
|
||||
weight: Weight::from_ref_time(1_000),
|
||||
}));
|
||||
assert_ok!(Sudo::sudo_unchecked_weight(
|
||||
Origin::signed(1),
|
||||
call,
|
||||
Weight::from_ref_time(1_000)
|
||||
));
|
||||
assert_eq!(Logger::i32_log(), vec![42i32]);
|
||||
|
||||
// A privileged function should not work when called with a non-root `key`.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1_000 }));
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
|
||||
i: 42,
|
||||
weight: Weight::from_ref_time(1_000),
|
||||
}));
|
||||
assert_noop!(
|
||||
Sudo::sudo_unchecked_weight(Origin::signed(2), call, 1_000),
|
||||
Sudo::sudo_unchecked_weight(Origin::signed(2), call, Weight::from_ref_time(1_000)),
|
||||
Error::<Test>::RequireSudo,
|
||||
);
|
||||
// `I32Log` is unchanged after unsuccessful call.
|
||||
assert_eq!(Logger::i32_log(), vec![42i32]);
|
||||
|
||||
// Controls the dispatched weight.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 }));
|
||||
let sudo_unchecked_weight_call = SudoCall::sudo_unchecked_weight { call, weight: 1_000 };
|
||||
let call =
|
||||
Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: Weight::one() }));
|
||||
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();
|
||||
assert_eq!(info.weight, 1_000);
|
||||
assert_eq!(info.weight, Weight::from_ref_time(1_000));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,8 +113,13 @@ 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: 1 }));
|
||||
assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000));
|
||||
let call =
|
||||
Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: Weight::one() }));
|
||||
assert_ok!(Sudo::sudo_unchecked_weight(
|
||||
Origin::signed(1),
|
||||
call,
|
||||
Weight::from_ref_time(1_000)
|
||||
));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
|
||||
})
|
||||
}
|
||||
@@ -134,17 +158,22 @@ fn set_key_emits_events_correctly() {
|
||||
fn sudo_as_basics() {
|
||||
new_test_ext(1).execute_with(|| {
|
||||
// A privileged function will not work when passed to `sudo_as`.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1_000 }));
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log {
|
||||
i: 42,
|
||||
weight: Weight::from_ref_time(1_000),
|
||||
}));
|
||||
assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call));
|
||||
assert!(Logger::i32_log().is_empty());
|
||||
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: 1 }));
|
||||
let call =
|
||||
Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: Weight::one() }));
|
||||
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: 1 }));
|
||||
let call =
|
||||
Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: Weight::one() }));
|
||||
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`.
|
||||
@@ -159,7 +188,8 @@ 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: 1 }));
|
||||
let call =
|
||||
Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: Weight::one() }));
|
||||
assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone { sudo_result: Ok(()) }));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user