Skip to content

Commit

Permalink
chore(blockifier): add runnable cairo version to the cairo version enum
Browse files Browse the repository at this point in the history
  • Loading branch information
meship-starkware committed Dec 8, 2024
1 parent c97fe52 commit f8fbee1
Show file tree
Hide file tree
Showing 33 changed files with 406 additions and 288 deletions.
4 changes: 2 additions & 2 deletions crates/blockifier/src/blockifier/block_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use crate::context::ChainInfo;
use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, BALANCE};
use crate::test_utils::{CairoVersion, RunnableCairo1, BALANCE};
use crate::versioned_constants::VersionedConstants;

#[test]
fn test_pre_process_block() {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
let mut state = test_state(&ChainInfo::create_for_testing(), BALANCE, &[(test_contract, 1)]);
let os_constants = VersionedConstants::create_for_testing().os_constants;

Expand Down
7 changes: 4 additions & 3 deletions crates/blockifier/src/blockifier/stateful_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::blockifier::stateful_validator::StatefulValidator;
use crate::context::BlockContext;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state};
use crate::test_utils::{CairoVersion, BALANCE};
use crate::test_utils::{CairoVersion, RunnableCairo1, BALANCE};
use crate::transaction::test_utils::{
block_context,
create_account_tx_for_validate_test_nonce_0,
Expand Down Expand Up @@ -37,7 +37,8 @@ fn test_tx_validator(
block_context: BlockContext,
#[values(default_l1_resource_bounds(), default_all_resource_bounds())]
resource_bounds: ValidResourceBounds,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
cairo_version: CairoVersion,
) {
let chain_info = &block_context.chain_info;

Expand Down Expand Up @@ -83,7 +84,7 @@ fn test_tx_validator_skip_validate(
resource_bounds: ValidResourceBounds,
) {
let block_context = BlockContext::create_for_testing();
let faulty_account = FeatureContract::FaultyAccount(CairoVersion::Cairo1);
let faulty_account = FeatureContract::FaultyAccount(CairoVersion::Cairo1(RunnableCairo1::Casm));
let state = test_state(&block_context.chain_info, BALANCE, &[(faulty_account, 1)]);

// Create a transaction that does not pass validations.
Expand Down
27 changes: 18 additions & 9 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::test_utils::{
create_calldata,
maybe_dummy_block_hash_and_number,
CairoVersion,
RunnableCairo1,
BALANCE,
DEFAULT_STRK_L1_GAS_PRICE,
};
Expand Down Expand Up @@ -92,7 +93,7 @@ fn tx_executor_test_body<S: StateReader>(
)]
#[case::tx_version_2(
TransactionVersion::TWO,
CairoVersion::Cairo1,
CairoVersion::Cairo1(RunnableCairo1::Casm),
BouncerWeights {
state_diff_size: 4,
message_segment_length: 0,
Expand All @@ -102,7 +103,7 @@ fn tx_executor_test_body<S: StateReader>(
)]
#[case::tx_version_3(
TransactionVersion::THREE,
CairoVersion::Cairo1,
CairoVersion::Cairo1(RunnableCairo1::Casm),
BouncerWeights {
state_diff_size: 4,
message_segment_length: 0,
Expand All @@ -112,7 +113,8 @@ fn tx_executor_test_body<S: StateReader>(
)]
fn test_declare(
block_context: BlockContext,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
account_cairo_version: CairoVersion,
#[case] tx_version: TransactionVersion,
#[case] cairo_version: CairoVersion,
#[case] expected_bouncer_weights: BouncerWeights,
Expand All @@ -139,7 +141,8 @@ fn test_declare(
fn test_deploy_account(
block_context: BlockContext,
#[values(TransactionVersion::ONE, TransactionVersion::THREE)] version: TransactionVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
cairo_version: CairoVersion,
) {
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 0)]);
Expand Down Expand Up @@ -204,7 +207,8 @@ fn test_deploy_account(
fn test_invoke(
block_context: BlockContext,
#[values(TransactionVersion::ONE, TransactionVersion::THREE)] version: TransactionVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
cairo_version: CairoVersion,
#[case] entry_point_name: &str,
#[case] entry_point_args: Vec<Felt>,
#[case] expected_bouncer_weights: BouncerWeights,
Expand All @@ -230,7 +234,7 @@ fn test_invoke(

#[rstest]
fn test_l1_handler(block_context: BlockContext) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
let state = test_state(&block_context.chain_info, BALANCE, &[(test_contract, 1)]);

let tx = Transaction::L1Handler(l1handler_tx(
Expand Down Expand Up @@ -265,7 +269,10 @@ fn test_bouncing(#[case] initial_bouncer_weights: BouncerWeights, #[case] n_even
let block_context = BlockContext::create_for_bouncer_testing(max_n_events_in_block);

let TestInitData { state, account_address, contract_address, mut nonce_manager } =
create_test_init_data(&block_context.chain_info, CairoVersion::Cairo1);
create_test_init_data(
&block_context.chain_info,
CairoVersion::Cairo1(RunnableCairo1::Casm),
);

// TODO(Yoni, 15/6/2024): turn on concurrency mode.
let mut tx_executor =
Expand Down Expand Up @@ -293,8 +300,10 @@ fn test_execute_txs_bouncing(#[values(true, false)] concurrency_enabled: bool) {
let max_n_events_in_block = 10;
let block_context = BlockContext::create_for_bouncer_testing(max_n_events_in_block);

let TestInitData { state, account_address, contract_address, .. } =
create_test_init_data(&block_context.chain_info, CairoVersion::Cairo1);
let TestInitData { state, account_address, contract_address, .. } = create_test_init_data(
&block_context.chain_info,
CairoVersion::Cairo1(RunnableCairo1::Casm),
);

let mut tx_executor = TransactionExecutor::new(state, block_context, config);

Expand Down
10 changes: 6 additions & 4 deletions crates/blockifier/src/concurrency/fee_utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::fee::fee_utils::get_sequencer_balance_keys;
use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state, test_state_inner};
use crate::test_utils::{create_trivial_calldata, CairoVersion, BALANCE};
use crate::test_utils::{create_trivial_calldata, CairoVersion, RunnableCairo1, BALANCE};
use crate::transaction::test_utils::{
block_context,
default_all_resource_bounds,
Expand All @@ -23,9 +23,11 @@ use crate::transaction::test_utils::{
pub fn test_fill_sequencer_balance_reads(
block_context: BlockContext,
default_all_resource_bounds: ValidResourceBounds,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] erc20_version: CairoVersion,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm))]
erc20_version: CairoVersion,
) {
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let account_tx = invoke_tx_with_default_flags(invoke_tx_args! {
sender_address: account.get_instance_address(0),
calldata: create_trivial_calldata(account.get_instance_address(0)),
Expand Down Expand Up @@ -61,7 +63,7 @@ pub fn test_add_fee_to_sequencer_balance(
#[case] sequencer_balance_high: Felt,
) {
let block_context = BlockContext::create_for_account_testing();
let account = FeatureContract::Empty(CairoVersion::Cairo1);
let account = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm));
let mut state = test_state(&block_context.chain_info, Fee(0), &[(account, 1)]);
let (sequencer_balance_key_low, sequencer_balance_key_high) =
get_sequencer_balance_keys(&block_context);
Expand Down
21 changes: 14 additions & 7 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::state::state_api::{State, StateReader, UpdatableState};
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::test_utils::{CairoVersion, RunnableCairo1, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{default_all_resource_bounds, l1_resource_bounds};
Expand Down Expand Up @@ -116,7 +116,8 @@ fn test_versioned_state_proxy() {
let class_hash_v10 = class_hash!(29_u8);
let compiled_class_hash_v18 = compiled_class_hash!(30_u8);
let contract_class_v11 =
FeatureContract::TestContract(CairoVersion::Cairo1).get_runnable_class();
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm))
.get_runnable_class();

versioned_state_proxys[3].state().apply_writes(
3,
Expand Down Expand Up @@ -404,7 +405,8 @@ fn test_false_validate_reads_declared_contracts(
};
let version_state_proxy = safe_versioned_state.pin_version(0);
let compiled_contract_calss =
FeatureContract::TestContract(CairoVersion::Cairo1).get_runnable_class();
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm))
.get_runnable_class();
let class_hash_to_class = HashMap::from([(class_hash!(1_u8), compiled_contract_calss)]);
version_state_proxy.state().apply_writes(0, &tx_0_writes, &class_hash_to_class);
assert!(!safe_versioned_state.pin_version(1).validate_reads(&tx_1_reads));
Expand All @@ -429,7 +431,9 @@ fn test_apply_writes(
assert_eq!(transactional_states[0].cache.borrow().writes.class_hashes.len(), 1);

// Transaction 0 contract class.
let contract_class_0 = FeatureContract::TestContract(CairoVersion::Cairo1).get_runnable_class();
let contract_class_0 =
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm))
.get_runnable_class();
assert!(transactional_states[0].class_hash_to_class.borrow().is_empty());
transactional_states[0].set_contract_class(class_hash, contract_class_0.clone()).unwrap();
assert_eq!(transactional_states[0].class_hash_to_class.borrow().len(), 1);
Expand Down Expand Up @@ -498,7 +502,8 @@ fn test_delete_writes(
(contract_address!("0x100"), class_hash!(20_u8)),
(contract_address!("0x200"), class_hash!(21_u8)),
];
let feature_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let feature_contract =
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
for (i, tx_state) in transactional_states.iter_mut().enumerate() {
// Modify the `cache` member of the CachedState.
for (contract_address, class_hash) in contract_addresses.iter() {
Expand Down Expand Up @@ -553,7 +558,8 @@ fn test_delete_writes(
fn test_delete_writes_completeness(
safe_versioned_state: ThreadSafeVersionedState<CachedState<DictStateReader>>,
) {
let feature_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let feature_contract =
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
let state_maps_writes = StateMaps {
nonces: HashMap::from([(contract_address!("0x1"), nonce!(1_u8))]),
class_hashes: HashMap::from([(
Expand Down Expand Up @@ -633,7 +639,8 @@ fn test_versioned_proxy_state_flow(
// Clients contract class values.
let contract_class_0 = FeatureContract::TestContract(CairoVersion::Cairo0).get_runnable_class();
let contract_class_2 =
FeatureContract::AccountWithLongValidate(CairoVersion::Cairo1).get_runnable_class();
FeatureContract::AccountWithLongValidate(CairoVersion::Cairo1(RunnableCairo1::Casm))
.get_runnable_class();

transactional_states[0].set_contract_class(class_hash, contract_class_0).unwrap();
transactional_states[2].set_contract_class(class_hash, contract_class_2.clone()).unwrap();
Expand Down
24 changes: 16 additions & 8 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::test_utils::{
create_calldata,
create_trivial_calldata,
CairoVersion,
RunnableCairo1,
BALANCE,
TEST_ERC20_CONTRACT_ADDRESS2,
};
Expand Down Expand Up @@ -80,7 +81,8 @@ fn verify_sequencer_balance_update<S: StateReader>(
#[rstest]
pub fn test_commit_tx() {
let block_context = BlockContext::create_for_account_testing();
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let mut expected_sequencer_balance_low = 0_u128;
let mut nonce_manager = NonceManager::default();
Expand Down Expand Up @@ -186,7 +188,8 @@ pub fn test_commit_tx() {
// commit tx should be the same (except for re-execution changes).
fn test_commit_tx_when_sender_is_sequencer() {
let mut block_context = BlockContext::create_for_account_testing();
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let account_address = account.get_instance_address(0_u16);
let test_contract_address = test_contract.get_instance_address(0_u16);
Expand Down Expand Up @@ -253,7 +256,8 @@ fn test_commit_tx_when_sender_is_sequencer() {
fn test_worker_execute(default_all_resource_bounds: ValidResourceBounds) {
// Settings.
let block_context = BlockContext::create_for_account_testing();
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account_contract =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let chain_info = &block_context.chain_info;

Expand Down Expand Up @@ -427,7 +431,8 @@ fn test_worker_execute(default_all_resource_bounds: ValidResourceBounds) {
fn test_worker_validate(default_all_resource_bounds: ValidResourceBounds) {
// Settings.
let block_context = BlockContext::create_for_account_testing();
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account_contract =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let chain_info = &block_context.chain_info;

Expand Down Expand Up @@ -528,7 +533,7 @@ fn test_worker_validate(default_all_resource_bounds: ValidResourceBounds) {

#[rstest]
#[case::declare_cairo0(CairoVersion::Cairo0, TransactionVersion::ONE)]
#[case::declare_cairo1(CairoVersion::Cairo1, TransactionVersion::THREE)]
#[case::declare_cairo1(CairoVersion::Cairo1(RunnableCairo1::Casm), TransactionVersion::THREE)]
fn test_deploy_before_declare(
max_fee: Fee,
default_all_resource_bounds: ValidResourceBounds,
Expand All @@ -538,7 +543,8 @@ fn test_deploy_before_declare(
// Create the state.
let block_context = BlockContext::create_for_account_testing();
let chain_info = &block_context.chain_info;
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account_contract =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let state = test_state(chain_info, BALANCE, &[(account_contract, 2)]);
let safe_versioned_state = safe_versioned_state_for_testing(state);

Expand Down Expand Up @@ -624,7 +630,8 @@ fn test_deploy_before_declare(
fn test_worker_commit_phase(default_all_resource_bounds: ValidResourceBounds) {
// Settings.
let block_context = BlockContext::create_for_account_testing();
let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account_contract =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let chain_info = &block_context.chain_info;

Expand Down Expand Up @@ -717,7 +724,8 @@ fn test_worker_commit_phase_with_halt() {
let max_n_events_in_block = 3;
let block_context = BlockContext::create_for_bouncer_testing(max_n_events_in_block);

let account_contract = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1);
let account_contract =
FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm));
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let chain_info = &block_context.chain_info;

Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/execution/entry_point_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::state::cached_state::CachedState;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, BALANCE};
use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, RunnableCairo1, BALANCE};
use crate::versioned_constants::VersionedConstants;

#[test]
Expand Down Expand Up @@ -514,7 +514,7 @@ fn test_storage_related_members() {

#[test]
fn test_cairo1_entry_point_segment_arena() {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);
let calldata = calldata![];
Expand Down
Loading

0 comments on commit f8fbee1

Please sign in to comment.