From 6577d742a827dc01710630fe6e13986de517ff1b Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Wed, 13 Jan 2016 12:18:54 +0100 Subject: [PATCH] Rewriting tests to support JIT and Interpreter --- src/evm/tests.rs | 96 ++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/src/evm/tests.rs b/src/evm/tests.rs index 9ec466359..d226e1bd0 100644 --- a/src/evm/tests.rs +++ b/src/evm/tests.rs @@ -1,6 +1,6 @@ use common::*; use evm; -use evm::{Ext, Schedule, Factory}; +use evm::{Ext, Schedule}; struct FakeLogEntry { topics: Vec, @@ -85,16 +85,21 @@ impl Ext for FakeExt { } } -#[test] -#[cfg(feature = "jit")] -fn test_add_jit() { - test_add(Box::new(super::jit::JitEvm)); -} -#[test] -fn test_add_interpreter() { - test_add(Box::new(super::interpreter::Interpreter)); -} +macro_rules! evm_test( + ($name_test: ident: $name_jit: ident, $name_int: ident) => { + #[test] + #[cfg(feature = "jit")] + fn $name_jit() { + $name_test(Box::new(super::jit::JitEvm)); + } + #[test] + fn $name_int() { + $name_test(Box::new(super::interpreter::Interpreter)); + } + } +); +evm_test!{test_add: test_add_jit, test_add_int} fn test_add(vm : Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap(); @@ -113,8 +118,8 @@ fn test_add(vm : Box) { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").unwrap()); } -#[test] -fn test_sha3() { +evm_test!{test_sha3: test_sha3_jit, test_sha3_int} +fn test_sha3(vm: Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let code = "6000600020600055".from_hex().unwrap(); @@ -125,7 +130,6 @@ fn test_sha3() { let mut ext = FakeExt::new(); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -133,8 +137,8 @@ fn test_sha3() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap()); } -#[test] -fn test_address() { +evm_test!{test_address: test_address_jit, test_address_int} +fn test_address(vm: Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let code = "30600055".from_hex().unwrap(); @@ -145,7 +149,6 @@ fn test_address() { let mut ext = FakeExt::new(); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -153,8 +156,8 @@ fn test_address() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("0000000000000000000000000f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap()); } -#[test] -fn test_origin() { +evm_test!{test_origin: test_origin_jit, test_origin_int} +fn test_origin(vm: Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let origin = Address::from_str("cd1722f2947def4cf144679da39c4c32bdc35681").unwrap(); let code = "32600055".from_hex().unwrap(); @@ -167,7 +170,6 @@ fn test_origin() { let mut ext = FakeExt::new(); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -175,8 +177,8 @@ fn test_origin() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("000000000000000000000000cd1722f2947def4cf144679da39c4c32bdc35681").unwrap()); } -#[test] -fn test_sender() { +evm_test!{test_sender: test_sender_jit, test_sender_int} +fn test_sender(vm: Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let sender = Address::from_str("cd1722f2947def4cf144679da39c4c32bdc35681").unwrap(); let code = "33600055".from_hex().unwrap(); @@ -189,7 +191,6 @@ fn test_sender() { let mut ext = FakeExt::new(); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -197,8 +198,8 @@ fn test_sender() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("000000000000000000000000cd1722f2947def4cf144679da39c4c32bdc35681").unwrap()); } -#[test] -fn test_extcodecopy() { +evm_test!{test_extcodecopy: test_extcodecopy_jit, test_extcodecopy_int} +fn test_extcodecopy(vm: Box) { // 33 - sender // 3b - extcodesize // 60 00 - push 0 @@ -224,7 +225,6 @@ fn test_extcodecopy() { ext.codes.insert(sender, sender_code); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -232,8 +232,8 @@ fn test_extcodecopy() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("6005600055000000000000000000000000000000000000000000000000000000").unwrap()); } -#[test] -fn test_log_empty() { +evm_test!{test_log_empty: test_log_empty_jit, test_log_empty_int} +fn test_log_empty(vm: Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let code = "60006000a0".from_hex().unwrap(); @@ -244,7 +244,6 @@ fn test_log_empty() { let mut ext = FakeExt::new(); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -254,8 +253,8 @@ fn test_log_empty() { assert_eq!(ext.logs[0].data, vec![]); } -#[test] -fn test_log_sender() { +evm_test!{test_log_sender: test_log_sender_jit, test_log_sender_int} +fn test_log_sender(vm: Box) { // 60 ff - push ff // 60 00 - push 00 // 53 - mstore @@ -276,7 +275,6 @@ fn test_log_sender() { let mut ext = FakeExt::new(); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -287,8 +285,8 @@ fn test_log_sender() { assert_eq!(ext.logs[0].data, "ff00000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap()); } -#[test] -fn test_blockhash() { +evm_test!{test_blockhash: test_blockhash_jit, test_blockhash_int} +fn test_blockhash(vm: Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let code = "600040600055".from_hex().unwrap(); let blockhash = H256::from_str("123400000000000000000000cd1722f2947def4cf144679da39c4c32bdc35681").unwrap(); @@ -301,7 +299,6 @@ fn test_blockhash() { ext.blockhashes.insert(U256::zero(), blockhash.clone()); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -309,8 +306,8 @@ fn test_blockhash() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &blockhash); } -#[test] -fn test_calldataload() { +evm_test!{test_calldataload: test_calldataload_jit, test_calldataload_int} +fn test_calldataload(vm: Box) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let code = "600135600055".from_hex().unwrap(); let data = "0123ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23".from_hex().unwrap(); @@ -323,7 +320,6 @@ fn test_calldataload() { let mut ext = FakeExt::new(); let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -332,8 +328,8 @@ fn test_calldataload() { } -#[test] -fn test_author() { +evm_test!{test_author: test_author_jit, test_author_int} +fn test_author(vm: Box) { let author = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let code = "41600055".from_hex().unwrap(); @@ -344,7 +340,6 @@ fn test_author() { ext.info.author = author; let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -352,8 +347,8 @@ fn test_author() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("0000000000000000000000000f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap()); } -#[test] -fn test_timestamp() { +evm_test!{test_timestamp: test_timestamp_jit, test_timestamp_int} +fn test_timestamp(vm: Box) { let timestamp = 0x1234; let code = "42600055".from_hex().unwrap(); @@ -364,7 +359,6 @@ fn test_timestamp() { ext.info.timestamp = timestamp; let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -372,8 +366,8 @@ fn test_timestamp() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("0000000000000000000000000000000000000000000000000000000000001234").unwrap()); } -#[test] -fn test_number() { +evm_test!{test_number: test_number_jit, test_number_int} +fn test_number(vm: Box) { let number = 0x1234; let code = "43600055".from_hex().unwrap(); @@ -384,7 +378,6 @@ fn test_number() { ext.info.number = number; let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -392,8 +385,8 @@ fn test_number() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("0000000000000000000000000000000000000000000000000000000000001234").unwrap()); } -#[test] -fn test_difficulty() { +evm_test!{test_difficulty: test_difficulty_jit, test_difficulty_int} +fn test_difficulty(vm: Box) { let difficulty = U256::from(0x1234); let code = "44600055".from_hex().unwrap(); @@ -404,7 +397,6 @@ fn test_difficulty() { ext.info.difficulty = difficulty; let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; @@ -412,8 +404,8 @@ fn test_difficulty() { assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("0000000000000000000000000000000000000000000000000000000000001234").unwrap()); } -#[test] -fn test_gas_limit() { +evm_test!{test_gas_limit: test_gas_limit_jit, test_gas_limit_int} +fn test_gas_limit(vm: Box) { let gas_limit = U256::from(0x1234); let code = "45600055".from_hex().unwrap(); @@ -424,10 +416,10 @@ fn test_gas_limit() { ext.info.gas_limit = gas_limit; let gas_left = { - let vm = Factory::create(); vm.exec(¶ms, &mut ext).unwrap() }; assert_eq!(gas_left, U256::from(79_995)); assert_eq!(ext.store.get(&H256::new()).unwrap(), &H256::from_str("0000000000000000000000000000000000000000000000000000000000001234").unwrap()); } +