compact param in calls (#1499)

* impl #[codec(compact)] for param

* update modules

* test all and build runtime

* Update srml/support/src/dispatch.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* Update srml/support/src/dispatch.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* delete wip comment

* update param to use #[compact] instead of Cmpact<>

* fmt

* impl metadata

* test metadata

* add compact attr test

* script buid

* update test
This commit is contained in:
thiolliere
2019-01-22 14:42:13 +01:00
committed by Bastian Köcher
parent 8f38593def
commit 2492931944
24 changed files with 576 additions and 541 deletions
+6 -11
View File
@@ -102,7 +102,7 @@ use account_db::AccountDb;
use rstd::prelude::*;
use rstd::marker::PhantomData;
use codec::{Codec, HasCompact};
use codec::Codec;
use runtime_primitives::traits::{Hash, As, SimpleArithmetic,Bounded, StaticLookup};
use runtime_support::dispatch::{Result, Dispatchable};
use runtime_support::{Parameter, StorageMap, StorageValue, StorageDoubleMap};
@@ -198,11 +198,10 @@ decl_module! {
/// Stores code in the storage. You can instantiate contracts only with stored code.
fn put_code(
origin,
gas_limit: <T::Gas as HasCompact>::Type,
#[compact] gas_limit: T::Gas,
code: Vec<u8>
) -> Result {
let origin = ensure_signed(origin)?;
let gas_limit = gas_limit.into();
let schedule = <Module<T>>::current_schedule();
let mut gas_meter = gas::buy_gas::<T>(&origin, gas_limit)?;
@@ -221,13 +220,11 @@ decl_module! {
fn call(
origin,
dest: <T::Lookup as StaticLookup>::Source,
value: <T::Balance as HasCompact>::Type,
gas_limit: <T::Gas as HasCompact>::Type,
#[compact] value: T::Balance,
#[compact] gas_limit: T::Gas,
data: Vec<u8>
) -> Result {
let origin = ensure_signed(origin)?;
let value = value.into();
let gas_limit = gas_limit.into();
let dest = T::Lookup::lookup(dest)?;
// Pay for the gas upfront.
@@ -277,14 +274,12 @@ decl_module! {
/// upon any message received by this account.
fn create(
origin,
endowment: <T::Balance as HasCompact>::Type,
gas_limit: <T::Gas as HasCompact>::Type,
#[compact] endowment: T::Balance,
#[compact] gas_limit: T::Gas,
code_hash: CodeHash<T>,
data: Vec<u8>
) -> Result {
let origin = ensure_signed(origin)?;
let endowment = endowment.into();
let gas_limit = gas_limit.into();
// Pay for the gas upfront.
//
+12 -12
View File
@@ -189,8 +189,8 @@ fn refunds_unused_gas() {
assert_ok!(Contract::call(
Origin::signed(0),
1,
0.into(),
100_000.into(),
0,
100_000,
Vec::new()
));
@@ -220,7 +220,7 @@ fn account_removal_removes_storage() {
// the balance of account 1 is will be below than exsistential threshold.
//
// This should lead to the removal of all storage associated with this account.
assert_ok!(Balances::transfer(Origin::signed(1), 2, 20.into()));
assert_ok!(Balances::transfer(Origin::signed(1), 2, 20));
// Verify that all entries from account 1 is removed, while
// entries from account 2 is in place.
@@ -277,14 +277,14 @@ fn instantiate_and_call() {
assert_ok!(Contract::put_code(
Origin::signed(ALICE),
100_000.into(),
100_000,
wasm,
));
assert_ok!(Contract::create(
Origin::signed(ALICE),
100.into(),
100_000.into(),
100,
100_000,
HASH_RETURN_FROM_START_FN.into(),
vec![],
));
@@ -335,7 +335,7 @@ const HASH_DISPATCH_CALL: [u8; 32] = hex!("49dfdcaf9c1553be10634467e95b8e71a3bc1
fn dispatch_call() {
// This test can fail due to the encoding changes. In case it becomes too annoying
// let's rewrite so as we use this module controlled call or we serialize it in runtime.
let encoded = codec::Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50.into())));
let encoded = codec::Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50)));
assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]);
let wasm = wabt::wat2wasm(CODE_DISPATCH_CALL).unwrap();
@@ -348,7 +348,7 @@ fn dispatch_call() {
assert_ok!(Contract::put_code(
Origin::signed(ALICE),
100_000.into(),
100_000,
wasm,
));
@@ -363,8 +363,8 @@ fn dispatch_call() {
assert_ok!(Contract::create(
Origin::signed(ALICE),
100.into(),
100_000.into(),
100,
100_000,
HASH_DISPATCH_CALL.into(),
vec![],
));
@@ -372,8 +372,8 @@ fn dispatch_call() {
assert_ok!(Contract::call(
Origin::signed(ALICE),
BOB, // newly created account
0.into(),
100_000.into(),
0,
100_000,
vec![],
));
+1 -1
View File
@@ -984,7 +984,7 @@ mod tests {
assert_eq!(
&mock_ext.dispatches,
&[DispatchEntry(
Call::Balances(balances::Call::set_balance(42, 1337.into(), 0.into())),
Call::Balances(balances::Call::set_balance(42, 1337, 0)),
)]
);
}