Skip to content

Commit

Permalink
Release 0.0.8
Browse files Browse the repository at this point in the history
add type arguments for run.rs.
`$ move run abc.mvir -t u64 -t address`
  • Loading branch information
liangping committed May 13, 2020
1 parent 139d909 commit b69a430
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "move-runner"
version = "0.0.7"
version = "0.0.8"
authors = ["Ping <[email protected]>"]
edition = "2018"
description = "A Move VM simulator which allows developers to compile and run Move script/module on local computer. "
Expand Down
22 changes: 9 additions & 13 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod compile;
pub mod new;
pub mod run;
pub mod test;
pub mod type_parser;

pub trait Command {
fn execute(&self, params: Parameter);
Expand All @@ -38,30 +39,25 @@ pub fn test_command() -> Box<dyn Command> {
Box::new(test::TestCommand {})
}


fn load_genesis(cfg: &Config, runner: &mut MoveRunner) {
println_color("Loading");
print!("'genesis.blob' from {:?}\n", &cfg.home);
let mut exec_cfg = ExecutionConfig::default();
exec_cfg.genesis_file_location = PathBuf::from("genesis.blob");
exec_cfg.load(&RootPath::new(&cfg.home)).expect("'genesis.blob' is invalid:");
exec_cfg
.load(&RootPath::new(&cfg.home))
.expect("'genesis.blob' is invalid:");

let tx = exec_cfg.genesis.unwrap();
let gen_payload = tx.as_signed_user_txn().unwrap().payload();
match &gen_payload {
TransactionPayload::WriteSet(cs) => {
runner.datastore.add_write_set(cs.write_set());
//print_all(cs);
},
TransactionPayload::Module(m) => {
println!("module:{:?}", m)
},
TransactionPayload::Script(s) => {
println!("script:{:?}", s)
},
TransactionPayload::Program => {
println!("unimplemented")
},
}
TransactionPayload::Module(m) => println!("module:{:?}", m),
TransactionPayload::Script(s) => println!("script:{:?}", s),
TransactionPayload::Program => println!("unimplemented"),
}
}

Expand All @@ -75,4 +71,4 @@ fn convert_txn_args(args: &[TransactionArgument]) -> Vec<Value> {
TransactionArgument::U8Vector(v) => Value::vector_u8(v.clone()),
})
.collect()
}
}
15 changes: 9 additions & 6 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bytecode_verifier::verifier::VerifiedModule;
use libra_types::transaction::{parse_as_transaction_argument, TransactionArgument};
use move_core_types::gas_schedule::{GasAlgebra, GasUnits};
use move_core_types::language_storage::TypeTag;
use move_vm_runtime::MoveVM;
use move_vm_state::execution_context::{ExecutionContext, TransactionExecutionContext};
use move_vm_types::gas_schedule::zero_cost_schedule;
Expand All @@ -11,6 +12,7 @@ use glob::glob;

use crate::{commands::Command, config::Config, Parameter, println_color, runner::MoveRunner};
use crate::commands::{convert_txn_args, load_genesis};
use crate::commands::type_parser::parse_type_tags;

pub struct RunCommand {}

Expand All @@ -19,9 +21,12 @@ impl Command for RunCommand {
if let Parameter::Run {
home,
mut source_path,
type_args,
args,
} = params
{
let ty_args: Vec<TypeTag> = parse_type_tags(&type_args.join(",")).unwrap();

// check if arguments are valid.
let ta_args: Vec<TransactionArgument> = args
.iter()
Expand Down Expand Up @@ -60,11 +65,11 @@ impl Command for RunCommand {

load_genesis(&cfg, &mut m_runner);


println_color("Running");
print!(
"Script: {:?} Args: {:?}\n",
"Script: {:?} Type Args:{:?}, Args: {:?}\n",
&source_path.file_name().unwrap(),
&ty_args,
args
);

Expand All @@ -77,15 +82,14 @@ impl Command for RunCommand {
// Execute script.
// create a Move VM and populate it with generated modules
let move_vm = MoveVM::new();
let mut ctx =
TransactionExecutionContext::new(GasUnits::new(600), &m_runner.datastore);
let mut ctx = TransactionExecutionContext::new(GasUnits::new(600), &m_runner.datastore);
let gas_schedule = zero_cost_schedule();

let mut txn_data = TransactionMetadata::default();
txn_data.sender = cfg.address();

let result: VMResult<()> =
move_vm.execute_script(script, &gas_schedule, &mut ctx, &txn_data, vec![], va_args);
move_vm.execute_script(script, &gas_schedule, &mut ctx, &txn_data, ty_args, va_args);

match result {
Ok(_) => {
Expand All @@ -103,4 +107,3 @@ impl Command for RunCommand {
}
}
}

36 changes: 17 additions & 19 deletions src/commands/test.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use std::io::Write;

use bytecode_verifier::verifier::VerifiedModule;
use move_core_types::{
gas_schedule::{GasAlgebra, GasUnits},
};
use move_core_types::gas_schedule::{GasAlgebra, GasUnits};
use move_vm_runtime::MoveVM;
use move_vm_state::execution_context::TransactionExecutionContext;
use move_vm_types::gas_schedule::zero_cost_schedule;
use move_vm_types::transaction_metadata::TransactionMetadata;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use vm::{
errors::VMResult,
};
use vm::errors::VMResult;

use glob::glob;

Expand All @@ -22,10 +18,7 @@ pub struct TestCommand {}

impl Command for TestCommand {
fn execute(&self, params: Parameter) {
if let Parameter::Test {
home,
} = params
{
if let Parameter::Test { home } = params {
// initialize
let cfg = Config::load_config(home);
let mut m_runner = MoveRunner::new(cfg.clone());
Expand Down Expand Up @@ -64,10 +57,7 @@ impl Command for TestCommand {
let compiled_script = m_runner.complie_script(&path).into_inner();

println_color("Running");
print!(
"Script: {:?} Args: []",
&path.file_name().unwrap()
);
print!("Script: {:?} Args: []", &path.file_name().unwrap());

let mut script: Vec<u8> = vec![];
compiled_script
Expand All @@ -78,21 +68,29 @@ impl Command for TestCommand {
// Execute script.
// create a Move VM and populate it with generated modules
let move_vm = MoveVM::new();
let mut ctx =
TransactionExecutionContext::new(GasUnits::new(600), &m_runner.datastore);
let mut ctx = TransactionExecutionContext::new(
GasUnits::new(600),
&m_runner.datastore,
);
let gas_schedule = zero_cost_schedule();

let mut txn_data = TransactionMetadata::default();
txn_data.sender = cfg.address();

let result: VMResult<()> =
move_vm.execute_script(script, &gas_schedule, &mut ctx, &txn_data, vec![], vec![]);
let result: VMResult<()> = move_vm.execute_script(
script,
&gas_schedule,
&mut ctx,
&txn_data,
vec![],
vec![],
);

match result {
Ok(_) => status_print("OK\n", Color::Green),
Err(_e) => status_print("Failed\n", Color::Red),
}
},
}
Err(_) => {
panic!("Failed to load source file of test cases.");
}
Expand Down
Loading

0 comments on commit b69a430

Please sign in to comment.