Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #54 from paritytech/call-gasleft
Browse files Browse the repository at this point in the history
call_gasleft test added
  • Loading branch information
NikVolf committed Aug 23, 2018
2 parents 8b57b09 + 0edbf86 commit d17bfb6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set -e
./build-rust-test.sh call_code
./build-rust-test.sh call_static
./build-rust-test.sh creator kip4
./build-rust-test.sh call_gasleft kip6
./build-rust-test.sh gasleft kip6
./build-rust-test.sh dispersion
./build-rust-test.sh empty
./build-rust-test.sh externs
Expand Down
Binary file added compiled/call_gasleft.wasm
Binary file not shown.
Binary file modified compiled/gasleft.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion gen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
let args = env::args().collect::<Vec<_>>();
let (file_name, pwasm_ethereum_version) = match args.len() {
2 => (&args[1], r#""0.6.3""#.to_string()),
3 => (&args[1], format!(r#"{{ version = "0.6.3", features = [{}] }}"#, args[2].split(",").map(|s| format!(r#""{}""#, s)).collect::<Vec<_>>().join(", "))),
3 => (&args[1], format!(r#"{{ version = "0.7", features = [{}] }}"#, args[2].split(",").map(|s| format!(r#""{}""#, s)).collect::<Vec<_>>().join(", "))),
_ => {
println!("Usage: {} gen <test.rs>", args[0]);
return;
Expand Down
27 changes: 27 additions & 0 deletions src/call_gasleft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![no_std]

#[macro_use] extern crate pwasm_std;
extern crate pwasm_ethereum;

use pwasm_std::logger;
use pwasm_std::hash::Address;
use pwasm_ethereum::{call as ext_call, gas_left as ext_gasleft, ret};

#[no_mangle]
pub fn call() {
let addr = Address::from([99, 88, 77, 66, 55, 44, 33, 22, 11, 0, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0]);

let input = [129u8, 123, 113, 107, 101, 97];
let mut temp = vec![0u8; 256];
// `700` is a fixed CALL price, that's why we have to subtract it
match ext_call(ext_gasleft() - 700, &addr, 1000000000.into(), &input, &mut temp[..]) {
Ok(_) => {
logger::debug("Call succeed");
},
Err(_) => {
logger::debug("Call failed");
}
}

ret(&[]);
}
1 change: 0 additions & 1 deletion src/gasleft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

extern crate pwasm_std;
extern crate pwasm_ethereum;
extern crate bigint;

use pwasm_std::{Vec, write_u64};
use pwasm_ethereum::{self as ext};
Expand Down

0 comments on commit d17bfb6

Please sign in to comment.