From 8cf7aebc2901830530e57137c4ef70316125b2c0 Mon Sep 17 00:00:00 2001 From: Mathieu <60658558+enitrat@users.noreply.github.com> Date: Fri, 24 May 2024 14:25:09 +0200 Subject: [PATCH] chore: bump cairo (#794) * chore: bump cairo * refactor: tests structure * move test_utils to tests/ * refactor test utils * fmt * fix tests utils --- .tool-versions | 2 +- Scarb.toml | 4 +- crates/contracts/Scarb.toml | 1 + .../contracts/src/kakarot_core/kakarot.cairo | 6 +- crates/contracts/src/lib.cairo | 4 +- .../contracts/src/{tests => }/test_data.cairo | 0 .../{src/tests.cairo => tests/lib.cairo} | 2 - .../{src => }/tests/test_cairo1_helpers.cairo | 0 .../tests/test_contract_account.cairo | 8 +- .../contracts/{src => }/tests/test_eoa.cairo | 20 +- .../{src => }/tests/test_kakarot_core.cairo | 133 ++++---- .../{src => }/tests/test_ownable.cairo | 12 +- .../{src => }/tests/test_upgradeable.cairo | 2 +- crates/contracts/tests/test_utils.cairo | 2 + .../tests/test_utils/contracts_utils.cairo | 186 +++++++++++ .../tests/test_utils/evm_utils.cairo} | 27 +- crates/evm/src/gas.cairo | 2 +- crates/evm/src/lib.cairo | 4 - .../evm/{src/tests.cairo => tests/lib.cairo} | 0 .../{src => }/tests/test_create_helpers.cairo | 4 +- crates/evm/{src => }/tests/test_gas.cairo | 2 +- .../{src => }/tests/test_instructions.cairo | 0 .../test_block_information.cairo | 10 +- .../test_comparison_operations.cairo | 2 +- .../test_duplication_operations.cairo | 2 +- .../test_environment_information.cairo | 12 +- .../test_exchange_operations.cairo | 2 +- .../test_logging_operations.cairo | 2 +- .../test_memory_operations.cairo | 4 +- .../test_push_operations.cairo | 2 +- .../tests/test_instructions/test_sha3.cairo | 2 +- .../test_stop_and_arithmetic_operations.cairo | 3 +- .../test_system_operations.cairo | 17 +- crates/evm/{src => }/tests/test_machine.cairo | 3 +- crates/evm/{src => }/tests/test_memory.cairo | 0 crates/evm/{src => }/tests/test_model.cairo | 8 +- .../{src => }/tests/test_model/test_vm.cairo | 0 .../{src => }/tests/test_precompiles.cairo | 0 .../tests/test_precompiles/test_blake2f.cairo | 4 +- .../tests/test_precompiles/test_data.cairo | 0 .../test_data/test_data_blake2f.cairo | 0 .../test_data/test_data_modexp.cairo | 0 .../test_precompiles/test_ec_recover.cairo | 4 +- .../test_precompiles/test_identity.cairo | 4 +- .../tests/test_precompiles/test_modexp.cairo | 6 +- .../test_precompiles/test_p256verify.cairo | 4 +- .../tests/test_precompiles/test_sha256.cairo | 4 +- crates/evm/{src => }/tests/test_stack.cairo | 0 .../tests/test_starknet_backend.cairo | 10 +- crates/evm/{src => }/tests/test_state.cairo | 81 +++-- crates/evm/tests/test_utils.cairo | 2 + .../tests/test_utils/contracts_utils.cairo} | 6 +- crates/evm/tests/test_utils/evm_utils.cairo | 296 ++++++++++++++++++ crates/utils/src/eth_transaction.cairo | 4 +- crates/utils/src/lib.cairo | 3 +- crates/utils/src/{tests => }/test_data.cairo | 0 .../{src/tests.cairo => tests/lib.cairo} | 1 - .../utils/{src => }/tests/test_address.cairo | 2 +- .../tests/test_eth_transaction.cairo | 7 +- .../utils/{src => }/tests/test_helpers.cairo | 0 crates/utils/{src => }/tests/test_i256.cairo | 0 crates/utils/{src => }/tests/test_math.cairo | 0 .../utils/{src => }/tests/test_modexp.cairo | 0 .../tests/test_modexp/test_arith.cairo | 2 +- .../tests/test_modexp/test_mpnat.cairo | 1 - crates/utils/{src => }/tests/test_rlp.cairo | 0 .../{src => }/tests/test_serialization.cairo | 0 crates/utils/{src => }/tests/test_set.cairo | 0 .../utils/{src => }/tests/test_storage.cairo | 0 .../utils/{src => }/tests/test_traits.cairo | 5 +- 70 files changed, 720 insertions(+), 216 deletions(-) rename crates/contracts/src/{tests => }/test_data.cairo (100%) rename crates/contracts/{src/tests.cairo => tests/lib.cairo} (90%) rename crates/contracts/{src => }/tests/test_cairo1_helpers.cairo (100%) rename crates/contracts/{src => }/tests/test_contract_account.cairo (90%) rename crates/contracts/{src => }/tests/test_eoa.cairo (97%) rename crates/contracts/{src => }/tests/test_kakarot_core.cairo (69%) rename crates/contracts/{src => }/tests/test_ownable.cairo (93%) rename crates/contracts/{src => }/tests/test_upgradeable.cairo (98%) create mode 100644 crates/contracts/tests/test_utils.cairo create mode 100644 crates/contracts/tests/test_utils/contracts_utils.cairo rename crates/{evm/src/tests/test_utils.cairo => contracts/tests/test_utils/evm_utils.cairo} (88%) rename crates/evm/{src/tests.cairo => tests/lib.cairo} (100%) rename crates/evm/{src => }/tests/test_create_helpers.cairo (63%) rename crates/evm/{src => }/tests/test_gas.cairo (98%) rename crates/evm/{src => }/tests/test_instructions.cairo (100%) rename crates/evm/{src => }/tests/test_instructions/test_block_information.cairo (97%) rename crates/evm/{src => }/tests/test_instructions/test_comparison_operations.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_duplication_operations.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_environment_information.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_exchange_operations.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_logging_operations.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_memory_operations.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_push_operations.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_sha3.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_stop_and_arithmetic_operations.cairo (99%) rename crates/evm/{src => }/tests/test_instructions/test_system_operations.cairo (98%) rename crates/evm/{src => }/tests/test_machine.cairo (98%) rename crates/evm/{src => }/tests/test_memory.cairo (100%) rename crates/evm/{src => }/tests/test_model.cairo (98%) rename crates/evm/{src => }/tests/test_model/test_vm.cairo (100%) rename crates/evm/{src => }/tests/test_precompiles.cairo (100%) rename crates/evm/{src => }/tests/test_precompiles/test_blake2f.cairo (96%) rename crates/evm/{src => }/tests/test_precompiles/test_data.cairo (100%) rename crates/evm/{src => }/tests/test_precompiles/test_data/test_data_blake2f.cairo (100%) rename crates/evm/{src => }/tests/test_precompiles/test_data/test_data_modexp.cairo (100%) rename crates/evm/{src => }/tests/test_precompiles/test_ec_recover.cairo (95%) rename crates/evm/{src => }/tests/test_precompiles/test_identity.cairo (90%) rename crates/evm/{src => }/tests/test_precompiles/test_modexp.cairo (94%) rename crates/evm/{src => }/tests/test_precompiles/test_p256verify.cairo (97%) rename crates/evm/{src => }/tests/test_precompiles/test_sha256.cairo (92%) rename crates/evm/{src => }/tests/test_stack.cairo (100%) rename crates/evm/{src => }/tests/test_starknet_backend.cairo (79%) rename crates/evm/{src => }/tests/test_state.cairo (81%) create mode 100644 crates/evm/tests/test_utils.cairo rename crates/{contracts/src/tests/test_utils.cairo => evm/tests/test_utils/contracts_utils.cairo} (96%) create mode 100644 crates/evm/tests/test_utils/evm_utils.cairo rename crates/utils/src/{tests => }/test_data.cairo (100%) rename crates/utils/{src/tests.cairo => tests/lib.cairo} (92%) rename crates/utils/{src => }/tests/test_address.cairo (94%) rename crates/utils/{src => }/tests/test_eth_transaction.cairo (99%) rename crates/utils/{src => }/tests/test_helpers.cairo (100%) rename crates/utils/{src => }/tests/test_i256.cairo (100%) rename crates/utils/{src => }/tests/test_math.cairo (100%) rename crates/utils/{src => }/tests/test_modexp.cairo (100%) rename crates/utils/{src => }/tests/test_modexp/test_arith.cairo (99%) rename crates/utils/{src => }/tests/test_modexp/test_mpnat.cairo (99%) rename crates/utils/{src => }/tests/test_rlp.cairo (100%) rename crates/utils/{src => }/tests/test_serialization.cairo (100%) rename crates/utils/{src => }/tests/test_set.cairo (100%) rename crates/utils/{src => }/tests/test_storage.cairo (100%) rename crates/utils/{src => }/tests/test_traits.cairo (76%) diff --git a/.tool-versions b/.tool-versions index e3d7ed99e..c3d1a2dc7 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.5.3 +scarb 2.6.3 starknet-foundry 0.12.0 diff --git a/Scarb.toml b/Scarb.toml index b0e3f3d2d..93dfd85d3 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -4,14 +4,14 @@ members = ["crates/*"] [workspace.package] description = "Kakarot is an (zk)-Ethereum Virtual Machine implementation written in Cairo." documentation = "https://www.kakarot.org/" -cairo-version = "2.4.0" +cairo-version = "2.6.3" version = "0.1.0" readme = "README.md" repository = "https://github.com/kkrt-labs/kakarot-ssj/" license-file = "LICENSE" [workspace.dependencies] -starknet = "2.4.0-rc6" +starknet = "2.6.3" [workspace.tool.fmt] sort-module-level-items = true diff --git a/crates/contracts/Scarb.toml b/crates/contracts/Scarb.toml index f0fae36c0..0fc4755d3 100644 --- a/crates/contracts/Scarb.toml +++ b/crates/contracts/Scarb.toml @@ -12,6 +12,7 @@ openzeppelin = { path = "../openzeppelin" } utils = { path = "../utils" } alexandria_storage = { path = "../alexandria_storage" } + [tool] fmt.workspace = true diff --git a/crates/contracts/src/kakarot_core/kakarot.cairo b/crates/contracts/src/kakarot_core/kakarot.cairo index a7e9f6b71..2db8e5b67 100644 --- a/crates/contracts/src/kakarot_core/kakarot.cairo +++ b/crates/contracts/src/kakarot_core/kakarot.cairo @@ -165,7 +165,7 @@ pub mod KakarotCore { let origin = Address { evm: origin, starknet: self.compute_starknet_address(origin) }; - let TransactionResult{success, return_data, gas_used, state: _ } = self + let TransactionResult { success, return_data, gas_used, state: _ } = self .process_transaction(origin, tx); (success, return_data, gas_used) @@ -180,7 +180,7 @@ pub mod KakarotCore { evm: account.get_evm_address(), starknet: starknet_caller_address }; - let TransactionResult{success, return_data, gas_used, mut state } = self + let TransactionResult { success, return_data, gas_used, mut state } = self .process_transaction(origin, tx); starknet_backend::commit(ref state).expect('Committing state failed'); (success, return_data, gas_used) @@ -323,7 +323,7 @@ pub mod KakarotCore { loop { match access_list.pop_front() { Option::Some(access_list_item) => { - let AccessListItem{ethereum_address, storage_keys: _ } = + let AccessListItem { ethereum_address, storage_keys: _ } = *access_list_item; let storage_keys = access_list_item.to_storage_keys(); diff --git a/crates/contracts/src/lib.cairo b/crates/contracts/src/lib.cairo index 247561672..32edd4993 100644 --- a/crates/contracts/src/lib.cairo +++ b/crates/contracts/src/lib.cairo @@ -6,9 +6,7 @@ mod errors; // Kakarot smart contract mod kakarot_core; - -#[cfg(test)] -mod tests; +mod test_data; // Account transparent proxy mod uninitialized_account; diff --git a/crates/contracts/src/tests/test_data.cairo b/crates/contracts/src/test_data.cairo similarity index 100% rename from crates/contracts/src/tests/test_data.cairo rename to crates/contracts/src/test_data.cairo diff --git a/crates/contracts/src/tests.cairo b/crates/contracts/tests/lib.cairo similarity index 90% rename from crates/contracts/src/tests.cairo rename to crates/contracts/tests/lib.cairo index 1f757aa89..b2901d72b 100644 --- a/crates/contracts/src/tests.cairo +++ b/crates/contracts/tests/lib.cairo @@ -1,8 +1,6 @@ mod test_cairo1_helpers; mod test_contract_account; -mod test_data; - mod test_eoa; mod test_kakarot_core; diff --git a/crates/contracts/src/tests/test_cairo1_helpers.cairo b/crates/contracts/tests/test_cairo1_helpers.cairo similarity index 100% rename from crates/contracts/src/tests/test_cairo1_helpers.cairo rename to crates/contracts/tests/test_cairo1_helpers.cairo diff --git a/crates/contracts/src/tests/test_contract_account.cairo b/crates/contracts/tests/test_contract_account.cairo similarity index 90% rename from crates/contracts/src/tests/test_contract_account.cairo rename to crates/contracts/tests/test_contract_account.cairo index 69c846e34..341c12c63 100644 --- a/crates/contracts/src/tests/test_contract_account.cairo +++ b/crates/contracts/tests/test_contract_account.cairo @@ -1,7 +1,9 @@ use contracts::account_contract::{AccountContract, IAccountDispatcher, IAccountDispatcherTrait}; -use contracts::tests::test_data::counter_evm_bytecode; -use contracts::tests::test_utils::{setup_contracts_for_testing, deploy_contract_account}; -use evm::tests::test_utils::{ca_address, native_token}; +use contracts::test_data::counter_evm_bytecode; +use contracts_tests::test_utils::contracts_utils::{ + setup_contracts_for_testing, deploy_contract_account +}; +use contracts_tests::test_utils::evm_utils::{ca_address, native_token}; #[test] fn test_ca_deploy() { diff --git a/crates/contracts/src/tests/test_eoa.cairo b/crates/contracts/tests/test_eoa.cairo similarity index 97% rename from crates/contracts/src/tests/test_eoa.cairo rename to crates/contracts/tests/test_eoa.cairo index d088749fb..ce88defd2 100644 --- a/crates/contracts/src/tests/test_eoa.cairo +++ b/crates/contracts/tests/test_eoa.cairo @@ -6,24 +6,24 @@ mod test_external_owned_account { IKakarotCore, KakarotCore, KakarotCore::KakarotCoreInternal, interface::IExtendedKakarotCoreDispatcherTrait }; - use contracts::tests::test_data::{counter_evm_bytecode, eip_2930_rlp_encoded_counter_inc_tx,}; - use contracts::tests::test_upgradeable::{ - IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait, - MockContractUpgradeableV1 + use contracts::test_data::{counter_evm_bytecode, eip_2930_rlp_encoded_counter_inc_tx,}; + use contracts_test::test_utils::evm_utils::{ + kakarot_address, evm_address, other_evm_address, other_starknet_address, eoa_address, + chain_id, tx_gas_limit, gas_price, VMBuilderTrait }; - use contracts::tests::test_utils::{ + use contracts_test::test_utils::evm_utils::{ setup_contracts_for_testing, deploy_eoa, deploy_contract_account, pop_log, pop_log_debug, fund_account_with_native_token, call_transaction }; + use contracts_tests::test_upgradeable::{ + IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait, + MockContractUpgradeableV1 + }; use core::array::SpanTrait; use core::box::BoxTrait; use core::starknet::account::{Call}; use evm::model::{Address, AddressTrait}; - use evm::tests::test_utils::{ - kakarot_address, evm_address, other_evm_address, other_starknet_address, eoa_address, - chain_id, tx_gas_limit, gas_price, VMBuilderTrait - }; use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait; use starknet::class_hash::Felt252TryIntoClassHash; use starknet::testing::{set_caller_address, set_contract_address, set_signature, set_chain_id}; @@ -36,7 +36,7 @@ mod test_external_owned_account { }; use utils::helpers::{U8SpanExTrait, u256_to_bytes_array}; use utils::serialization::{serialize_bytes, serialize_transaction_signature}; - use utils::tests::test_data::{legacy_rlp_encoded_tx, eip_2930_encoded_tx, eip_1559_encoded_tx}; + use utils::test_data::{legacy_rlp_encoded_tx, eip_2930_encoded_tx, eip_1559_encoded_tx}; #[test] diff --git a/crates/contracts/src/tests/test_kakarot_core.cairo b/crates/contracts/tests/test_kakarot_core.cairo similarity index 69% rename from crates/contracts/src/tests/test_kakarot_core.cairo rename to crates/contracts/tests/test_kakarot_core.cairo index 9dd0bc1b5..2fce054b4 100644 --- a/crates/contracts/src/tests/test_kakarot_core.cairo +++ b/crates/contracts/tests/test_kakarot_core.cairo @@ -7,66 +7,66 @@ use contracts::kakarot_core::interface::{ use contracts::kakarot_core::{ interface::IExtendedKakarotCoreDispatcherImpl, KakarotCore, KakarotCore::{KakarotCoreInternal}, }; -use contracts::tests::test_data::{deploy_counter_calldata, counter_evm_bytecode}; -use contracts::tests::test_upgradeable::{ +use contracts::test_data::{deploy_counter_calldata, counter_evm_bytecode}; +use contracts::uninitialized_account::UninitializedAccount; +use contracts_tests::test_upgradeable::{ MockContractUpgradeableV1, IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait }; -use contracts::tests::test_utils as contract_utils; -use contracts::uninitialized_account::UninitializedAccount; +use contracts_tests::test_utils::contracts_utils; +use contracts_tests::test_utils::evm_utils as evm_utils; +use contracts_tests::test_utils::evm_utils::{sequencer_evm_address, chain_id}; use core::num::traits::Zero; use core::option::OptionTrait; use core::traits::TryInto; use evm::model::{Address}; -use evm::tests::test_utils::{sequencer_evm_address, chain_id}; -use evm::tests::test_utils; use starknet::{testing, contract_address_const, ContractAddress, EthAddress, ClassHash}; use utils::eth_transaction::{EthereumTransaction, EthereumTransactionTrait, LegacyTransaction}; use utils::helpers::{EthAddressExTrait, u256_to_bytes_array}; #[test] fn test_kakarot_core_owner() { - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); - assert(kakarot_core.owner() == test_utils::other_starknet_address(), 'wrong owner') + assert(kakarot_core.owner() == evm_utils::other_starknet_address(), 'wrong owner') } #[test] fn test_kakarot_core_transfer_ownership() { - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); - assert(kakarot_core.owner() == test_utils::other_starknet_address(), 'wrong owner'); - testing::set_contract_address(test_utils::other_starknet_address()); - kakarot_core.transfer_ownership(test_utils::starknet_address()); - assert(kakarot_core.owner() == test_utils::starknet_address(), 'wrong owner') + assert(kakarot_core.owner() == evm_utils::other_starknet_address(), 'wrong owner'); + testing::set_contract_address(evm_utils::other_starknet_address()); + kakarot_core.transfer_ownership(evm_utils::starknet_address()); + assert(kakarot_core.owner() == evm_utils::starknet_address(), 'wrong owner') } #[test] fn test_kakarot_core_renounce_ownership() { - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); - assert(kakarot_core.owner() == test_utils::other_starknet_address(), 'wrong owner'); - testing::set_contract_address(test_utils::other_starknet_address()); + assert(kakarot_core.owner() == evm_utils::other_starknet_address(), 'wrong owner'); + testing::set_contract_address(evm_utils::other_starknet_address()); kakarot_core.renounce_ownership(); assert(kakarot_core.owner() == contract_address_const::<0x00>(), 'wrong owner') } #[test] fn test_kakarot_core_chain_id() { - contract_utils::setup_contracts_for_testing(); + contracts_utils::setup_contracts_for_testing(); - assert(chain_id() == contract_utils::chain_id(), 'wrong chain id'); + assert(chain_id() == contracts_utils::chain_id(), 'wrong chain id'); } #[test] fn test_kakarot_core_set_native_token() { - let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (native_token, kakarot_core) = contracts_utils::setup_contracts_for_testing(); assert(kakarot_core.get_native_token() == native_token.contract_address, 'wrong native_token'); - testing::set_contract_address(test_utils::other_starknet_address()); + testing::set_contract_address(evm_utils::other_starknet_address()); kakarot_core.set_native_token(contract_address_const::<0xdead>()); assert( kakarot_core.get_native_token() == contract_address_const::<0xdead>(), @@ -76,11 +76,11 @@ fn test_kakarot_core_set_native_token() { #[test] fn test_kakarot_core_deploy_eoa() { - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); let eoa_starknet_address = kakarot_core - .deploy_externally_owned_account(test_utils::evm_address()); + .deploy_externally_owned_account(evm_utils::evm_address()); - let event = contract_utils::pop_log::< + let event = contracts_utils::pop_log::< KakarotCore::AccountDeployed >(kakarot_core.contract_address) .unwrap(); @@ -90,17 +90,16 @@ fn test_kakarot_core_deploy_eoa() { #[test] fn test_kakarot_core_eoa_mapping() { // Given - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); assert( - kakarot_core.address_registry(test_utils::evm_address()).is_zero(), - 'should be uninitialized' + kakarot_core.address_registry(evm_utils::evm_address()).is_zero(), 'should be uninitialized' ); let expected_eoa_starknet_address = kakarot_core - .deploy_externally_owned_account(test_utils::evm_address()); + .deploy_externally_owned_account(evm_utils::evm_address()); // When - let address = kakarot_core.address_registry(test_utils::evm_address()); + let address = kakarot_core.address_registry(evm_utils::evm_address()); // Then assert_eq!(address, expected_eoa_starknet_address); @@ -108,16 +107,16 @@ fn test_kakarot_core_eoa_mapping() { let another_sn_address: ContractAddress = 0xbeef.try_into().unwrap(); let mut kakarot_state = KakarotCore::unsafe_new_contract_state(); - kakarot_state.set_address_registry(test_utils::evm_address(), another_sn_address); + kakarot_state.set_address_registry(evm_utils::evm_address(), another_sn_address); - let address = kakarot_core.address_registry(test_utils::evm_address()); + let address = kakarot_core.address_registry(evm_utils::evm_address()); assert_eq!(address, another_sn_address) } #[test] fn test_kakarot_core_compute_starknet_address() { - let evm_address = test_utils::evm_address(); - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let evm_address = evm_utils::evm_address(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); let expected_starknet_address = kakarot_core.deploy_externally_owned_account(evm_address); let actual_starknet_address = kakarot_core.compute_starknet_address(evm_address); @@ -126,11 +125,11 @@ fn test_kakarot_core_compute_starknet_address() { #[test] fn test_kakarot_core_upgrade_contract() { - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); let class_hash: ClassHash = MockContractUpgradeableV1::TEST_CLASS_HASH.try_into().unwrap(); - testing::set_contract_address(test_utils::other_starknet_address()); + testing::set_contract_address(evm_utils::other_starknet_address()); kakarot_core.upgrade(class_hash); let version = IMockContractUpgradeableDispatcher { @@ -144,19 +143,19 @@ fn test_kakarot_core_upgrade_contract() { #[available_gas(2000000000000000000)] fn test_eth_send_transaction_non_deploy_tx() { // Given - let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (native_token, kakarot_core) = contracts_utils::setup_contracts_for_testing(); - let evm_address = test_utils::evm_address(); + let evm_address = evm_utils::evm_address(); let eoa = kakarot_core.deploy_externally_owned_account(evm_address); - contract_utils::fund_account_with_native_token( + contracts_utils::fund_account_with_native_token( eoa, native_token, 0xfffffffffffffffffffffffffff ); let counter_address = 'counter_contract'.try_into().unwrap(); - contract_utils::deploy_contract_account(counter_address, counter_evm_bytecode()); + contracts_utils::deploy_contract_account(counter_address, counter_evm_bytecode()); - let gas_limit = test_utils::tx_gas_limit(); - let gas_price = test_utils::gas_price(); + let gas_limit = evm_utils::tx_gas_limit(); + let gas_price = evm_utils::gas_price(); let value = 0; // Then @@ -164,7 +163,7 @@ fn test_eth_send_transaction_non_deploy_tx() { let data_get_tx = array![0x6d, 0x4c, 0xe6, 0x3c].span(); // check counter value is 0 before doing inc - let tx = contract_utils::call_transaction( + let tx = contracts_utils::call_transaction( chain_id(), Option::Some(counter_address), data_get_tx ); let (_, return_data) = kakarot_core @@ -197,7 +196,7 @@ fn test_eth_send_transaction_non_deploy_tx() { let data_get_tx = array![0x6d, 0x4c, 0xe6, 0x3c].span(); // check counter value is 1 - let tx = contract_utils::call_transaction( + let tx = contracts_utils::call_transaction( chain_id(), Option::Some(counter_address), data_get_tx ); let (_, _) = kakarot_core @@ -212,23 +211,23 @@ fn test_eth_send_transaction_non_deploy_tx() { #[test] fn test_eth_call() { // Given - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); - let evm_address = test_utils::evm_address(); + let evm_address = evm_utils::evm_address(); kakarot_core.deploy_externally_owned_account(evm_address); - let account = contract_utils::deploy_contract_account( - test_utils::other_evm_address(), counter_evm_bytecode() + let account = contracts_utils::deploy_contract_account( + evm_utils::other_evm_address(), counter_evm_bytecode() ); let counter = IAccountDispatcher { contract_address: account.starknet }; counter.write_storage(0, 1); - let to = Option::Some(test_utils::other_evm_address()); + let to = Option::Some(evm_utils::other_evm_address()); // selector: function get() let calldata = array![0x6d, 0x4c, 0xe6, 0x3c].span(); // When - let tx = contract_utils::call_transaction(chain_id(), to, calldata); + let tx = contracts_utils::call_transaction(chain_id(), to, calldata); let (success, return_data) = kakarot_core .eth_call(origin: evm_address, tx: EthereumTransaction::LegacyTransaction(tx)); @@ -240,23 +239,23 @@ fn test_eth_call() { #[test] fn test_process_transaction() { // Given - let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (native_token, kakarot_core) = contracts_utils::setup_contracts_for_testing(); - let evm_address = test_utils::evm_address(); + let evm_address = evm_utils::evm_address(); let eoa = kakarot_core.deploy_externally_owned_account(evm_address); - contract_utils::fund_account_with_native_token( + contracts_utils::fund_account_with_native_token( eoa, native_token, 0xfffffffffffffffffffffffffff ); let chain_id = chain_id(); - let _account = contract_utils::deploy_contract_account( - test_utils::other_evm_address(), counter_evm_bytecode() + let _account = contracts_utils::deploy_contract_account( + evm_utils::other_evm_address(), counter_evm_bytecode() ); let nonce = 0; - let to = Option::Some(test_utils::other_evm_address()); - let gas_limit = test_utils::tx_gas_limit(); - let gas_price = test_utils::gas_price(); + let to = Option::Some(evm_utils::other_evm_address()); + let gas_limit = evm_utils::tx_gas_limit(); + let gas_price = evm_utils::gas_price(); let value = 0; // selector: function get() let calldata = array![0x6d, 0x4c, 0xe6, 0x3c].span(); @@ -281,16 +280,16 @@ fn test_process_transaction() { #[test] fn test_eth_send_transaction_deploy_tx() { // Given - let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (native_token, kakarot_core) = contracts_utils::setup_contracts_for_testing(); - let evm_address = test_utils::evm_address(); + let evm_address = evm_utils::evm_address(); let eoa = kakarot_core.deploy_externally_owned_account(evm_address); - contract_utils::fund_account_with_native_token( + contracts_utils::fund_account_with_native_token( eoa, native_token, 0xfffffffffffffffffffffffffff ); - let gas_limit = test_utils::tx_gas_limit(); - let gas_price = test_utils::gas_price(); + let gas_limit = evm_utils::tx_gas_limit(); + let gas_price = evm_utils::gas_price(); let value = 0; // When @@ -344,7 +343,7 @@ fn test_eth_send_transaction_deploy_tx() { #[test] fn test_account_class_hash() { - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); let class_hash = kakarot_core.uninitialized_account_class_hash(); @@ -353,11 +352,11 @@ fn test_account_class_hash() { ); let new_class_hash: ClassHash = MockContractUpgradeableV1::TEST_CLASS_HASH.try_into().unwrap(); - testing::set_contract_address(test_utils::other_starknet_address()); + testing::set_contract_address(evm_utils::other_starknet_address()); kakarot_core.set_account_class_hash(new_class_hash); assert(kakarot_core.uninitialized_account_class_hash() == new_class_hash, 'wrong class hash'); - let event = contract_utils::pop_log::< + let event = contracts_utils::pop_log::< KakarotCore::AccountClassHashChange >(kakarot_core.contract_address) .unwrap(); @@ -369,18 +368,18 @@ fn test_account_class_hash() { #[test] fn test_account_contract_class_hash() { - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); let class_hash = kakarot_core.get_account_contract_class_hash(); assert(class_hash == TEST_CLASS_HASH.try_into().unwrap(), 'wrong class hash'); let new_class_hash: ClassHash = MockContractUpgradeableV1::TEST_CLASS_HASH.try_into().unwrap(); - testing::set_contract_address(test_utils::other_starknet_address()); + testing::set_contract_address(evm_utils::other_starknet_address()); kakarot_core.set_account_contract_class_hash(new_class_hash); assert(kakarot_core.get_account_contract_class_hash() == new_class_hash, 'wrong class hash'); - let event = contract_utils::pop_log::< + let event = contracts_utils::pop_log::< KakarotCore::EOAClassHashChange >(kakarot_core.contract_address) .unwrap(); diff --git a/crates/contracts/src/tests/test_ownable.cairo b/crates/contracts/tests/test_ownable.cairo similarity index 93% rename from crates/contracts/src/tests/test_ownable.cairo rename to crates/contracts/tests/test_ownable.cairo index 0cd5311f2..fce1dc8f4 100644 --- a/crates/contracts/src/tests/test_ownable.cairo +++ b/crates/contracts/tests/test_ownable.cairo @@ -1,9 +1,8 @@ use contracts::components::ownable::{ownable_component}; -use contracts::tests::test_utils::constants::{ZERO, OWNER, OTHER}; -use contracts::tests::test_utils; +use contracts_tests::test_utils::contracts_utils::constants::{ZERO, OWNER, OTHER}; +use contracts_tests::test_utils::contracts_utils; use core::num::traits::Zero; - use ownable_component::{InternalImpl, OwnableImpl}; use starknet::ContractAddress; use starknet::testing; @@ -46,7 +45,7 @@ impl TestingStateImpl of TestingStateTrait { fn new_with(owner: ContractAddress) -> TestingState { let mut ownable: TestingState = Default::default(); ownable.initializer(owner); - test_utils::drop_event(ZERO()); + contracts_utils::drop_event(ZERO()); ownable } } @@ -169,8 +168,9 @@ fn test_renounce_ownership_from_nonowner() { fn assert_event_ownership_transferred(previous_owner: ContractAddress, new_owner: ContractAddress) { - let event = test_utils::pop_log::(ZERO()).unwrap(); + let event = contracts_utils::pop_log::(ZERO()) + .unwrap(); assert(event.previous_owner == previous_owner, 'Invalid `previous_owner`'); assert(event.new_owner == new_owner, 'Invalid `new_owner`'); - test_utils::assert_no_events_left(ZERO()); + contracts_utils::assert_no_events_left(ZERO()); } diff --git a/crates/contracts/src/tests/test_upgradeable.cairo b/crates/contracts/tests/test_upgradeable.cairo similarity index 98% rename from crates/contracts/src/tests/test_upgradeable.cairo rename to crates/contracts/tests/test_upgradeable.cairo index c40a717b0..09d571c54 100644 --- a/crates/contracts/src/tests/test_upgradeable.cairo +++ b/crates/contracts/tests/test_upgradeable.cairo @@ -1,7 +1,7 @@ use MockContractUpgradeableV0::HasComponentImpl_upgradeable_component; use contracts::components::upgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait}; use contracts::components::upgradeable::{upgradeable_component}; -use contracts::tests::test_utils; +use contracts_tests::test_utils::evm_utils; use core::serde::Serde; use starknet::{deploy_syscall, ClassHash, ContractAddress, testing}; diff --git a/crates/contracts/tests/test_utils.cairo b/crates/contracts/tests/test_utils.cairo new file mode 100644 index 000000000..78b7eaa95 --- /dev/null +++ b/crates/contracts/tests/test_utils.cairo @@ -0,0 +1,2 @@ +mod contracts_utils; +mod evm_utils; diff --git a/crates/contracts/tests/test_utils/contracts_utils.cairo b/crates/contracts/tests/test_utils/contracts_utils.cairo new file mode 100644 index 000000000..f1ea77fba --- /dev/null +++ b/crates/contracts/tests/test_utils/contracts_utils.cairo @@ -0,0 +1,186 @@ +use contracts::account_contract::{AccountContract}; +use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; +use contracts::kakarot_core::{ + interface::IExtendedKakarotCoreDispatcher, interface::IExtendedKakarotCoreDispatcherTrait, + KakarotCore +}; +use contracts::uninitialized_account::{UninitializedAccount}; + +use contracts_tests::test_utils::evm_utils::{ + ca_address, other_starknet_address, chain_id, sequencer_evm_address +}; +use core::fmt::Debug; +use core::result::ResultTrait; +use evm::backend::starknet_backend; +use evm::model::{Address}; +use openzeppelin::token::erc20::ERC20; +use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; +use starknet::{ + testing, contract_address_const, EthAddress, ContractAddress, deploy_syscall, + get_contract_address +}; +use utils::constants::BLOCK_GAS_LIMIT; +use utils::eth_transaction::LegacyTransaction; + +/// Pop the earliest unpopped logged event for the contract as the requested type +/// and checks there's no more data left on the event, preventing unaccounted params. +/// This function also removes the first key from the event. This is because indexed +/// params are set as event keys, but the first event key is always set as the +/// event ID. +/// Author: Openzeppelin https://github.com/OpenZeppelin/cairo-contracts +fn pop_log, impl TEvent: starknet::Event>(address: ContractAddress) -> Option { + let (mut keys, mut data) = testing::pop_log_raw(address)?; + + // Remove the event ID from the keys + keys.pop_front().expect('pop_log popfront failed'); + + let ret = starknet::Event::deserialize(ref keys, ref data); + ret +} + +fn pop_log_debug, +Debug, impl TEvent: starknet::Event>( + address: ContractAddress +) -> Option { + let (mut keys, mut data) = testing::pop_log_raw(address)?; + + // Remove the event ID from the keys + keys.pop_front().expect('pop_log popfront failed'); + + let ret = starknet::Event::deserialize(ref keys, ref data); + + ret +} + +/// Author: Openzeppelin https://github.com/OpenZeppelin/cairo-contracts +fn drop_event(address: ContractAddress) { + testing::pop_log_raw(address).unwrap(); +} + +/// Author: Openzeppelin https://github.com/OpenZeppelin/cairo-contracts +fn assert_no_events_left(address: ContractAddress) { + assert(testing::pop_log_raw(address).is_none(), 'Events remaining on queue'); +} + +mod constants { + use starknet::{EthAddress, testing, contract_address_const, ContractAddress}; + fn ZERO() -> ContractAddress { + contract_address_const::<0>() + } + + fn OWNER() -> ContractAddress { + contract_address_const::<0xabde1>() + } + + fn OTHER() -> ContractAddress { + contract_address_const::<0xe1145>() + } + + pub(crate) fn EVM_ADDRESS() -> EthAddress { + 0xc0ffee.try_into().unwrap() + } + + pub(crate) fn ETH_BANK() -> ContractAddress { + contract_address_const::<0x777>() + } +} + +fn deploy_native_token() -> IERC20CamelDispatcher { + let calldata: Array = array![ + 'STARKNET_ETH', 'ETH', 0x00, 0xfffffffffffffffffffffffffff, constants::ETH_BANK().into() + ]; + let maybe_address = deploy_syscall( + ERC20::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false + ); + match maybe_address { + Result::Ok((contract_address, _)) => { IERC20CamelDispatcher { contract_address } }, + Result::Err(err) => panic(err) + } +} + +fn deploy_kakarot_core( + native_token: ContractAddress, mut eoas: Span +) -> IExtendedKakarotCoreDispatcher { + let mut calldata: Array = array![ + other_starknet_address().into(), + native_token.into(), + AccountContract::TEST_CLASS_HASH.try_into().unwrap(), + UninitializedAccount::TEST_CLASS_HASH.try_into().unwrap(), + 'coinbase', + BLOCK_GAS_LIMIT.into(), + ]; + + Serde::serialize(@eoas, ref calldata); + + let maybe_address = deploy_syscall( + KakarotCore::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false + ); + + match maybe_address { + Result::Ok(( + contract_address, _ + )) => { IExtendedKakarotCoreDispatcher { contract_address } }, + Result::Err(err) => panic(err) + } +} + +pub fn deploy_contract_account(evm_address: EthAddress, bytecode: Span) -> Address { + let ca_address = starknet_backend::deploy(evm_address).expect('failed to deploy CA'); + IAccountDispatcher { contract_address: ca_address.starknet }.set_nonce(1); + IAccountDispatcher { contract_address: ca_address.starknet }.write_bytecode(bytecode); + ca_address +} + +fn deploy_eoa(eoa_address: EthAddress) -> IAccountDispatcher { + let kakarot_address = get_contract_address(); + let calldata: Span = array![kakarot_address.into(), eoa_address.into()].span(); + + let (starknet_address, _) = deploy_syscall( + UninitializedAccount::TEST_CLASS_HASH.try_into().unwrap(), + eoa_address.into(), + calldata, + true + ) + .expect('failed to deploy EOA'); + + let eoa = IAccountDispatcher { contract_address: starknet_address }; + eoa +} + +fn call_transaction( + chain_id: u128, destination: Option, calldata: Span +) -> LegacyTransaction { + LegacyTransaction { + chain_id, nonce: 0, gas_price: 0, gas_limit: 500000000, destination, amount: 0, calldata + } +} + +fn fund_account_with_native_token( + contract_address: ContractAddress, native_token: IERC20CamelDispatcher, amount: u256, +) { + let current_contract = get_contract_address(); + testing::set_contract_address(constants::ETH_BANK()); + native_token.transfer(contract_address, amount); + testing::set_contract_address(current_contract); +} + +pub(crate) fn setup_contracts_for_testing() -> ( + IERC20CamelDispatcher, IExtendedKakarotCoreDispatcher +) { + let native_token = deploy_native_token(); + let kakarot_core = deploy_kakarot_core( + native_token.contract_address, array![sequencer_evm_address()].span() + ); + + // We drop the first event of Kakarot Core, as it is the initializer from Ownable, + // triggered in the constructor. + drop_event(kakarot_core.contract_address); + + let sequencer: EthAddress = sequencer_evm_address(); + + let sequencer_sn_address = kakarot_core.address_registry(sequencer); + // We drop the event of the EOA deployment + drop_event(kakarot_core.contract_address); + testing::set_sequencer_address(sequencer_sn_address); + testing::set_contract_address(kakarot_core.contract_address); + return (native_token, kakarot_core); +} diff --git a/crates/evm/src/tests/test_utils.cairo b/crates/contracts/tests/test_utils/evm_utils.cairo similarity index 88% rename from crates/evm/src/tests/test_utils.cairo rename to crates/contracts/tests/test_utils/evm_utils.cairo index 8cff069ba..bc7813692 100644 --- a/crates/evm/src/tests/test_utils.cairo +++ b/crates/contracts/tests/test_utils/evm_utils.cairo @@ -1,8 +1,8 @@ use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; -use contracts::tests::test_utils::{deploy_contract_account}; use contracts::uninitialized_account::UninitializedAccount; use core::nullable::{match_nullable, FromNullableResult}; use core::traits::TryInto; +use evm::backend::starknet_backend; use evm::errors::{EVMError}; use evm::model::vm::{VM, VMTrait}; @@ -15,6 +15,31 @@ use starknet::{ }; use utils::constants; +pub fn deploy_contract_account(evm_address: EthAddress, bytecode: Span) -> Address { + let ca_address = starknet_backend::deploy(evm_address).expect('failed to deploy CA'); + IAccountDispatcher { contract_address: ca_address.starknet }.set_nonce(1); + IAccountDispatcher { contract_address: ca_address.starknet }.write_bytecode(bytecode); + ca_address +} + + +fn deploy_eoa(eoa_address: EthAddress) -> IAccountDispatcher { + let kakarot_address = get_contract_address(); + let calldata: Span = array![kakarot_address.into(), eoa_address.into()].span(); + + let (starknet_address, _) = deploy_syscall( + UninitializedAccount::TEST_CLASS_HASH.try_into().unwrap(), + eoa_address.into(), + calldata, + true + ) + .expect('failed to deploy EOA'); + + let eoa = IAccountDispatcher { contract_address: starknet_address }; + eoa +} + + #[derive(Destruct)] struct VMBuilder { vm: VM diff --git a/crates/evm/src/gas.cairo b/crates/evm/src/gas.cairo index 5e6adbc5a..8a5899555 100644 --- a/crates/evm/src/gas.cairo +++ b/crates/evm/src/gas.cairo @@ -227,7 +227,7 @@ fn calculate_intrinsic_gas_cost(tx: @EthereumTransaction) -> u128 { loop { match access_list.pop_front() { Option::Some(access_list_item) => { - let AccessListItem{ethereum_address: _, storage_keys } = access_list_item; + let AccessListItem { ethereum_address: _, storage_keys } = access_list_item; access_list_cost += ACCESS_LIST_ADDRESS + (ACCESS_LIST_STORAGE_KEY * (*storage_keys).len().into()); }, diff --git a/crates/evm/src/lib.cairo b/crates/evm/src/lib.cairo index 20f2b9b6a..329672c9a 100644 --- a/crates/evm/src/lib.cairo +++ b/crates/evm/src/lib.cairo @@ -31,7 +31,3 @@ mod stack; // Local state mod state; - -// tests -#[cfg(test)] -mod tests; diff --git a/crates/evm/src/tests.cairo b/crates/evm/tests/lib.cairo similarity index 100% rename from crates/evm/src/tests.cairo rename to crates/evm/tests/lib.cairo diff --git a/crates/evm/src/tests/test_create_helpers.cairo b/crates/evm/tests/test_create_helpers.cairo similarity index 63% rename from crates/evm/src/tests/test_create_helpers.cairo rename to crates/evm/tests/test_create_helpers.cairo index 499c4b747..75aea519f 100644 --- a/crates/evm/src/tests/test_create_helpers.cairo +++ b/crates/evm/tests/test_create_helpers.cairo @@ -1,6 +1,6 @@ -use contracts::tests::test_data::counter_evm_bytecode; +use contracts::test_data::counter_evm_bytecode; use evm::create_helpers::CreateHelpers; -use evm::tests::test_utils::{VMBuilderTrait}; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait}; use starknet::EthAddress; use utils::address::{compute_contract_address, compute_create2_contract_address}; //TODO: test create helpers diff --git a/crates/evm/src/tests/test_gas.cairo b/crates/evm/tests/test_gas.cairo similarity index 98% rename from crates/evm/src/tests/test_gas.cairo rename to crates/evm/tests/test_gas.cairo index a0babc2bd..356f0c48a 100644 --- a/crates/evm/src/tests/test_gas.cairo +++ b/crates/evm/tests/test_gas.cairo @@ -4,7 +4,7 @@ use evm::gas::{ calculate_intrinsic_gas_cost, calculate_memory_gas_cost, ACCESS_LIST_ADDRESS, ACCESS_LIST_STORAGE_KEY }; -use evm::tests::test_utils::evm_address; +use evm_tests::test_utils::evm_utils::evm_address; use starknet::EthAddress; use utils::eth_transaction::{ EthereumTransaction, LegacyTransaction, AccessListTransaction, EthereumTransactionTrait, diff --git a/crates/evm/src/tests/test_instructions.cairo b/crates/evm/tests/test_instructions.cairo similarity index 100% rename from crates/evm/src/tests/test_instructions.cairo rename to crates/evm/tests/test_instructions.cairo diff --git a/crates/evm/src/tests/test_instructions/test_block_information.cairo b/crates/evm/tests/test_instructions/test_block_information.cairo similarity index 97% rename from crates/evm/src/tests/test_instructions/test_block_information.cairo rename to crates/evm/tests/test_instructions/test_block_information.cairo index 648075891..83dc96005 100644 --- a/crates/evm/src/tests/test_instructions/test_block_information.cairo +++ b/crates/evm/tests/test_instructions/test_block_information.cairo @@ -1,14 +1,14 @@ use contracts::kakarot_core::interface::{ IExtendedKakarotCoreDispatcher, IExtendedKakarotCoreDispatcherTrait }; - -use contracts::tests::test_utils::{ - setup_contracts_for_testing, fund_account_with_native_token, deploy_contract_account, -}; use core::result::ResultTrait; use evm::instructions::BlockInformationTrait; use evm::stack::StackTrait; -use evm::tests::test_utils::{evm_address, VMBuilderTrait, tx_gas_limit, gas_price}; + +use evm_tests::test_utils::contracts_utils::{ + setup_contracts_for_testing, fund_account_with_native_token, deploy_contract_account, +}; +use evm_tests::test_utils::evm_utils::{evm_address, VMBuilderTrait, tx_gas_limit, gas_price}; use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait; use starknet::testing::{ set_block_timestamp, set_block_number, set_contract_address, set_sequencer_address, diff --git a/crates/evm/src/tests/test_instructions/test_comparison_operations.cairo b/crates/evm/tests/test_instructions/test_comparison_operations.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_comparison_operations.cairo rename to crates/evm/tests/test_instructions/test_comparison_operations.cairo index c0f6f5f59..045339757 100644 --- a/crates/evm/src/tests/test_instructions/test_comparison_operations.cairo +++ b/crates/evm/tests/test_instructions/test_comparison_operations.cairo @@ -1,7 +1,7 @@ use core::integer::BoundedInt; use evm::instructions::ComparisonAndBitwiseOperationsTrait; use evm::stack::StackTrait; -use evm::tests::test_utils::VMBuilderTrait; +use evm_tests::test_utils::evm_utils::VMBuilderTrait; #[test] fn test_eq_same_pair() { diff --git a/crates/evm/src/tests/test_instructions/test_duplication_operations.cairo b/crates/evm/tests/test_instructions/test_duplication_operations.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_duplication_operations.cairo rename to crates/evm/tests/test_instructions/test_duplication_operations.cairo index 729c15b0b..dd7b327b5 100644 --- a/crates/evm/src/tests/test_instructions/test_duplication_operations.cairo +++ b/crates/evm/tests/test_instructions/test_duplication_operations.cairo @@ -2,7 +2,7 @@ use core::integer::BoundedInt; use evm::instructions::DuplicationOperationsTrait; use evm::stack::Stack; use evm::stack::StackTrait; -use evm::tests::test_utils::VMBuilderTrait; +use evm_tests::test_utils::evm_utils::VMBuilderTrait; // ensures all values start from index `from` upto index `to` of stack are `0x0` diff --git a/crates/evm/src/tests/test_instructions/test_environment_information.cairo b/crates/evm/tests/test_instructions/test_environment_information.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_environment_information.cairo rename to crates/evm/tests/test_instructions/test_environment_information.cairo index d2376d749..a5ef3d876 100644 --- a/crates/evm/src/tests/test_instructions/test_environment_information.cairo +++ b/crates/evm/tests/test_instructions/test_environment_information.cairo @@ -1,8 +1,5 @@ use contracts::kakarot_core::{interface::IExtendedKakarotCoreDispatcherImpl, KakarotCore}; -use contracts::tests::test_data::counter_evm_bytecode; -use contracts::tests::test_utils::{ - setup_contracts_for_testing, fund_account_with_native_token, deploy_contract_account -}; +use contracts::test_data::counter_evm_bytecode; use core::integer::u32_overflowing_add; use evm::errors::{EVMError, TYPE_CONVERSION_ERROR}; use evm::instructions::EnvironmentInformationTrait; @@ -12,7 +9,10 @@ use evm::model::vm::{VM, VMTrait}; use evm::model::{Account}; use evm::stack::StackTrait; use evm::state::StateTrait; -use evm::tests::test_utils::{ +use evm_tests::test_utils::contracts_utils::{ + setup_contracts_for_testing, fund_account_with_native_token, deploy_contract_account +}; +use evm_tests::test_utils::evm_utils::{ VMBuilderTrait, evm_address, origin, callvalue, native_token, other_address, gas_price, tx_gas_limit }; @@ -917,7 +917,7 @@ fn test_exec_extcodehash_precompile() { // // The bytecode remains empty, and we expect the empty hash in return // let mut ca_address = deploy_contract_account(evm_address, array![].span()); // let account = Account { -// +// // address: ca_address, // code: array![].span(), // nonce: 1, diff --git a/crates/evm/src/tests/test_instructions/test_exchange_operations.cairo b/crates/evm/tests/test_instructions/test_exchange_operations.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_exchange_operations.cairo rename to crates/evm/tests/test_instructions/test_exchange_operations.cairo index 5742507a9..b4c4a090b 100644 --- a/crates/evm/src/tests/test_instructions/test_exchange_operations.cairo +++ b/crates/evm/tests/test_instructions/test_exchange_operations.cairo @@ -1,7 +1,7 @@ use core::array::ArrayTrait; use evm::instructions::exchange_operations::ExchangeOperationsTrait; use evm::stack::StackTrait; -use evm::tests::test_utils::VMBuilderTrait; +use evm_tests::test_utils::evm_utils::VMBuilderTrait; #[test] diff --git a/crates/evm/src/tests/test_instructions/test_logging_operations.cairo b/crates/evm/tests/test_instructions/test_logging_operations.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_logging_operations.cairo rename to crates/evm/tests/test_instructions/test_logging_operations.cairo index 4b53b744e..4125e6904 100644 --- a/crates/evm/src/tests/test_instructions/test_logging_operations.cairo +++ b/crates/evm/tests/test_instructions/test_logging_operations.cairo @@ -5,7 +5,7 @@ use evm::instructions::LoggingOperationsTrait; use evm::memory::MemoryTrait; use evm::stack::StackTrait; use evm::state::StateTrait; -use evm::tests::test_utils::{VMBuilderTrait}; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait}; use utils::helpers::u256_to_bytes_array; #[test] diff --git a/crates/evm/src/tests/test_instructions/test_memory_operations.cairo b/crates/evm/tests/test_instructions/test_memory_operations.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_memory_operations.cairo rename to crates/evm/tests/test_instructions/test_memory_operations.cairo index c8acbcd14..8450c6998 100644 --- a/crates/evm/src/tests/test_instructions/test_memory_operations.cairo +++ b/crates/evm/tests/test_instructions/test_memory_operations.cairo @@ -1,5 +1,4 @@ use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; -use contracts::tests::test_utils::{setup_contracts_for_testing, deploy_contract_account}; use core::integer::BoundedInt; use core::result::ResultTrait; use evm::backend::starknet_backend::fetch_original_storage; @@ -11,7 +10,8 @@ use evm::model::vm::{VM, VMTrait}; use evm::model::{Account, AccountTrait}; use evm::stack::StackTrait; use evm::state::{StateTrait, compute_storage_address}; -use evm::tests::test_utils::{evm_address, VMBuilderTrait}; +use evm_tests::test_utils::contracts_utils::{setup_contracts_for_testing, deploy_contract_account}; +use evm_tests::test_utils::evm_utils::{evm_address, VMBuilderTrait}; use starknet::get_contract_address; #[test] diff --git a/crates/evm/src/tests/test_instructions/test_push_operations.cairo b/crates/evm/tests/test_instructions/test_push_operations.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_push_operations.cairo rename to crates/evm/tests/test_instructions/test_push_operations.cairo index 81562fbb7..8f51e625e 100644 --- a/crates/evm/src/tests/test_instructions/test_push_operations.cairo +++ b/crates/evm/tests/test_instructions/test_push_operations.cairo @@ -1,6 +1,6 @@ use evm::instructions::PushOperationsTrait; use evm::stack::StackTrait; -use evm::tests::test_utils::{VMBuilderTrait}; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait}; fn get_n_0xFF(mut n: u8) -> Span { let mut array: Array = ArrayTrait::new(); diff --git a/crates/evm/src/tests/test_instructions/test_sha3.cairo b/crates/evm/tests/test_instructions/test_sha3.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_sha3.cairo rename to crates/evm/tests/test_instructions/test_sha3.cairo index ae1bc4040..28efed6c9 100644 --- a/crates/evm/src/tests/test_instructions/test_sha3.cairo +++ b/crates/evm/tests/test_instructions/test_sha3.cairo @@ -3,7 +3,7 @@ use evm::instructions::Sha3Trait; use evm::instructions::sha3::internal; use evm::memory::{InternalMemoryTrait, MemoryTrait}; use evm::stack::StackTrait; -use evm::tests::test_utils::VMBuilderTrait; +use evm_tests::test_utils::evm_utils::VMBuilderTrait; #[test] fn test_exec_sha3_size_0_offset_0() { diff --git a/crates/evm/src/tests/test_instructions/test_stop_and_arithmetic_operations.cairo b/crates/evm/tests/test_instructions/test_stop_and_arithmetic_operations.cairo similarity index 99% rename from crates/evm/src/tests/test_instructions/test_stop_and_arithmetic_operations.cairo rename to crates/evm/tests/test_instructions/test_stop_and_arithmetic_operations.cairo index 13bac7a65..907222557 100644 --- a/crates/evm/src/tests/test_instructions/test_stop_and_arithmetic_operations.cairo +++ b/crates/evm/tests/test_instructions/test_stop_and_arithmetic_operations.cairo @@ -3,7 +3,7 @@ use core::result::ResultTrait; use evm::instructions::StopAndArithmeticOperationsTrait; use evm::model::vm::{VM, VMTrait}; use evm::stack::StackTrait; -use evm::tests::test_utils::VMBuilderTrait; +use evm_tests::test_utils::evm_utils::VMBuilderTrait; #[test] @@ -467,4 +467,3 @@ fn test_exec_signextend_on_negative() { vm.stack.peek().unwrap() == 0x01, 'stack top should be 0' ); // The 241-th bit of x is 0, so all bits before t are switched to 0 } - diff --git a/crates/evm/src/tests/test_instructions/test_system_operations.cairo b/crates/evm/tests/test_instructions/test_system_operations.cairo similarity index 98% rename from crates/evm/src/tests/test_instructions/test_system_operations.cairo rename to crates/evm/tests/test_instructions/test_system_operations.cairo index 00c5d0771..1f81ae3e1 100644 --- a/crates/evm/src/tests/test_instructions/test_system_operations.cairo +++ b/crates/evm/tests/test_instructions/test_system_operations.cairo @@ -1,9 +1,5 @@ use contracts::kakarot_core::interface::IExtendedKakarotCoreDispatcherTrait; -use contracts::tests::test_data::{storage_evm_bytecode, storage_evm_initcode}; -use contracts::tests::test_eoa::test_external_owned_account::deploy_eoa; -use contracts::tests::test_utils::{ - fund_account_with_native_token, setup_contracts_for_testing, deploy_contract_account -}; +use contracts::test_data::{storage_evm_bytecode, storage_evm_initcode}; use core::result::ResultTrait; use core::traits::TryInto; use evm::backend::starknet_backend; @@ -18,7 +14,11 @@ use evm::model::vm::{VM, VMTrait}; use evm::model::{AccountTrait, Address, Transfer}; use evm::stack::StackTrait; use evm::state::{StateTrait, State}; -use evm::tests::test_utils::{ +use evm_tests::test_utils::contracts_utils::{ + fund_account_with_native_token, setup_contracts_for_testing, deploy_contract_account +}; +use evm_tests::test_utils::evm_utils::deploy_eoa; +use evm_tests::test_utils::evm_utils::{ VMBuilderTrait, initialize_contract_account, native_token, evm_address, test_address, other_evm_address, }; @@ -485,8 +485,8 @@ fn test_exec_create_no_value_transfer() { vm.exec_create().unwrap(); EVMTrait::execute_code(ref vm); - // computed using `compute_create_address` script - // run `bun run compute_create_address` -> CREATE -> EthAddress = evm_address() -> nonce = 1 + // computed using `compute_create_address` script + // run `bun run compute_create_address` -> CREATE -> EthAddress = evm_address() -> nonce = 1 let account = vm .env .state @@ -681,4 +681,3 @@ fn test_exec_selfdestruct_add_transfer_post_selfdestruct() { assert(sender_balance == 0, 'sender wrong balance'); assert(ca_balance == 150, 'ca wrong balance'); } - diff --git a/crates/evm/src/tests/test_machine.cairo b/crates/evm/tests/test_machine.cairo similarity index 98% rename from crates/evm/src/tests/test_machine.cairo rename to crates/evm/tests/test_machine.cairo index 1e2742483..d73290950 100644 --- a/crates/evm/src/tests/test_machine.cairo +++ b/crates/evm/tests/test_machine.cairo @@ -1,7 +1,7 @@ use evm::errors::DebugEVMError; use evm::errors::{EVMError, READ_SYSCALL_FAILED}; use evm::model::vm::{VM, VMTrait}; -use evm::tests::test_utils::{ +use evm_tests::test_utils::evm_utils::{ tx_gas_limit, evm_address, starknet_address, VMBuilderTrait, test_address, gas_price }; @@ -86,4 +86,3 @@ fn test_return_data() { let return_data = vm.return_data(); assert(return_data.len() == 0, 'wrong length'); } - diff --git a/crates/evm/src/tests/test_memory.cairo b/crates/evm/tests/test_memory.cairo similarity index 100% rename from crates/evm/src/tests/test_memory.cairo rename to crates/evm/tests/test_memory.cairo diff --git a/crates/evm/src/tests/test_model.cairo b/crates/evm/tests/test_model.cairo similarity index 98% rename from crates/evm/src/tests/test_model.cairo rename to crates/evm/tests/test_model.cairo index ed26fee23..19674eee3 100644 --- a/crates/evm/src/tests/test_model.cairo +++ b/crates/evm/tests/test_model.cairo @@ -1,9 +1,6 @@ mod test_vm; use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; use contracts::kakarot_core::interface::IExtendedKakarotCoreDispatcherTrait; -use contracts::tests::test_utils::{ - setup_contracts_for_testing, fund_account_with_native_token, deploy_contract_account -}; use core::starknet::EthAddress; use evm::backend::starknet_backend; use evm::model::account::AccountTrait; @@ -11,7 +8,10 @@ use evm::model::account::AccountTrait; use evm::model::{Address, Account, AddressTrait}; use evm::state::StateTrait; use evm::state::{State, StateChangeLog, StateChangeLogTrait}; -use evm::tests::test_utils::{evm_address}; +use evm_tests::test_utils::contracts_utils::{ + setup_contracts_for_testing, fund_account_with_native_token, deploy_contract_account +}; +use evm_tests::test_utils::evm_utils::{evm_address}; use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait; use starknet::testing::set_contract_address; diff --git a/crates/evm/src/tests/test_model/test_vm.cairo b/crates/evm/tests/test_model/test_vm.cairo similarity index 100% rename from crates/evm/src/tests/test_model/test_vm.cairo rename to crates/evm/tests/test_model/test_vm.cairo diff --git a/crates/evm/src/tests/test_precompiles.cairo b/crates/evm/tests/test_precompiles.cairo similarity index 100% rename from crates/evm/src/tests/test_precompiles.cairo rename to crates/evm/tests/test_precompiles.cairo diff --git a/crates/evm/src/tests/test_precompiles/test_blake2f.cairo b/crates/evm/tests/test_precompiles/test_blake2f.cairo similarity index 96% rename from crates/evm/src/tests/test_precompiles/test_blake2f.cairo rename to crates/evm/tests/test_precompiles/test_blake2f.cairo index 81a59de57..c6bec850b 100644 --- a/crates/evm/src/tests/test_precompiles/test_blake2f.cairo +++ b/crates/evm/tests/test_precompiles/test_blake2f.cairo @@ -1,4 +1,3 @@ -use contracts::tests::test_utils::{setup_contracts_for_testing}; use core::array::SpanTrait; use evm::errors::EVMError; use evm::instructions::memory_operations::MemoryOperationTrait; @@ -8,7 +7,8 @@ use evm::memory::InternalMemoryTrait; use evm::memory::MemoryTrait; use evm::precompiles::blake2f::Blake2f; use evm::stack::StackTrait; -use evm::tests::test_utils::{VMBuilderTrait, native_token, other_starknet_address}; +use evm_tests::test_utils::contracts_utils::{setup_contracts_for_testing}; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait, native_token, other_starknet_address}; use starknet::testing::set_contract_address; use super::test_data::test_data_blake2f::{ blake2_precompile_fail_wrong_length_input_1_test_case, diff --git a/crates/evm/src/tests/test_precompiles/test_data.cairo b/crates/evm/tests/test_precompiles/test_data.cairo similarity index 100% rename from crates/evm/src/tests/test_precompiles/test_data.cairo rename to crates/evm/tests/test_precompiles/test_data.cairo diff --git a/crates/evm/src/tests/test_precompiles/test_data/test_data_blake2f.cairo b/crates/evm/tests/test_precompiles/test_data/test_data_blake2f.cairo similarity index 100% rename from crates/evm/src/tests/test_precompiles/test_data/test_data_blake2f.cairo rename to crates/evm/tests/test_precompiles/test_data/test_data_blake2f.cairo diff --git a/crates/evm/src/tests/test_precompiles/test_data/test_data_modexp.cairo b/crates/evm/tests/test_precompiles/test_data/test_data_modexp.cairo similarity index 100% rename from crates/evm/src/tests/test_precompiles/test_data/test_data_modexp.cairo rename to crates/evm/tests/test_precompiles/test_data/test_data_modexp.cairo diff --git a/crates/evm/src/tests/test_precompiles/test_ec_recover.cairo b/crates/evm/tests/test_precompiles/test_ec_recover.cairo similarity index 95% rename from crates/evm/src/tests/test_precompiles/test_ec_recover.cairo rename to crates/evm/tests/test_precompiles/test_ec_recover.cairo index 326177662..d31ca8421 100644 --- a/crates/evm/src/tests/test_precompiles/test_ec_recover.cairo +++ b/crates/evm/tests/test_precompiles/test_ec_recover.cairo @@ -1,4 +1,3 @@ -use contracts::tests::test_utils::setup_contracts_for_testing; use core::array::ArrayTrait; use evm::instructions::system_operations::SystemOperationsTrait; use evm::memory::InternalMemoryTrait; @@ -6,7 +5,8 @@ use evm::memory::MemoryTrait; use evm::precompiles::ec_recover::EcRecover; use evm::stack::StackTrait; -use evm::tests::test_utils::{VMBuilderTrait, native_token, other_starknet_address}; +use evm_tests::test_utils::contracts_utils::setup_contracts_for_testing; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait, native_token, other_starknet_address}; use utils::helpers::{U256Trait, ToBytes, FromBytes}; diff --git a/crates/evm/src/tests/test_precompiles/test_identity.cairo b/crates/evm/tests/test_precompiles/test_identity.cairo similarity index 90% rename from crates/evm/src/tests/test_precompiles/test_identity.cairo rename to crates/evm/tests/test_precompiles/test_identity.cairo index e61a08918..2c29a899b 100644 --- a/crates/evm/src/tests/test_precompiles/test_identity.cairo +++ b/crates/evm/tests/test_precompiles/test_identity.cairo @@ -1,4 +1,3 @@ -use contracts::tests::test_utils::{setup_contracts_for_testing}; use core::clone::Clone; use core::result::ResultTrait; use evm::instructions::system_operations::SystemOperationsTrait; @@ -6,7 +5,8 @@ use evm::instructions::system_operations::SystemOperationsTrait; use evm::memory::MemoryTrait; use evm::precompiles::identity::Identity; use evm::stack::StackTrait; -use evm::tests::test_utils::{VMBuilderTrait, native_token, other_starknet_address}; +use evm_tests::test_utils::contracts_utils::{setup_contracts_for_testing}; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait, native_token, other_starknet_address}; use starknet::testing::set_contract_address; // source: diff --git a/crates/evm/src/tests/test_precompiles/test_modexp.cairo b/crates/evm/tests/test_precompiles/test_modexp.cairo similarity index 94% rename from crates/evm/src/tests/test_precompiles/test_modexp.cairo rename to crates/evm/tests/test_precompiles/test_modexp.cairo index 44399a61b..d53ab1a06 100644 --- a/crates/evm/src/tests/test_precompiles/test_modexp.cairo +++ b/crates/evm/tests/test_precompiles/test_modexp.cairo @@ -1,4 +1,3 @@ -use contracts::tests::test_utils::{setup_contracts_for_testing}; use core::result::ResultTrait; use evm::instructions::system_operations::SystemOperationsTrait; @@ -7,13 +6,14 @@ use evm::memory::MemoryTrait; use evm::precompiles::Precompiles; use evm::stack::StackTrait; -use evm::tests::test_precompiles::test_data::test_data_modexp::{ +use evm_tests::test_precompiles::test_data::test_data_modexp::{ test_modexp_modsize0_returndatasizeFiller_data, test_modexp_create2callPrecompiles_test0_berlin_data, test_modexp_eip198_example_1_data, test_modexp_eip198_example_2_data, test_modexp_nagydani_1_square_data, test_modexp_nagydani_1_qube_data }; -use evm::tests::test_utils::{VMBuilderTrait, native_token, other_starknet_address}; +use evm_tests::test_utils::contracts_utils::{setup_contracts_for_testing}; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait, native_token, other_starknet_address}; use starknet::EthAddress; use starknet::testing::set_contract_address; use utils::helpers::U256Trait; diff --git a/crates/evm/src/tests/test_precompiles/test_p256verify.cairo b/crates/evm/tests/test_precompiles/test_p256verify.cairo similarity index 97% rename from crates/evm/src/tests/test_precompiles/test_p256verify.cairo rename to crates/evm/tests/test_precompiles/test_p256verify.cairo index 73e63d49a..c4529d0e9 100644 --- a/crates/evm/src/tests/test_precompiles/test_p256verify.cairo +++ b/crates/evm/tests/test_precompiles/test_p256verify.cairo @@ -1,4 +1,3 @@ -use contracts::tests::test_utils::setup_contracts_for_testing; use core::array::ArrayTrait; use evm::instructions::system_operations::SystemOperationsTrait; use evm::memory::InternalMemoryTrait; @@ -6,7 +5,8 @@ use evm::memory::MemoryTrait; use evm::precompiles::p256verify::P256Verify; use evm::stack::StackTrait; -use evm::tests::test_utils::{VMBuilderTrait}; +use evm_tests::test_utils::contracts_utils::setup_contracts_for_testing; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait}; use utils::helpers::{U256Trait, ToBytes, FromBytes}; diff --git a/crates/evm/src/tests/test_precompiles/test_sha256.cairo b/crates/evm/tests/test_precompiles/test_sha256.cairo similarity index 92% rename from crates/evm/src/tests/test_precompiles/test_sha256.cairo rename to crates/evm/tests/test_precompiles/test_sha256.cairo index c0328dd6b..94edeb4d3 100644 --- a/crates/evm/src/tests/test_precompiles/test_sha256.cairo +++ b/crates/evm/tests/test_precompiles/test_sha256.cairo @@ -1,11 +1,11 @@ -use contracts::tests::test_utils::{setup_contracts_for_testing}; use core::result::ResultTrait; use evm::instructions::system_operations::SystemOperationsTrait; use evm::memory::MemoryTrait; use evm::precompiles::sha256::Sha256; use evm::stack::StackTrait; -use evm::tests::test_utils::{VMBuilderTrait, native_token, other_starknet_address}; +use evm_tests::test_utils::contracts_utils::{setup_contracts_for_testing}; +use evm_tests::test_utils::evm_utils::{VMBuilderTrait, native_token, other_starknet_address}; use starknet::testing::set_contract_address; use utils::helpers::{FromBytes}; diff --git a/crates/evm/src/tests/test_stack.cairo b/crates/evm/tests/test_stack.cairo similarity index 100% rename from crates/evm/src/tests/test_stack.cairo rename to crates/evm/tests/test_stack.cairo diff --git a/crates/evm/src/tests/test_starknet_backend.cairo b/crates/evm/tests/test_starknet_backend.cairo similarity index 79% rename from crates/evm/src/tests/test_starknet_backend.cairo rename to crates/evm/tests/test_starknet_backend.cairo index 96a74e384..f7f46a557 100644 --- a/crates/evm/src/tests/test_starknet_backend.cairo +++ b/crates/evm/tests/test_starknet_backend.cairo @@ -1,10 +1,12 @@ use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; use contracts::kakarot_core::KakarotCore; -use contracts::tests::test_utils as contract_utils; -use contracts::tests::test_utils::{setup_contracts_for_testing, fund_account_with_native_token}; use evm::backend::starknet_backend; use evm::errors::EVMErrorTrait; -use evm::tests::test_utils::{chain_id, evm_address, VMBuilderTrait}; +use evm_tests::test_utils::contracts_utils::{ + setup_contracts_for_testing, fund_account_with_native_token +}; +use evm_tests::test_utils::contracts_utils; +use evm_tests::test_utils::evm_utils::{chain_id, evm_address, VMBuilderTrait}; use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait; use starknet::testing::{set_contract_address, set_chain_id}; @@ -15,7 +17,7 @@ fn test_account_deploy() { let eoa_address = starknet_backend::deploy(evm_address()).expect('deployment of EOA failed'); - let event = contract_utils::pop_log::< + let event = contracts_utils::pop_log::< KakarotCore::AccountDeployed >(kakarot_core.contract_address) .unwrap(); diff --git a/crates/evm/src/tests/test_state.cairo b/crates/evm/tests/test_state.cairo similarity index 81% rename from crates/evm/src/tests/test_state.cairo rename to crates/evm/tests/test_state.cairo index 50517bf39..49b14a758 100644 --- a/crates/evm/src/tests/test_state.cairo +++ b/crates/evm/tests/test_state.cairo @@ -1,12 +1,11 @@ -use contracts::tests::test_utils::{deploy_contract_account, deploy_eoa}; - use evm::state::compute_state_key; -use evm::tests::test_utils; +use evm_tests::test_utils::evm_utils::{deploy_contract_account, deploy_eoa}; +use evm_tests::test_utils::evm_utils; #[test] fn test_compute_state_key() { let key = 100; - let evm_address = test_utils::evm_address(); + let evm_address = evm_utils::evm_address(); // The values can be computed externally by running a Rust program using the `starknet_crypto` crate and `poseidon_hash_many`. // ```rust @@ -21,7 +20,7 @@ fn test_compute_state_key() { // ]; // let values_to_hash = [keys[0],keys[1],keys[2]]; // let hash = poseidon_hash_many(&values_to_hash); - // + // // } // let address = compute_state_key(evm_address, key); @@ -33,7 +32,7 @@ fn test_compute_state_key() { mod test_state_changelog { use evm::state::{StateChangeLog, StateChangeLogTrait}; - use evm::tests::test_utils; + use evm_tests::test_utils::evm_utils; use utils::set::{Set, SetTrait}; use utils::traits::StorageBaseAddressIntoFelt252; @@ -41,14 +40,14 @@ mod test_state_changelog { #[test] fn test_read_empty_log() { let mut changelog: StateChangeLog = Default::default(); - let key = test_utils::storage_base_address().into(); + let key = evm_utils::storage_base_address().into(); assert(changelog.read(key).is_none(), 'should return None'); } #[test] fn test_write_read() { let mut changelog: StateChangeLog = Default::default(); - let key = test_utils::storage_base_address().into(); + let key = evm_utils::storage_base_address().into(); changelog.write(key, 42); assert(changelog.read(key).unwrap() == 42, 'value not stored correctly'); @@ -70,13 +69,13 @@ mod test_state_changelog { mod test_state { use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; use contracts::kakarot_core::interface::{IExtendedKakarotCoreDispatcherTrait}; - use contracts::tests::test_utils as contract_utils; use contracts::uninitialized_account::UninitializedAccount; use evm::backend::starknet_backend; use evm::model::account::{Account, AccountTrait, AccountInternalTrait}; use evm::model::{Event, Transfer, Address}; use evm::state::{State, StateTrait}; - use evm::tests::test_utils; + use evm_tests::test_utils::contracts_utils; + use evm_tests::test_utils::evm_utils; use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; use starknet::EthAddress; use starknet::testing::set_contract_address; @@ -88,8 +87,8 @@ mod test_state { fn test_get_account_when_not_present() { let mut state: State = Default::default(); // Transfer native tokens to sender - let (_, kakarot_core) = contract_utils::setup_contracts_for_testing(); - let evm_address: EthAddress = test_utils::evm_address(); + let (_, kakarot_core) = contracts_utils::setup_contracts_for_testing(); + let evm_address: EthAddress = evm_utils::evm_address(); let starknet_address = compute_starknet_address( kakarot_core.contract_address.into(), evm_address, @@ -114,10 +113,10 @@ mod test_state { #[test] fn test_get_account_when_present() { let mut state: State = Default::default(); - let deployer = test_utils::kakarot_address(); + let deployer = evm_utils::kakarot_address(); set_contract_address(deployer); - let evm_address: EthAddress = test_utils::evm_address(); + let evm_address: EthAddress = evm_utils::evm_address(); let starknet_address = compute_starknet_address( deployer.into(), evm_address, UninitializedAccount::TEST_CLASS_HASH.try_into().unwrap() ); @@ -142,12 +141,12 @@ mod test_state { #[ignore] fn test_get_account_when_deployed() { let mut state: State = Default::default(); - let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing(); - let evm_address: EthAddress = test_utils::evm_address(); - let ca = contract_utils::deploy_contract_account( + let (native_token, kakarot_core) = contracts_utils::setup_contracts_for_testing(); + let evm_address: EthAddress = evm_utils::evm_address(); + let ca = contracts_utils::deploy_contract_account( evm_address, array![0xab, 0xcd, 0xef].span() ); - contract_utils::fund_account_with_native_token(ca.starknet, native_token, 420); + contracts_utils::fund_account_with_native_token(ca.starknet, native_token, 420); let starknet_address = kakarot_core.compute_starknet_address(evm_address); let expected_account = Account { @@ -168,7 +167,7 @@ mod test_state { #[test] fn test_write_read_cached_storage() { let mut state: State = Default::default(); - let evm_address: EthAddress = test_utils::evm_address(); + let evm_address: EthAddress = evm_utils::evm_address(); let key = 10; let value = 100; @@ -181,9 +180,9 @@ mod test_state { #[test] fn test_read_state_from_sn_storage() { // Transfer native tokens to sender - contract_utils::setup_contracts_for_testing(); - let evm_address: EthAddress = test_utils::evm_address(); - let mut ca_address = contract_utils::deploy_contract_account(evm_address, array![].span()); + contracts_utils::setup_contracts_for_testing(); + let evm_address: EthAddress = evm_utils::evm_address(); + let mut ca_address = contracts_utils::deploy_contract_account(evm_address, array![].span()); let mut state: State = Default::default(); let key = 10; @@ -219,14 +218,14 @@ mod test_state { fn test_add_transfer() { //Given let mut state: State = Default::default(); - contract_utils::setup_contracts_for_testing(); + contracts_utils::setup_contracts_for_testing(); - let sender_evm_address = test_utils::evm_address(); - let sender_starknet_address = contract_utils::deploy_eoa(sender_evm_address) + let sender_evm_address = evm_utils::evm_address(); + let sender_starknet_address = contracts_utils::deploy_eoa(sender_evm_address) .contract_address; let sender_address = Address { evm: sender_evm_address, starknet: sender_starknet_address }; - let recipient_evm_address = test_utils::other_evm_address(); - let recipient_starknet_address = contract_utils::deploy_eoa(recipient_evm_address) + let recipient_evm_address = evm_utils::other_evm_address(); + let recipient_starknet_address = contracts_utils::deploy_eoa(recipient_evm_address) .contract_address; let recipient_address = Address { evm: recipient_evm_address, starknet: recipient_starknet_address @@ -256,10 +255,10 @@ mod test_state { fn test_add_transfer_with_same_sender_and_recipient() { //Given let mut state: State = Default::default(); - contract_utils::setup_contracts_for_testing(); + contracts_utils::setup_contracts_for_testing(); - let sender_evm_address = test_utils::evm_address(); - let sender_starknet_address = contract_utils::deploy_eoa(sender_evm_address) + let sender_evm_address = evm_utils::evm_address(); + let sender_starknet_address = contracts_utils::deploy_eoa(sender_evm_address) .contract_address; let sender_address = Address { evm: sender_evm_address, starknet: sender_starknet_address }; @@ -284,14 +283,14 @@ mod test_state { fn test_add_transfer_when_amount_is_zero() { //Given let mut state: State = Default::default(); - contract_utils::setup_contracts_for_testing(); + contracts_utils::setup_contracts_for_testing(); - let sender_evm_address = test_utils::evm_address(); - let sender_starknet_address = contract_utils::deploy_eoa(sender_evm_address) + let sender_evm_address = evm_utils::evm_address(); + let sender_starknet_address = contracts_utils::deploy_eoa(sender_evm_address) .contract_address; let sender_address = Address { evm: sender_evm_address, starknet: sender_starknet_address }; - let recipient_evm_address = test_utils::other_evm_address(); - let recipient_starknet_address = contract_utils::deploy_eoa(recipient_evm_address) + let recipient_evm_address = evm_utils::other_evm_address(); + let recipient_starknet_address = contracts_utils::deploy_eoa(recipient_evm_address) .contract_address; let recipient_address = Address { evm: recipient_evm_address, starknet: recipient_starknet_address @@ -321,10 +320,10 @@ mod test_state { #[test] fn test_read_balance_cached() { let mut state: State = Default::default(); - contract_utils::setup_contracts_for_testing(); + contracts_utils::setup_contracts_for_testing(); - let evm_address = test_utils::evm_address(); - let starknet_address = contract_utils::deploy_eoa(evm_address).contract_address; + let evm_address = evm_utils::evm_address(); + let starknet_address = contracts_utils::deploy_eoa(evm_address).contract_address; let address = Address { evm: evm_address, starknet: starknet_address }; let balance = 100; @@ -341,11 +340,11 @@ mod test_state { #[test] fn test_read_balance_from_storage() { // Transfer native tokens to sender - let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing(); - let evm_address: EthAddress = test_utils::evm_address(); + let (native_token, kakarot_core) = contracts_utils::setup_contracts_for_testing(); + let evm_address: EthAddress = evm_utils::evm_address(); let eoa_account = starknet_backend::deploy(evm_address).expect('sender deploy failed'); // Transfer native tokens to sender - we need to set the contract address for this - set_contract_address(contract_utils::constants::ETH_BANK()); + set_contract_address(contracts_utils::constants::ETH_BANK()); IERC20CamelDispatcher { contract_address: native_token.contract_address } .transfer(eoa_account.starknet, 10000); // Revert back to contract_address = kakarot for the test diff --git a/crates/evm/tests/test_utils.cairo b/crates/evm/tests/test_utils.cairo new file mode 100644 index 000000000..78b7eaa95 --- /dev/null +++ b/crates/evm/tests/test_utils.cairo @@ -0,0 +1,2 @@ +mod contracts_utils; +mod evm_utils; diff --git a/crates/contracts/src/tests/test_utils.cairo b/crates/evm/tests/test_utils/contracts_utils.cairo similarity index 96% rename from crates/contracts/src/tests/test_utils.cairo rename to crates/evm/tests/test_utils/contracts_utils.cairo index 0f6458d5c..132994f55 100644 --- a/crates/contracts/src/tests/test_utils.cairo +++ b/crates/evm/tests/test_utils/contracts_utils.cairo @@ -10,7 +10,9 @@ use core::result::ResultTrait; use evm::backend::starknet_backend; use evm::model::{Address}; -use evm::tests::test_utils::{ca_address, other_starknet_address, chain_id, sequencer_evm_address}; +use evm_tests::test_utils::evm_utils::{ + ca_address, other_starknet_address, chain_id, sequencer_evm_address +}; use openzeppelin::token::erc20::ERC20; use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; use starknet::{ @@ -121,7 +123,7 @@ fn deploy_kakarot_core( } } -pub(crate) fn deploy_contract_account(evm_address: EthAddress, bytecode: Span) -> Address { +pub fn deploy_contract_account(evm_address: EthAddress, bytecode: Span) -> Address { let ca_address = starknet_backend::deploy(evm_address).expect('failed to deploy CA'); IAccountDispatcher { contract_address: ca_address.starknet }.set_nonce(1); IAccountDispatcher { contract_address: ca_address.starknet }.write_bytecode(bytecode); diff --git a/crates/evm/tests/test_utils/evm_utils.cairo b/crates/evm/tests/test_utils/evm_utils.cairo new file mode 100644 index 000000000..bc7813692 --- /dev/null +++ b/crates/evm/tests/test_utils/evm_utils.cairo @@ -0,0 +1,296 @@ +use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; +use contracts::uninitialized_account::UninitializedAccount; +use core::nullable::{match_nullable, FromNullableResult}; +use core::traits::TryInto; +use evm::backend::starknet_backend; +use evm::errors::{EVMError}; + +use evm::model::vm::{VM, VMTrait}; +use evm::model::{Message, Environment, Address, Account, AccountTrait}; +use evm::state::State; +use evm::{stack::{Stack, StackTrait}, memory::{Memory, MemoryTrait}}; +use starknet::{ + StorageBaseAddress, storage_base_address_from_felt252, contract_address_try_from_felt252, + ContractAddress, EthAddress, deploy_syscall, get_contract_address, contract_address_const +}; +use utils::constants; + +pub fn deploy_contract_account(evm_address: EthAddress, bytecode: Span) -> Address { + let ca_address = starknet_backend::deploy(evm_address).expect('failed to deploy CA'); + IAccountDispatcher { contract_address: ca_address.starknet }.set_nonce(1); + IAccountDispatcher { contract_address: ca_address.starknet }.write_bytecode(bytecode); + ca_address +} + + +fn deploy_eoa(eoa_address: EthAddress) -> IAccountDispatcher { + let kakarot_address = get_contract_address(); + let calldata: Span = array![kakarot_address.into(), eoa_address.into()].span(); + + let (starknet_address, _) = deploy_syscall( + UninitializedAccount::TEST_CLASS_HASH.try_into().unwrap(), + eoa_address.into(), + calldata, + true + ) + .expect('failed to deploy EOA'); + + let eoa = IAccountDispatcher { contract_address: starknet_address }; + eoa +} + + +#[derive(Destruct)] +struct VMBuilder { + vm: VM +} + +#[generate_trait] +impl VMBuilderImpl of VMBuilderTrait { + fn new() -> VMBuilder { + VMBuilder { vm: Default::default() }.with_gas_limit(0x100000000000000000000) + } + + fn new_with_presets() -> VMBuilder { + VMBuilder { vm: preset_vm() } + } + + fn with_return_data(mut self: VMBuilder, return_data: Span) -> VMBuilder { + self.vm.set_return_data(return_data); + self + } + + fn with_caller(mut self: VMBuilder, address: Address) -> VMBuilder { + self.vm.message.caller = address; + self + } + + fn with_calldata(mut self: VMBuilder, calldata: Span) -> VMBuilder { + self.vm.message.data = calldata; + self + } + + fn with_read_only(mut self: VMBuilder) -> VMBuilder { + self.vm.message.read_only = true; + self + } + + fn with_bytecode(mut self: VMBuilder, bytecode: Span) -> VMBuilder { + self.vm.message.code = bytecode; + self + } + + fn with_gas_limit(mut self: VMBuilder, gas_limit: u128) -> VMBuilder { + self.vm.message.gas_limit = gas_limit; + self + } + + // fn with_nested_vm(mut self: VMBuilder) -> VMBuilder { + // let current_ctx = self.machine.current_ctx.unbox(); + + // // Second Execution Context + // let context_id = ExecutionContextType::Call(1); + // let mut child_context = preset_message(); + // child_context.ctx_type = context_id; + // child_context.parent_ctx = NullableTrait::new(current_ctx); + // let mut call_ctx = child_context.call_ctx(); + // call_ctx.caller = other_address(); + // child_context.call_ctx = BoxTrait::new(call_ctx); + // self.machine.current_ctx = BoxTrait::new(child_context); + // self + // } + + fn with_target(mut self: VMBuilder, target: Address) -> VMBuilder { + self.vm.message.target = target; + self + } + + fn build(mut self: VMBuilder) -> VM { + self.vm.valid_jumpdests = AccountTrait::get_jumpdests(self.vm.message.code); + return self.vm; + } +} + +fn origin() -> EthAddress { + 'origin'.try_into().unwrap() +} + +fn caller() -> EthAddress { + 'caller'.try_into().unwrap() +} + +fn coinbase() -> EthAddress { + 'coinbase'.try_into().unwrap() +} + +fn starknet_address() -> ContractAddress { + contract_address_const::<'starknet_address'>() +} + +fn evm_address() -> EthAddress { + 'evm_address'.try_into().unwrap() +} + +fn test_address() -> Address { + Address { evm: evm_address(), starknet: starknet_address() } +} + +fn other_evm_address() -> EthAddress { + 'other_evm_address'.try_into().unwrap() +} + +fn other_starknet_address() -> ContractAddress { + contract_address_const::<'other_starknet_address'>() +} + +fn other_address() -> Address { + Address { evm: other_evm_address(), starknet: other_starknet_address() } +} + +fn storage_base_address() -> StorageBaseAddress { + storage_base_address_from_felt252('storage_base_address') +} + +fn zero_address() -> ContractAddress { + contract_address_const::<0x00>() +} + +fn callvalue() -> u256 { + 123456789 +} + +fn native_token() -> ContractAddress { + contract_address_const::<'native_token'>() +} + +fn chain_id() -> u128 { + 'KKRT'.try_into().unwrap() +} + +fn kakarot_address() -> ContractAddress { + contract_address_const::<'kakarot'>() +} + +fn sequencer_evm_address() -> EthAddress { + 'sequencer'.try_into().unwrap() +} + +fn eoa_address() -> EthAddress { + let evm_address: EthAddress = 0xe0a.try_into().unwrap(); + evm_address +} + +fn tx_gas_limit() -> u128 { + 15000000000 +} + +fn gas_price() -> u128 { + 32 +} + +fn value() -> u256 { + 0xffffffffffffffffffffffffffffffff +} + +fn ca_address() -> EthAddress { + let evm_address: EthAddress = 0xca.try_into().unwrap(); + evm_address +} + +fn preset_message() -> Message { + let code: Span = array![0x00].span(); + let data: Span = array![4, 5, 6].span(); + let value: u256 = callvalue(); + let caller = Address { + evm: origin(), + starknet: utils::helpers::compute_starknet_address( + get_contract_address(), + origin(), + UninitializedAccount::TEST_CLASS_HASH.try_into().unwrap() + ) + }; + let read_only = false; + let tx_gas_limit = tx_gas_limit(); + let target = test_address(); + + Message { + target, + caller, + data, + value, + gas_limit: tx_gas_limit, + read_only, + code, + should_transfer_value: true, + depth: 0, + accessed_addresses: Default::default(), + accessed_storage_keys: Default::default(), + } +} + +fn preset_environment() -> Environment { + let block_info = starknet::get_block_info().unbox(); + Environment { + origin: origin(), + gas_price: gas_price(), + chain_id: chain_id(), + prevrandao: 0, + block_number: block_info.block_number, + block_timestamp: block_info.block_timestamp, + block_gas_limit: constants::BLOCK_GAS_LIMIT, + coinbase: coinbase(), + base_fee: 0, + state: Default::default(), + } +} + +fn preset_vm() -> VM { + let message = preset_message(); + let environment = preset_environment(); + let return_data = array![1, 2, 3].span(); + VM { + stack: Default::default(), + memory: Default::default(), + pc: 0, + valid_jumpdests: AccountTrait::get_jumpdests(message.code), + return_data, + env: environment, + message, + gas_left: message.gas_limit, + running: true, + error: false, + accessed_addresses: Default::default(), + accessed_storage_keys: Default::default(), + gas_refund: 0, + } +} + + +/// Initializes the contract account by setting the bytecode, the storage +/// and incrementing the nonce to 1. +fn initialize_contract_account( + eth_address: EthAddress, bytecode: Span, storage: Span<(u256, u256)> +) -> Result { + let mut ca_address = deploy_contract_account(eth_address, bytecode); + // Set the storage of the contract account + let account = Account { + address: ca_address, + code: array![0xab, 0xcd, 0xef].span(), + nonce: 1, + balance: 0, + selfdestruct: false, + is_created: false, + }; + let mut i = 0; + loop { + if i == storage.len() { + break; + }; + let (key, value) = storage.get(i).unwrap().unbox(); + IAccountDispatcher { contract_address: account.starknet_address() } + .write_storage(*key, *value); + i += 1; + }; + + Result::Ok(ca_address) +} diff --git a/crates/utils/src/eth_transaction.cairo b/crates/utils/src/eth_transaction.cairo index 8e84b7c08..9a330fc51 100644 --- a/crates/utils/src/eth_transaction.cairo +++ b/crates/utils/src/eth_transaction.cairo @@ -22,7 +22,7 @@ struct AccessListItem { #[generate_trait] impl AccessListItemImpl of AccessListItemTrait { fn to_storage_keys(self: @AccessListItem) -> Span<(EthAddress, u256)> { - let AccessListItem{ethereum_address, mut storage_keys } = *self; + let AccessListItem { ethereum_address, mut storage_keys } = *self; let mut storage_keys_arr = array![]; loop { @@ -459,7 +459,7 @@ impl EthTransactionImpl of EthTransactionTrait { fn validate_eth_tx( tx_metadata: TransactionMetadata, encoded_tx_data: Span ) -> Result { - let TransactionMetadata{address, account_nonce, chain_id, signature } = tx_metadata; + let TransactionMetadata { address, account_nonce, chain_id, signature } = tx_metadata; let decoded_tx = EthTransactionTrait::decode(encoded_tx_data)?; diff --git a/crates/utils/src/lib.cairo b/crates/utils/src/lib.cairo index e6d7fb517..1bcb0f187 100644 --- a/crates/utils/src/lib.cairo +++ b/crates/utils/src/lib.cairo @@ -15,6 +15,5 @@ mod serialization; mod set; mod storage; -#[cfg(test)] -mod tests; +mod test_data; mod traits; diff --git a/crates/utils/src/tests/test_data.cairo b/crates/utils/src/test_data.cairo similarity index 100% rename from crates/utils/src/tests/test_data.cairo rename to crates/utils/src/test_data.cairo diff --git a/crates/utils/src/tests.cairo b/crates/utils/tests/lib.cairo similarity index 92% rename from crates/utils/src/tests.cairo rename to crates/utils/tests/lib.cairo index e980a6488..d913629fb 100644 --- a/crates/utils/src/tests.cairo +++ b/crates/utils/tests/lib.cairo @@ -1,5 +1,4 @@ mod test_address; -mod test_data; mod test_eth_transaction; mod test_helpers; mod test_i256; diff --git a/crates/utils/src/tests/test_address.cairo b/crates/utils/tests/test_address.cairo similarity index 94% rename from crates/utils/src/tests/test_address.cairo rename to crates/utils/tests/test_address.cairo index 9987e9cd1..b89691d6b 100644 --- a/crates/utils/src/tests/test_address.cairo +++ b/crates/utils/tests/test_address.cairo @@ -1,4 +1,4 @@ -use contracts::tests::test_data::counter_evm_bytecode; +use contracts::test_data::counter_evm_bytecode; use starknet::EthAddress; use utils::address::{compute_contract_address, compute_create2_contract_address}; diff --git a/crates/utils/src/tests/test_eth_transaction.cairo b/crates/utils/tests/test_eth_transaction.cairo similarity index 99% rename from crates/utils/src/tests/test_eth_transaction.cairo rename to crates/utils/tests/test_eth_transaction.cairo index 9bbbf5573..f2ae7e8a8 100644 --- a/crates/utils/src/tests/test_eth_transaction.cairo +++ b/crates/utils/tests/test_eth_transaction.cairo @@ -1,4 +1,3 @@ -use contracts::tests::test_utils::chain_id; use core::option::OptionTrait; use core::starknet::eth_signature::{EthAddress, Signature}; @@ -9,10 +8,14 @@ use utils::eth_transaction::{ }; use utils::helpers::{U256Trait, ToBytes}; use utils::rlp::{RLPTrait, RLPItem, RLPHelpersTrait}; -use utils::tests::test_data::{ +use utils::test_data::{ legacy_rlp_encoded_tx, legacy_rlp_encoded_deploy_tx, eip_2930_encoded_tx, eip_1559_encoded_tx }; +fn chain_id() -> u128 { + 'KKRT'.try_into().unwrap() +} + #[test] fn test_decode_legacy_tx() { diff --git a/crates/utils/src/tests/test_helpers.cairo b/crates/utils/tests/test_helpers.cairo similarity index 100% rename from crates/utils/src/tests/test_helpers.cairo rename to crates/utils/tests/test_helpers.cairo diff --git a/crates/utils/src/tests/test_i256.cairo b/crates/utils/tests/test_i256.cairo similarity index 100% rename from crates/utils/src/tests/test_i256.cairo rename to crates/utils/tests/test_i256.cairo diff --git a/crates/utils/src/tests/test_math.cairo b/crates/utils/tests/test_math.cairo similarity index 100% rename from crates/utils/src/tests/test_math.cairo rename to crates/utils/tests/test_math.cairo diff --git a/crates/utils/src/tests/test_modexp.cairo b/crates/utils/tests/test_modexp.cairo similarity index 100% rename from crates/utils/src/tests/test_modexp.cairo rename to crates/utils/tests/test_modexp.cairo diff --git a/crates/utils/src/tests/test_modexp/test_arith.cairo b/crates/utils/tests/test_modexp/test_arith.cairo similarity index 99% rename from crates/utils/src/tests/test_modexp/test_arith.cairo rename to crates/utils/tests/test_modexp/test_arith.cairo index 629b0486f..f7720bb31 100644 --- a/crates/utils/src/tests/test_modexp/test_arith.cairo +++ b/crates/utils/tests/test_modexp/test_arith.cairo @@ -14,7 +14,7 @@ use utils::crypto::modexp::mpnat::{ use utils::helpers::{Felt252VecTrait, ToBytes}; use utils::helpers::{U128Trait}; use utils::math::{WrappingMul, WrappingBitshift, WrappingExponentiation}; -use utils::tests::test_modexp::test_mpnat::{mp_nat_to_u128}; +use utils_tests::test_modexp::test_mpnat::{mp_nat_to_u128}; // the tests are taken from [aurora-engine](https://github.com/aurora-is-near/aurora-engine/blob/1213f2c7c035aa523601fced8f75bef61b4728ab/engine-modexp/src/arith.rs#L401) diff --git a/crates/utils/src/tests/test_modexp/test_mpnat.cairo b/crates/utils/tests/test_modexp/test_mpnat.cairo similarity index 99% rename from crates/utils/src/tests/test_modexp/test_mpnat.cairo rename to crates/utils/tests/test_modexp/test_mpnat.cairo index 747d0b5eb..ddd60883a 100644 --- a/crates/utils/src/tests/test_modexp/test_mpnat.cairo +++ b/crates/utils/tests/test_modexp/test_mpnat.cairo @@ -15,7 +15,6 @@ use utils::math::{Bitshift, WrappingBitshift}; // the tests are taken from [aurora-engine](https://github.com/aurora-is-near/aurora-engine/blob/1213f2c7c035aa523601fced8f75bef61b4728ab/engine-modexp/src/mpnat.rs#L825) -#[cfg(test)] pub fn mp_nat_to_u128(ref x: MPNat) -> u128 { let result = x.digits.to_le_bytes(); let mut i: usize = 0; diff --git a/crates/utils/src/tests/test_rlp.cairo b/crates/utils/tests/test_rlp.cairo similarity index 100% rename from crates/utils/src/tests/test_rlp.cairo rename to crates/utils/tests/test_rlp.cairo diff --git a/crates/utils/src/tests/test_serialization.cairo b/crates/utils/tests/test_serialization.cairo similarity index 100% rename from crates/utils/src/tests/test_serialization.cairo rename to crates/utils/tests/test_serialization.cairo diff --git a/crates/utils/src/tests/test_set.cairo b/crates/utils/tests/test_set.cairo similarity index 100% rename from crates/utils/src/tests/test_set.cairo rename to crates/utils/tests/test_set.cairo diff --git a/crates/utils/src/tests/test_storage.cairo b/crates/utils/tests/test_storage.cairo similarity index 100% rename from crates/utils/src/tests/test_storage.cairo rename to crates/utils/tests/test_storage.cairo diff --git a/crates/utils/src/tests/test_traits.cairo b/crates/utils/tests/test_traits.cairo similarity index 76% rename from crates/utils/src/tests/test_traits.cairo rename to crates/utils/tests/test_traits.cairo index 20d19e592..6df447e0b 100644 --- a/crates/utils/src/tests/test_traits.cairo +++ b/crates/utils/tests/test_traits.cairo @@ -2,14 +2,13 @@ use starknet::{ StorageBaseAddress, StorageAddress, storage_address_from_base, storage_address_try_from_felt252, storage_base_address_from_felt252 }; -use test::test_utils::{assert_eq, assert_ne}; use utils::traits::{StorageBaseAddressPartialEq}; #[test] fn test_eq_storage_base_address() { let val_1 = storage_base_address_from_felt252(0x01); - assert_eq(@val_1, @val_1, 'expected equality') + assert_eq!(@val_1, @val_1); } #[test] @@ -17,5 +16,5 @@ fn test_ne_storage_base_address() { let val_1 = storage_base_address_from_felt252(0x01); let val_2 = storage_base_address_from_felt252(0x02); - assert_ne(@val_1, @val_2, 'expected inequality') + assert_ne!(@val_1, @val_2); }