Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Next Next commit
Rename ext_transfer → ext_call
There are several tests where gas was changed. This is due to shrinking
the name and consequently a size of contracts.
  • Loading branch information
pepyakin committed Aug 30, 2018
commit 74896232c9871dc30939c795716773d1a81ff225
14 changes: 7 additions & 7 deletions substrate/runtime/contract/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ impl ExtBuilder {

const CODE_TRANSFER: &str = r#"
(module
;; ext_transfer(transfer_to: u32, transfer_to_len: u32, value_ptr: u32, value_len: u32)
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32)))
;; ext_call(callee_ptr: u32, callee_len: u32, value_ptr: u32, value_len: u32)
(import "env" "ext_call" (func $ext_call (param i32 i32 i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "call")
(call $ext_transfer
(call $ext_call
(i32.const 4) ;; Pointer to "Transfer to" address.
(i32.const 8) ;; Length of "Transfer to" address.
(i32.const 12) ;; Pointer to the buffer with value to transfer
Expand Down Expand Up @@ -377,12 +377,12 @@ fn contract_create() {
);

// 11 - value sent with the transaction
// 2 * 128 - gas spent by the deployer contract (128) multiplied by gas price (2)
// 2 * 124 - gas spent by the deployer contract (124) multiplied by gas price (2)
// 2 * 135 - base gas fee for call (top level)
// 2 * 175 - base gas fee for create (by contract)
// ((21 / 2) * 2) - price per account creation
let expected_gas_after_create =
100_000_000 - 11 - (2 * 128) - (2 * 135) - (2 * 175) - ((21 / 2) * 2);
100_000_000 - 11 - (2 * 124) - (2 * 135) - (2 * 175) - ((21 / 2) * 2);
assert_eq!(Staking::free_balance(&0), expected_gas_after_create);
assert_eq!(Staking::free_balance(&1), 8);
assert_eq!(Staking::free_balance(&derived_address), 3);
Expand Down Expand Up @@ -428,12 +428,12 @@ fn top_level_create() {
));

// 11 - value sent with the transaction
// (3 * 122) - gas spent by the ctor
// (3 * 118) - gas spent by the ctor
// (3 * 175) - base gas fee for create (175) (top level) multipled by gas price (3)
// ((21 / 3) * 3) - price for contract creation
assert_eq!(
Staking::free_balance(&0),
100_000_000 - 11 - (3 * 122) - (3 * 175) - ((21 / 3) * 3)
100_000_000 - 11 - (3 * 118) - (3 * 175) - ((21 / 3) * 3)
);
assert_eq!(Staking::free_balance(&derived_address), 30 + 11);

Expand Down
17 changes: 8 additions & 9 deletions substrate/runtime/contract/src/vm/env_def/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,13 @@ define_env!(init_env, <E: Ext>,
Ok(())
},

// TODO: Rename ext_transfer to ext_call.
// ext_transfer(transfer_to_ptr: u32, transfer_to_len: u32, value_ptr: u32, value_len: u32)
ext_transfer(ctx, transfer_to_ptr: u32, transfer_to_len: u32, value_ptr: u32, value_len: u32) => {
let mut transfer_to = Vec::new();
transfer_to.resize(transfer_to_len as usize, 0);
ctx.memory().get(transfer_to_ptr, &mut transfer_to)?;
let transfer_to =
<<E as Ext>::T as system::Trait>::AccountId::decode(&mut &transfer_to[..]).unwrap();
// ext_call(transfer_to_ptr: u32, transfer_to_len: u32, value_ptr: u32, value_len: u32)
ext_call(ctx, callee_ptr: u32, callee_len: u32, value_ptr: u32, value_len: u32) => {
let mut callee = Vec::new();
callee.resize(callee_len as usize, 0);
ctx.memory().get(callee_ptr, &mut callee)?;
let callee =
<<E as Ext>::T as system::Trait>::AccountId::decode(&mut &callee[..]).unwrap();

let mut value_buf = Vec::new();
value_buf.resize(value_len as usize, 0);
Expand All @@ -188,7 +187,7 @@ define_env!(init_env, <E: Ext>,
let ext = &mut ctx.ext;
let call_outcome = ctx.gas_meter.with_nested(nested_gas_limit, |nested_meter| {
match nested_meter {
Some(nested_meter) => ext.call(&transfer_to, value, nested_meter, &input_data),
Some(nested_meter) => ext.call(&callee, value, nested_meter, &input_data),
// there is not enough gas to allocate for the nested call.
None => Err(()),
}
Expand Down
6 changes: 3 additions & 3 deletions substrate/runtime/contract/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ mod tests {

const CODE_TRANSFER: &str = r#"
(module
;; ext_transfer(transfer_to: u32, transfer_to_len: u32, value_ptr: u32, value_len: u32)
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32)))
;; ext_call(callee_ptr: u32, callee_len: u32, value_ptr: u32, value_len: u32)
(import "env" "ext_call" (func $ext_call (param i32 i32 i32 i32)))

(import "env" "memory" (memory 1 1))

(func (export "call")
(call $ext_transfer
(call $ext_call
(i32.const 4) ;; Pointer to "Transfer to" address.
(i32.const 8) ;; Length of "Transfer to" address.
(i32.const 12) ;; Pointer to the buffer with value to transfer
Expand Down