Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
4 changes: 2 additions & 2 deletions src/execution/execution_entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl ExecutionEntryPoint {

// create starknet runner
let mut vm = VirtualMachine::new(false);
let mut cairo_runner = CairoRunner::new(&contract_class.program, "all_cairo", false)?;
let mut cairo_runner = CairoRunner::new(&contract_class.program, "starknet", false)?;
cairo_runner.initialize_function_runner(&mut vm)?;

validate_contract_deployed(state, &self.contract_address)?;
Expand Down Expand Up @@ -415,7 +415,7 @@ impl ExecutionEntryPoint {
// get a program from the casm contract class
let program: Program = contract_class.as_ref().clone().try_into()?;
// create and initialize a cairo runner for running cairo 1 programs.
let mut cairo_runner = CairoRunner::new(&program, "all_cairo", false)?;
let mut cairo_runner = CairoRunner::new(&program, "starknet", false)?;

cairo_runner.initialize_function_runner_cairo_1(
&mut vm,
Expand Down
38 changes: 34 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ mod test {
use crate::definitions::constants::EXECUTE_ENTRY_POINT_SELECTOR;
use crate::estimate_fee;
use crate::estimate_message_fee;
use crate::execution::execution_entry_point::ExecutionEntryPoint;
use crate::execution::TransactionExecutionContext;
use crate::services::api::contract_classes::deprecated_contract_class::ContractClass;
use crate::testing::{create_account_tx_test_state, TEST_CONTRACT_ADDRESS, TEST_CONTRACT_PATH};
use crate::testing::TEST_CONTRACT_PATH;
use crate::testing::{create_account_tx_test_state, TEST_CONTRACT_ADDRESS};
use crate::transaction::{InvokeFunction, L1Handler, Transaction};
use crate::utils::felt_to_hash;
use cairo_lang_starknet::casm_contract_class::CasmContractClass;
Expand All @@ -206,8 +209,35 @@ mod test {
let entrypoints = contract_class.entry_points_by_type;
let entrypoint_selector = &entrypoints.get(&EntryPointType::External).unwrap()[0].selector;

let (transaction_context, state) = create_account_tx_test_state().unwrap();
let (block_context, mut state) = create_account_tx_test_state().unwrap();

// Add balance to account
let calldata = [TEST_CONTRACT_ADDRESS.0.clone(), 0.into(), 1000.into()].to_vec();

let fee_transfer_call = ExecutionEntryPoint::new(
block_context.starknet_os_config.fee_token_address.clone(),
calldata,
felt_str!("37313232031488507829243159589199778096432170431839144894988167447577083165"), // mint entrypoint
block_context.starknet_os_config.fee_token_address.clone(),
EntryPointType::External,
None,
None,
100000,
);

let mut tx_execution_context = TransactionExecutionContext::default();
let mut resources_manager = ExecutionResourcesManager::default();
let _fee_transfer_exec = fee_transfer_call
.execute(
&mut state,
&block_context,
&mut resources_manager,
&mut tx_execution_context,
false,
)
.unwrap();

// Fibonacci
let calldata = [1.into(), 1.into(), 10.into()].to_vec();
let invoke_function = InvokeFunction::new(
TEST_CONTRACT_ADDRESS.clone(),
Expand All @@ -223,8 +253,8 @@ mod test {
.unwrap();
let transaction = Transaction::InvokeFunction(invoke_function);

let estimated_fee = estimate_fee(&transaction, state, &transaction_context).unwrap();
assert_eq!(estimated_fee, (0, 0));
let estimated_fee = estimate_fee(&transaction, state, &block_context).unwrap();
assert_eq!(estimated_fee, (12, 0));
}

#[test]
Expand Down
16 changes: 8 additions & 8 deletions src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ mod test {
#[test]
fn prepare_os_context_test() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let mut vm = VirtualMachine::new(true);

let os_context = StarknetRunner::<SyscallHintProcessor<CachedState::<InMemoryStateReader>>>::prepare_os_context_cairo0(&cairo_runner, &mut vm);
Expand All @@ -425,7 +425,7 @@ mod test {
#[test]
fn run_from_entrypoint_should_fail_with_no_exec_base() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let vm = VirtualMachine::new(true);

let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -441,7 +441,7 @@ mod test {
#[test]
fn get_os_segment_ptr_range_should_fail_when_ptr_offset_is_not_zero() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let vm = VirtualMachine::new(true);

let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -460,7 +460,7 @@ mod test {
#[test]
fn validate_segment_pointers_should_fail_when_offset_is_not_zero() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let vm = VirtualMachine::new(true);

let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -482,7 +482,7 @@ mod test {
#[test]
fn validate_segment_pointers_should_fail_when_base_is_not_a_value() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let vm = VirtualMachine::new(true);

let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -504,7 +504,7 @@ mod test {
#[test]
fn validate_segment_pointers_should_fail_with_invalid_segment_size() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let vm = VirtualMachine::new(true);

let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -524,7 +524,7 @@ mod test {
#[test]
fn validate_segment_pointers_should_fail_when_stop_is_not_a_value() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let mut vm = VirtualMachine::new(true);
vm.add_memory_segment();
vm.compute_segments_effective_sizes();
Expand All @@ -547,7 +547,7 @@ mod test {
#[test]
fn validate_segment_pointers_should_fail_with_invalid_stop_pointer() {
let program = cairo_vm::types::program::Program::default();
let cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap();
let cairo_runner = CairoRunner::new(&program, "starknet", false).unwrap();
let mut vm = VirtualMachine::new(true);
vm.add_memory_segment();
vm.compute_segments_effective_sizes();
Expand Down
12 changes: 6 additions & 6 deletions src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ lazy_static! {

// Others.
// Blockifier had this value hardcoded to 2.
pub static ref ACTUAL_FEE: Felt252 = Felt252::zero();
pub static ref ACTUAL_FEE: Felt252 = Felt252::from(10000000);
}

pub fn new_starknet_general_config_for_testing() -> BlockContext {
pub fn new_starknet_block_context_for_testing() -> BlockContext {
BlockContext::new(
StarknetOsConfig::new(
StarknetChainId::TestNet,
TEST_ERC20_CONTRACT_ADDRESS.clone(),
0,
1,
),
0,
0,
Expand All @@ -87,7 +87,7 @@ where

pub fn create_account_tx_test_state(
) -> Result<(BlockContext, CachedState<InMemoryStateReader>), Box<dyn std::error::Error>> {
let general_config = new_starknet_general_config_for_testing();
let block_context = new_starknet_block_context_for_testing();

let test_contract_class_hash = felt_to_hash(&TEST_CLASS_HASH.clone());
let test_account_contract_class_hash = felt_to_hash(&TEST_ACCOUNT_CONTRACT_CLASS_HASH.clone());
Expand All @@ -109,7 +109,7 @@ pub fn create_account_tx_test_state(

let test_contract_address = TEST_CONTRACT_ADDRESS.clone();
let test_account_contract_address = TEST_ACCOUNT_CONTRACT_ADDRESS.clone();
let test_erc20_address = general_config
let test_erc20_address = block_context
.starknet_os_config()
.fee_token_address()
.clone();
Expand Down Expand Up @@ -165,5 +165,5 @@ pub fn create_account_tx_test_state(
Some(HashMap::new()),
);

Ok((general_config, cached_state))
Ok((block_context, cached_state))
}
2 changes: 1 addition & 1 deletion src/transaction/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub(crate) fn execute_fee_transfer<S: State + StateReader>(

let calldata = [
block_context.block_info.sequencer_address.0.clone(),
Felt252::from(actual_fee),
0.into(),
Felt252::from(actual_fee),
]
.to_vec();

Expand Down
2 changes: 1 addition & 1 deletion src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Transaction {
Transaction::DeclareV2(tx) => tx.execute(state, block_context),
Transaction::Deploy(tx) => tx.execute(state, block_context),
Transaction::DeployAccount(tx) => tx.execute(state, block_context),
Transaction::InvokeFunction(tx) => tx.execute(state, block_context, 0),
Transaction::InvokeFunction(tx) => tx.execute(state, block_context, remaining_gas),
Transaction::L1Handler(tx) => tx.execute(state, block_context, remaining_gas),
}
}
Expand Down
2 changes: 1 addition & 1 deletion starknet_programs/ERC20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func permissionedMint{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_chec
recipient: felt, amount: Uint256
) {
alloc_locals;
permitted_minter_only();
//permitted_minter_only(); <- We remove this to make testing easier
local syscall_ptr: felt* = syscall_ptr;

ERC20_mint(recipient=recipient, amount=amount);
Expand Down
10 changes: 5 additions & 5 deletions tests/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,21 +761,21 @@ fn expected_declare_fee_transfer_info() -> CallInfo {
Felt252::zero(),
],
accessed_storage_keys: HashSet::from([
[
2, 162, 196, 156, 77, 186, 13, 145, 179, 79, 42, 222, 133, 212, 29, 9, 86, 31, 154,
119, 136, 76, 21, 186, 42, 176, 242, 36, 27, 8, 13, 236,
],
[
7, 35, 151, 50, 8, 99, 155, 120, 57, 206, 41, 143, 127, 254, 166, 30, 63, 149, 51,
135, 45, 239, 215, 171, 219, 145, 2, 61, 180, 101, 136, 18,
],
[
2, 162, 196, 156, 77, 186, 13, 145, 179, 79, 42, 222, 133, 212, 29, 9, 86, 31, 154,
119, 136, 76, 21, 186, 42, 176, 242, 36, 27, 8, 13, 235,
],
[
7, 35, 151, 50, 8, 99, 155, 120, 57, 206, 41, 143, 127, 254, 166, 30, 63, 149, 51,
135, 45, 239, 215, 171, 219, 145, 2, 61, 180, 101, 136, 19,
],
[
2, 162, 196, 156, 77, 186, 13, 145, 179, 79, 42, 222, 133, 212, 29, 9, 86, 31, 154,
119, 136, 76, 21, 186, 42, 176, 242, 36, 27, 8, 13, 235,
119, 136, 76, 21, 186, 42, 176, 242, 36, 27, 8, 13, 236,
],
]),
execution_resources: ExecutionResources {
Expand Down