Skip to content

Commit

Permalink
tester -> emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
0xys committed Mar 31, 2022
1 parent ec28796 commit 1d0c696
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 35 deletions.
9 changes: 4 additions & 5 deletions src/tester/mod.rs → src/emulator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use crate::{
host::{stateful::StatefulHost, Host}
};

#[derive(Clone)]
pub struct Evm {
pub struct EvmEmulator {
scope: CallScope,
host: Rc<RefCell<dyn Host>>,

Expand Down Expand Up @@ -50,11 +49,11 @@ impl EvmResult {
}
}

impl Evm {
impl EvmEmulator {
pub fn new() -> Self {
let host = StatefulHost::new();
let host = Rc::new(RefCell::new(host));
Evm{
EvmEmulator{
scope: CallScope::default(),
host,
is_execution_cost_enabled: false,
Expand All @@ -65,7 +64,7 @@ impl Evm {
pub fn new_with(context: TxContext) -> Self {
let host = StatefulHost::new_with(context);
let host = Rc::new(RefCell::new(host));
Evm{
EvmEmulator{
scope: CallScope::default(),
host,
is_execution_cost_enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pub mod interpreter;
pub mod executor;
pub mod utils;
pub mod host;
pub mod tester;
pub mod emulator;
12 changes: 6 additions & 6 deletions tests/call.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use ethereum_types::{U256, Address};
use hex::decode;

use evmstar::tester::{
Evm,
use evmstar::emulator::{
EvmEmulator,
};
#[allow(unused_imports)]
use evmstar::model::{
Expand Down Expand Up @@ -106,7 +106,7 @@ fn test_call() {

let gas_limit = 100_000;

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down Expand Up @@ -143,7 +143,7 @@ fn test_remote_self_balance() {

let gas_limit = 100_000;

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down Expand Up @@ -179,7 +179,7 @@ fn test_remote_address() {
.clone();

let gas_limit = 100_000;
let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_deep() {
.append(OpCode::RETURN)
.clone(); // 3 * 6 + call + 3 * 2 + 2 = 24 + call[=3+2600] + 2 = 2629

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
tester.with_default_gas();

let max_depth = 50;
Expand Down
8 changes: 4 additions & 4 deletions tests/eip1283.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use evmstar::model::{
},
revision::Revision,
};
use evmstar::tester::Evm;
use evmstar::emulator::EvmEmulator;

fn default_address() -> Address { Address::from_low_u64_be(0xffffeeee) }

Expand All @@ -33,7 +33,7 @@ fn test_common(code: &str, consumed_gas: i64, gas_refund: i64) {
let code = builder.append(code).clone();
let gas_limit = i64::max_value();

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand All @@ -50,7 +50,7 @@ fn test_common_with_initial_state(code: &str, consumed_gas: i64, gas_refund: i64
let code = builder.append(code).clone();
let gas_limit = i64::max_value();

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down Expand Up @@ -147,7 +147,7 @@ fn test_eip1283_16(){// 16
let code = builder.append(code).clone();
let gas_limit = i64::max_value();

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down
4 changes: 2 additions & 2 deletions tests/eip2200.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use evmstar::model::{
},
revision::Revision,
};
use evmstar::tester::Evm;
use evmstar::emulator::EvmEmulator;

fn default_address() -> Address { Address::from_low_u64_be(0xffffeeee) }

Expand All @@ -33,7 +33,7 @@ fn test_common_with_original(code: &str, consumed_gas: i64, gas_refund: i64, ori
let code = builder.append(code).clone();
let gas_limit = i64::max_value();

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down
4 changes: 2 additions & 2 deletions tests/eip2929.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ethereum_types::{U256, Address};
use evmstar::tester::Evm;
use evmstar::emulator::EvmEmulator;

use evmstar::model::{
code::{
Expand Down Expand Up @@ -32,7 +32,7 @@ fn sstore_eip2929(code: &str, gas_used: i64, gas_refund: i64, warm: bool, origin
let code = Code::builder().append(code).clone();
let gas_limit = i64::max_value();

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down
14 changes: 7 additions & 7 deletions tests/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use evmstar::model::{
},
revision::Revision,
};
use evmstar::tester::Evm;
use evmstar::emulator::EvmEmulator;

fn address_0() -> Address {
Address::from_low_u64_be(0)
Expand Down Expand Up @@ -45,7 +45,7 @@ fn get_default_context() -> TxContext {
#[test]
fn test_eip2930_nocode() {
{
let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester
.with_default_gas()
.add_accessed_account(address_0())
Expand All @@ -57,7 +57,7 @@ fn test_eip2930_nocode() {
.expect_gas(21000 + 2400);
}
{
let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester
.with_default_gas()
.add_accessed_account(address_0())
Expand All @@ -75,7 +75,7 @@ fn test_eip2930_nocode() {
#[test]
fn test_eip2930_nocode_storage() {
{
let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester
.with_default_gas()
.add_accessed_account(address_0())
Expand All @@ -90,7 +90,7 @@ fn test_eip2930_nocode_storage() {
.expect_gas(21000 + 2400*3 + 1900);
}
{
let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester
.with_default_gas()
.add_accessed_account(address_0())
Expand Down Expand Up @@ -142,7 +142,7 @@ fn test_eip2930() {
+ 2600 // cold extcodesize
;

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester
.with_to(address_default())
.with_default_gas()
Expand Down Expand Up @@ -182,7 +182,7 @@ fn test_eip2930_sstore() {
+ 22100 // cold sstore
;

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester
.with_to(address_default())
.with_default_gas()
Expand Down
4 changes: 2 additions & 2 deletions tests/eip3529.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ethereum_types::{U256, Address};
use evmstar::tester::Evm;
use evmstar::emulator::EvmEmulator;

use evmstar::model::{
code::{
Expand Down Expand Up @@ -32,7 +32,7 @@ fn sstore_eip3529(code: &str, gas_used: i64, gas_refund: i64, warm: bool, origin
let code = Code::builder().append(code).clone();
let gas_limit = i64::max_value();

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down
12 changes: 6 additions & 6 deletions tests/revert.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ethereum_types::{U256, Address};
use evmstar::tester::Evm;
use evmstar::emulator::EvmEmulator;
use evmstar::model::{
code::{
Code, Append,
Expand Down Expand Up @@ -44,7 +44,7 @@ fn test_revert_one_level() {

let gas_limit = 100_000;

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down Expand Up @@ -73,7 +73,7 @@ fn test_revert_one_level_with_original() {

let gas_limit = 100_000;

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
let result = tester.with_to(default_address())
.with_gas_limit(gas_limit)
.with_gas_left(gas_limit)
Expand Down Expand Up @@ -170,7 +170,7 @@ fn test_multiple_revert() {
.append(OpCode::RETURN)
.clone();

let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
tester.with_default_gas();

for i in 0..max {
Expand Down Expand Up @@ -273,7 +273,7 @@ fn callrevert_contract(called_address: u64) -> Code {

#[test]
fn test_stackitem_after_revert() {
let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
tester.with_default_gas()
.with_contract_deployed2(address(1), return_contract(), U256::zero())
.with_contract_deployed2(address(2), revert_contract(), U256::zero());
Expand Down Expand Up @@ -304,7 +304,7 @@ fn test_stackitem_after_revert() {

#[test]
fn test_revert_deep() {
let mut tester = Evm::new_with(get_default_context());
let mut tester = EvmEmulator::new_with(get_default_context());
tester.with_default_gas()
// [call, call, call, return, return, return]
// |
Expand Down

0 comments on commit 1d0c696

Please sign in to comment.