Weights to u64 + Balances Weights (#5446)

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2020-04-16 10:43:18 +02:00
committed by GitHub
parent 1c7525fd4b
commit 980b635c8d
82 changed files with 636 additions and 428 deletions
+6 -4
View File
@@ -258,6 +258,7 @@ use frame_support::{
dispatch::DispatchResult, decl_module, decl_storage, decl_event,
weights::{
SimpleDispatchInfo, DispatchClass, ClassifyDispatch, WeighData, Weight, PaysFee,
MINIMUM_WEIGHT,
},
};
use sp_std::prelude::*;
@@ -468,7 +469,7 @@ decl_module! {
// weight (a numeric representation of pure execution time and difficulty) of the
// transaction and the latter demonstrates the [`DispatchClass`] of the call. A higher
// weight means a larger transaction (less of which can be placed in a single block).
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
fn accumulate_dummy(origin, increase_by: T::Balance) -> DispatchResult {
// This is a public call, so we ensure that the origin is some signed account.
let _sender = ensure_signed(origin)?;
@@ -523,7 +524,7 @@ decl_module! {
// Anything that needs to be done at the start of the block.
// We don't do anything here.
SimpleDispatchInfo::default().weigh_data(())
MINIMUM_WEIGHT
}
// The signature could also look like: `fn on_finalize()`
@@ -753,6 +754,7 @@ mod tests {
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
@@ -843,11 +845,11 @@ mod tests {
#[test]
fn weights_work() {
// must have a default weight.
// must have a defined weight.
let default_call = <Call<Test>>::accumulate_dummy(10);
let info = default_call.get_dispatch_info();
// aka. `let info = <Call<Test> as GetDispatchInfo>::get_dispatch_info(&default_call);`
assert_eq!(info.weight, 10_000);
assert_eq!(info.weight, 10_000_000);
// must have a custom weight of `100 * arg = 2000`
let custom_call = <Call<Test>>::set_dummy(20);