Mandate weight annotation (#5357)

* Disallow default weight

* Fix build and test

* Fix tests

* Fix another beloved ui test.

* fix beloved trybuild tests

* fix treasury?

* Final test fix

* Fix build

* Fix another one

* Fix

* More doctest fix
This commit is contained in:
Kian Paimani
2020-03-26 11:17:05 +01:00
committed by GitHub
parent 7cbadd73be
commit a0772117ac
27 changed files with 111 additions and 48 deletions
+17 -4
View File
@@ -71,6 +71,7 @@ decl_module! {
fn deposit_event() = default;
/// Do nothing.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn do_nothing(_origin, input: u32) {
if input > 0 {
return Ok(());
@@ -82,6 +83,7 @@ decl_module! {
/// storage database, however, the `repeat` calls will all pull from the
/// storage overlay cache. You must consider this when analyzing the
/// results of the benchmark.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn read_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::get();
@@ -89,6 +91,7 @@ decl_module! {
}
/// Put a value into a storage value.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn put_value(_origin, repeat: u32) {
for r in 0..repeat {
MyValue::put(r);
@@ -100,6 +103,7 @@ decl_module! {
/// storage database, however, the `repeat` calls will all pull from the
/// storage overlay cache. You must consider this when analyzing the
/// results of the benchmark.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn exists_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::exists();
@@ -107,6 +111,7 @@ decl_module! {
}
/// Remove a value from storage `repeat` number of times.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn remove_value(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::remove(r);
@@ -114,6 +119,7 @@ decl_module! {
}
/// Read a value from storage map `repeat` number of times.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn read_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::get(r);
@@ -121,6 +127,7 @@ decl_module! {
}
/// Insert a value into a map.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn insert_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::insert(r, r);
@@ -128,6 +135,7 @@ decl_module! {
}
/// Check is a map contains a value `repeat` number of times.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn contains_key_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::contains_key(r);
@@ -135,25 +143,29 @@ decl_module! {
}
/// Read a value from storage `repeat` number of times.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn remove_prefix(_origin, repeat: u32) {
for r in 0..repeat {
MyDoubleMap::remove_prefix(r);
}
}
// Add user to the list.
/// Add user to the list.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn add_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::mutate(|x| x.push(who));
}
// Append user to the list.
/// Append user to the list.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn append_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::append(&[who])?;
}
// Encode a vector of accounts to bytes.
/// Encode a vector of accounts to bytes.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn encode_accounts(_origin, accounts: Vec<T::AccountId>) {
let bytes = accounts.encode();
@@ -164,7 +176,8 @@ decl_module! {
}
}
// Decode bytes into a vector of accounts.
/// Decode bytes into a vector of accounts.
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
pub fn decode_accounts(_origin, bytes: Vec<u8>) {
let accounts: Vec<T::AccountId> = Decode::decode(&mut bytes.as_slice()).map_err(|_| "Could not decode")?;