Skip to content

Commit

Permalink
fix: delete print and fix selfbalance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eikix committed Oct 18, 2023
1 parent 8a9cca5 commit ce739c0
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 83 deletions.
1 change: 0 additions & 1 deletion crates/contracts/src/tests/test_kakarot_core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use contracts::tests::test_upgradeable::{
IMockContractUpgradeableDispatcherTrait
};
use contracts::tests::utils;
use debug::PrintTrait;
use eoa::externally_owned_account::ExternallyOwnedAccount;
use evm::tests::test_utils;
use starknet::{get_caller_address, testing, contract_address_const, ContractAddress, ClassHash};
Expand Down
1 change: 0 additions & 1 deletion crates/contracts/src/tests/test_upgradeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use MockContractUpgradeableV0::HasComponentImpl_upgradeable_component;
use contracts::components::upgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait};
use contracts::components::upgradeable::{upgradeable_component};
use contracts::tests::utils;
use debug::PrintTrait;
use serde::Serde;
use starknet::{deploy_syscall, ClassHash, ContractAddress, testing};

Expand Down
1 change: 0 additions & 1 deletion crates/evm/src/stack.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

//! let value = stack.pop()?;
//! ```
use debug::PrintTrait;
use evm::errors::{EVMError, STACK_OVERFLOW, STACK_UNDERFLOW, TYPE_CONVERSION_ERROR};
use nullable::{nullable_from_box, NullableTrait};
use starknet::{StorageBaseAddress, EthAddress};
Expand Down
1 change: 0 additions & 1 deletion crates/evm/src/tests/test_execution_context.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::nullable::{NullableTrait, null};
use debug::PrintTrait;
use evm::context::{
CallContext, CallContextTrait, ExecutionContext, ExecutionContextTrait, DefaultOptionSpanU8
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use evm::instructions::BlockInformationTrait;
use evm::stack::StackTrait;
use evm::tests::test_utils::setup_machine;
use starknet::testing::{set_block_timestamp, set_block_number};
use evm::tests::test_utils::{setup_machine, evm_address};
use starknet::testing::{set_block_timestamp, set_block_number, set_contract_address};
use utils::constants::CHAIN_ID;
use contracts::kakarot_core::interface::IExtendedKakarotCoreDispatcherTrait;
use contracts::tests::utils::{
deploy_kakarot_core, deploy_native_token, fund_account_with_native_token
};
use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait;

#[test]
#[available_gas(20000000)]
Expand Down Expand Up @@ -49,6 +54,71 @@ fn test_gaslimit() {
assert(machine.stack.peek().unwrap() == 0xffffff, 'stack top should be 0xffffff');
}

// *************************************************************************
// 0x47: SELFBALANCE
// *************************************************************************
#[test]
#[available_gas(5000000)]
fn test_selfbalance_eoa() {
// Given
let native_token = deploy_native_token();
let kakarot_core = deploy_kakarot_core(native_token.contract_address);
let eoa = kakarot_core.deploy_eoa(evm_address());

fund_account_with_native_token(eoa, native_token);

// And
let mut machine = setup_machine();

// When
set_contract_address(kakarot_core.contract_address);
machine.exec_selfbalance();

// Then
assert(machine.stack.peek().unwrap() == native_token.balanceOf(eoa), 'wrong balance');
}

#[test]
#[available_gas(5000000)]
fn test_selfbalance_zero() {
// Given
let native_token = deploy_native_token();
let kakarot_core = deploy_kakarot_core(native_token.contract_address);

// And
let mut machine = setup_machine();

// When
set_contract_address(kakarot_core.contract_address);
machine.exec_selfbalance();

// Then
assert(machine.stack.peek().unwrap() == 0x00, 'wrong balance');
}

// TODO: implement balance once contracts accounts can be deployed
#[ignore]
#[test]
#[available_gas(5000000)]
fn test_selfbalance_contract_account() {
// Given
let native_token = deploy_native_token();
let kakarot_core = deploy_kakarot_core(native_token.contract_address);
// TODO: deploy contract account
// and fund it

// And
let mut machine = setup_machine();

// When
set_contract_address(kakarot_core.contract_address);
machine.exec_selfbalance();

// Then
panic_with_felt252('Not implemented yet');
}


#[test]
#[available_gas(20000000)]
fn test_basefee() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use debug::PrintTrait;
use evm::instructions::ComparisonAndBitwiseOperationsTrait;
use evm::stack::StackTrait;
use evm::tests::test_utils::setup_machine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use debug::PrintTrait;
use evm::instructions::DuplicationOperationsTrait;
use evm::stack::Stack;
use evm::stack::StackTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use contracts::kakarot_core::interface::IExtendedKakarotCoreDispatcherTrait;
use contracts::tests::utils::{
deploy_kakarot_core, deploy_native_token, fund_account_with_native_token
};
use debug::U256PrintImpl;
use evm::errors::{EVMError, TYPE_CONVERSION_ERROR, RETURNDATA_OUT_OF_BOUNDS_ERROR};
use evm::instructions::EnvironmentInformationTrait;
use evm::machine::{Machine, MachineCurrentContextTrait};
Expand Down Expand Up @@ -69,7 +68,6 @@ fn test_balance_eoa() {
machine.exec_balance();

// Then
machine.stack.peek().unwrap().print();
assert(machine.stack.peek().unwrap() == native_token.balanceOf(eoa), 'wrong balance');
}

Expand All @@ -89,7 +87,6 @@ fn test_balance_zero() {
machine.exec_balance();

// Then
machine.stack.peek().unwrap().print();
assert(machine.stack.peek().unwrap() == 0x00, 'wrong balance');
}

Expand All @@ -113,7 +110,6 @@ fn test_balance_contract_account() {
machine.exec_balance();

// Then
machine.stack.peek().unwrap().print();
panic_with_felt252('Not implemented yet');
}

Expand Down Expand Up @@ -714,70 +710,3 @@ fn test_returndata_copy(dest_offset: u32, offset: u32, mut size: u32) {
assert(results.span() == return_data.slice(offset, size), 'wrong data value');
}


// *************************************************************************
// 0x31: SELFBALANCE
// *************************************************************************
#[test]
#[available_gas(5000000)]
fn test_selfbalance_eoa() {
// Given
let native_token = deploy_native_token();
let kakarot_core = deploy_kakarot_core(native_token.contract_address);
let eoa = kakarot_core.deploy_eoa(evm_address());

fund_account_with_native_token(eoa, native_token);

// And
let mut machine = setup_machine();

// When
set_contract_address(kakarot_core.contract_address);
machine.exec_balance();

// Then
machine.stack.peek().unwrap().print();
assert(machine.stack.peek().unwrap() == native_token.balanceOf(eoa), 'wrong balance');
}

#[test]
#[available_gas(5000000)]
fn test_selfbalance_zero() {
// Given
let native_token = deploy_native_token();
let kakarot_core = deploy_kakarot_core(native_token.contract_address);

// And
let mut machine = setup_machine();

// When
set_contract_address(kakarot_core.contract_address);
machine.exec_balance();

// Then
machine.stack.peek().unwrap().print();
assert(machine.stack.peek().unwrap() == 0x00, 'wrong balance');
}

// TODO: implement balance once contracts accounts can be deployed
#[ignore]
#[test]
#[available_gas(5000000)]
fn test_selfbalance_contract_account() {
// Given
let native_token = deploy_native_token();
let kakarot_core = deploy_kakarot_core(native_token.contract_address);
// TODO: deploy contract account
// and fund it

// And
let mut machine = setup_machine();

// When
set_contract_address(kakarot_core.contract_address);
machine.exec_balance();

// Then
machine.stack.peek().unwrap().print();
panic_with_felt252('Not implemented yet');
}
4 changes: 2 additions & 2 deletions crates/evm/src/tests/test_memory.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use evm::memory::{MemoryTrait, InternalMemoryTrait, MemoryPrintTrait};
use evm::memory::{MemoryTrait, InternalMemoryTrait};
use integer::BoundedInt;
use utils::constants::{POW_2_8, POW_2_56, POW_2_64, POW_2_120};
use utils::{math::Exponentiation, math::WrappingExponentiation, helpers, helpers::SpanExtTrait};

mod internal {
use evm::memory::{MemoryTrait, InternalMemoryTrait, MemoryPrintTrait};
use evm::memory::{MemoryTrait, InternalMemoryTrait};
use utils::{math::Exponentiation, helpers};

fn load_should_load_an_element_from_the_memory_with_offset_stored_with_store_n(
Expand Down
1 change: 0 additions & 1 deletion crates/utils/src/helpers.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use debug::PrintTrait;
use starknet::{EthAddress, EthAddressIntoFelt252};
use cmp::min;
use utils::constants::{
Expand Down
1 change: 0 additions & 1 deletion crates/utils/src/tests/test_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use utils::helpers::{
SpanExtension, SpanExtTrait, ArrayExtension, ArrayExtTrait, U256Trait, BytesSerde
};
use utils::helpers::{ByteArrayExTrait};
use debug::PrintTrait;

#[test]
#[available_gas(2000000000)]
Expand Down

0 comments on commit ce739c0

Please sign in to comment.