Skip to content

Commit

Permalink
add test for calling non legacy contract
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Dec 11, 2024
1 parent fdd0956 commit 1deee22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 6 additions & 4 deletions crates/katana/executor/src/implementation/blockifier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,19 @@ pub fn call<S: StateReader>(
tx_info: TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()),
});

// The reason whhy we assign a new `RunResources` is because of how the initial gas value for
// The reason why we assign a new `RunResources` is because of how the initial gas value for
// the call is being computed. Passing the `initial_gas` value directly used to work,
// meaning the actual value of the `initial_gas` would be used to run the contract call, but
// now Blockifier computes the initial gas differently, based on the block gas prices. See
// `EntryPointExecutionContext::max_steps()` for further references.
// meaning the literal value of the `initial_gas` would be used as the to run the contract call,
// but now Blockifier computes the initial gas differently, based on the block gas prices.
// See `EntryPointExecutionContext::max_steps()` for further references.
//
// The value of `limit_steps_by_resources` becomes irrelevant because of the explicit
// re-assignment of the run resources.

let limit_steps_by_resources = false;
let mut ctx = EntryPointExecutionContext::new_invoke(tx_context, limit_steps_by_resources);

// If `initial_gas` can't fit in a usize, use the maximum.
ctx.vm_run_resources = RunResources::new(initial_gas.try_into().unwrap_or(usize::MAX));

let mut remaining_gas = initial_gas as u64;
Expand Down
20 changes: 17 additions & 3 deletions crates/katana/rpc/rpc/tests/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;

use anyhow::Result;
use assert_matches::assert_matches;
use cainome::rs::abigen_legacy;
use cainome::rs::{abigen, abigen_legacy};
use common::split_felt;
use dojo_test_utils::sequencer::{get_default_test_config, TestSequencer};
use indexmap::IndexSet;
Expand Down Expand Up @@ -1153,9 +1153,23 @@ async fn call_contract() {
let provider = sequencer.provider();
let account = sequencer.account().address();

// setup contract to interact with (can be any existing contract that can be interacted with)
let contract = Erc20ContractReader::new(DEFAULT_ETH_FEE_TOKEN_ADDRESS.into(), &provider);
// -----------------------------------------------------------------------
// Call legacy contract

let contract = Erc20ContractReader::new(DEFAULT_ETH_FEE_TOKEN_ADDRESS.into(), &provider);
let _ = contract.name().call().await.unwrap();
let _ = contract.balanceOf(&account).call().await.unwrap();

// -----------------------------------------------------------------------
// Call contract

abigen!(
AccountContract,
"[{\"type\":\"function\",\"name\":\"get_public_key\",\"inputs\":[],\"outputs\":[{\"type\":\
\"core::felt252\"}],\"state_mutability\":\"view\"}]"
);

// setup contract to interact with (can be any existing contract that can be interacted with)
let contract = AccountContractReader::new(account, &provider);
let _ = contract.get_public_key().call().await.unwrap();
}

0 comments on commit 1deee22

Please sign in to comment.