Running parametrized JSON tests
This commit is contained in:
parent
d3a71d3058
commit
4c1b8ddd8f
@ -1,11 +1,31 @@
|
|||||||
//! Evm factory.
|
//! Evm factory.
|
||||||
|
use std::fmt;
|
||||||
use evm::Evm;
|
use evm::Evm;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum VMType {
|
pub enum VMType {
|
||||||
Jit,
|
Jit,
|
||||||
Interpreter
|
Interpreter
|
||||||
}
|
}
|
||||||
|
impl fmt::Display for VMType {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{}", match *self {
|
||||||
|
VMType::Jit => "JIT",
|
||||||
|
VMType::Interpreter => "INT"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VMType {
|
||||||
|
#[cfg(feature="jit")]
|
||||||
|
pub fn all() -> Vec<VMType> {
|
||||||
|
vec![VMType::Jit, VMType::Interpreter]
|
||||||
|
}
|
||||||
|
#[cfg(not(feature="jit"))]
|
||||||
|
pub fn all() -> Vec<VMType> {
|
||||||
|
vec![VMType::Interpreter]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Evm factory. Creates appropriate Evm.
|
/// Evm factory. Creates appropriate Evm.
|
||||||
pub struct Factory {
|
pub struct Factory {
|
||||||
|
@ -156,16 +156,28 @@ impl<'a> Ext for TestExt<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||||
|
let vms = VMType::all();
|
||||||
|
|
||||||
|
vms
|
||||||
|
.iter()
|
||||||
|
.flat_map(|vm| do_json_test_for(vm, json_data))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
|
||||||
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
|
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
|
||||||
let mut failed = Vec::new();
|
let mut failed = Vec::new();
|
||||||
for (name, test) in json.as_object().unwrap() {
|
for (name, test) in json.as_object().unwrap() {
|
||||||
// sync io is usefull when something crashes in jit
|
// sync io is usefull when something crashes in jit
|
||||||
//::std::io::stdout().write(&name.as_bytes());
|
// ::std::io::stdout().write(&name.as_bytes());
|
||||||
//::std::io::stdout().write(b"\n");
|
// ::std::io::stdout().write(b"\n");
|
||||||
//::std::io::stdout().flush();
|
// ::std::io::stdout().flush();
|
||||||
let mut fail = false;
|
let mut fail = false;
|
||||||
//let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); fail = true };
|
//let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); fail = true };
|
||||||
let mut fail_unless = |cond: bool, s: &str | if !cond && !fail { failed.push(name.to_string() + ": "+ s); fail = true };
|
let mut fail_unless = |cond: bool, s: &str | if !cond && !fail {
|
||||||
|
failed.push(format!("[{}] {}: {}", vm, name.to_string(), s));
|
||||||
|
fail = true
|
||||||
|
};
|
||||||
|
|
||||||
// test env
|
// test env
|
||||||
let mut state = State::new_temp();
|
let mut state = State::new_temp();
|
||||||
@ -197,7 +209,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
info.timestamp = u256_from_json(&env["currentTimestamp"]).low_u64();
|
info.timestamp = u256_from_json(&env["currentTimestamp"]).low_u64();
|
||||||
});
|
});
|
||||||
|
|
||||||
let engine = TestEngine::new(0, VMType::Jit);
|
let engine = TestEngine::new(0, vm.clone());
|
||||||
|
|
||||||
// params
|
// params
|
||||||
let mut params = ActionParams::new();
|
let mut params = ActionParams::new();
|
||||||
@ -222,7 +234,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
let (res, callcreates) = {
|
let (res, callcreates) = {
|
||||||
let ex = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::Return(BytesRef::Flexible(&mut output)));
|
let ex = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::Return(BytesRef::Flexible(&mut output)));
|
||||||
let mut test_ext = TestExt::new(ex);
|
let mut test_ext = TestExt::new(ex);
|
||||||
let evm = Factory::default().create();
|
let evm = engine.vm_factory().create();
|
||||||
let res = evm.exec(¶ms, &mut test_ext);
|
let res = evm.exec(¶ms, &mut test_ext);
|
||||||
(res, test_ext.callcreates)
|
(res, test_ext.callcreates)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user