Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Oct 30, 2024
1 parent 3cee7e5 commit c04a00f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
5 changes: 4 additions & 1 deletion crates/vm/levm/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{
constants::TX_BASE_COST, db::{Cache, Db}, operations::Operation, vm::{Account, AccountInfo, Environment, VM}
constants::TX_BASE_COST,
db::{Cache, Db},
operations::Operation,
vm::{Account, AccountInfo, Environment, VM},
};
use bytes::Bytes;
use ethereum_types::{Address, U256};
Expand Down
8 changes: 5 additions & 3 deletions crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,14 @@ impl VM {

if self.is_create() {
// If address is already in db, there's an error
let new_address_acc = self.db.get_account_info(self.call_frames.first().unwrap().to);
let new_address_acc = self
.db
.get_account_info(self.call_frames.first().unwrap().to);
if !new_address_acc.is_empty() {
return Err(VMError::AddressAlreadyOccupied);
}
}
}

let sender_account = match self.cache.get_mut_account(self.env.origin) {
Some(acc) => acc,
None => return Err(VMError::AddressDoesNotMatchAnAccount),
Expand Down
32 changes: 16 additions & 16 deletions crates/vm/levm/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4013,10 +4013,10 @@ fn origin_op() {
&Account::default().with_bytecode(ops_to_bytecde(&operations)),
);

let env = Environment::default_from_address(address_that_has_the_code);
let mut env = Environment::default_from_address(msg_sender);

let mut vm = VM::new(
Some(Address::from_low_u64_be(42)),
Some(address_that_has_the_code),
env,
Default::default(),
Default::default(),
Expand All @@ -4026,7 +4026,6 @@ fn origin_op() {
None,
);


let mut current_call_frame = vm.call_frames.pop().unwrap();
vm.execute(&mut current_call_frame);

Expand Down Expand Up @@ -4082,10 +4081,10 @@ fn address_op() {
&Account::default().with_bytecode(ops_to_bytecde(&operations)),
);

let env = Environment::default_from_address(address_that_has_the_code);
let env = Environment::default_from_address(Address::from_low_u64_be(42));

let mut vm = VM::new(
Some(Address::from_low_u64_be(42)),
Some(address_that_has_the_code),
env,
Default::default(),
Default::default(),
Expand Down Expand Up @@ -4128,10 +4127,10 @@ fn selfbalance_op() {
.with_balance(balance),
);

let env = Environment::default_from_address(address_that_has_the_code);
let env = Environment::default_from_address(Address::from_low_u64_be(42));

let mut vm = VM::new(
Some(Address::from_low_u64_be(42)),
Some(address_that_has_the_code),
env,
Default::default(),
Default::default(),
Expand Down Expand Up @@ -4168,12 +4167,12 @@ fn callvalue_op() {
&Account::default().with_bytecode(ops_to_bytecde(&operations)),
);

let env = Environment::default_from_address(address_that_has_the_code);
let env = Environment::default_from_address(Address::from_low_u64_be(42));

let mut vm = VM::new(
Some(Address::from_low_u64_be(42)),
Some(address_that_has_the_code),
env,
Default::default(),
value,
Default::default(),
Box::new(db),
cache,
Expand Down Expand Up @@ -4207,10 +4206,10 @@ fn codesize_op() {
&Account::default().with_bytecode(ops_to_bytecde(&operations)),
);

let env = Environment::default_from_address(address_that_has_the_code);
let env = Environment::default_from_address(Address::from_low_u64_be(42));

let mut vm = VM::new(
Some(Address::from_low_u64_be(42)),
Some(address_that_has_the_code),
env,
Default::default(),
Default::default(),
Expand Down Expand Up @@ -4248,10 +4247,11 @@ fn gasprice_op() {
&Account::default().with_bytecode(ops_to_bytecde(&operations)),
);

let env = Environment::default_from_address(address_that_has_the_code);
let mut env = Environment::default_from_address(Address::from_low_u64_be(42));
env.gas_price = U256::from_str_radix("9876", 16).unwrap();

let mut vm = VM::new(
Some(Address::from_low_u64_be(42)),
Some(address_that_has_the_code),
env,
Default::default(),
Default::default(),
Expand Down Expand Up @@ -4306,10 +4306,10 @@ fn codecopy_op() {
&Account::default().with_bytecode(ops_to_bytecde(&operations)),
);

let env = Environment::default_from_address(address_that_has_the_code);
let env = Environment::default_from_address(Address::from_low_u64_be(42));

let mut vm = VM::new(
Some(Address::from_low_u64_be(42)),
Some(address_that_has_the_code),
env,
Default::default(),
Default::default(),
Expand Down

0 comments on commit c04a00f

Please sign in to comment.