Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix(transaction): change deploy_account deafult version to be V3
Browse files Browse the repository at this point in the history
  • Loading branch information
meship-starkware committed Jul 10, 2024
1 parent 70fe33a commit e386bd4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
20 changes: 11 additions & 9 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use rstest::{fixture, rstest};
use starknet_api::core::{
calculate_contract_address, ClassHash, ContractAddress, Nonce, PatriciaKey,
};
use starknet_api::transaction::{Calldata, ContractAddressSalt, Fee, TransactionVersion};
use starknet_api::transaction::{
Calldata, ContractAddressSalt, Fee, ResourceBoundsMapping, TransactionVersion,
};
use starknet_api::{calldata, class_hash, contract_address, felt, patricia_key};

use crate::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address};
Expand All @@ -28,10 +30,10 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::deploy_account::deploy_account_tx;
use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, NonceManager, BALANCE, DEFAULT_STRK_L1_GAS_PRICE, MAX_FEE};
use crate::test_utils::{CairoVersion, NonceManager, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::{FeeType, TransactionInfoCreator};
use crate::transaction::test_utils::l1_resource_bounds;
use crate::transaction::test_utils::{l1_resource_bounds, max_resource_bounds};
use crate::transaction::transactions::ExecutableTransaction;
use crate::{compiled_class_hash, deploy_account_tx_args, nonce, storage_key};

Expand Down Expand Up @@ -188,9 +190,9 @@ fn test_versioned_state_proxy() {
);
}

#[test]
#[rstest]
// Test parallel execution of two transactions that use the same versioned state.
fn test_run_parallel_txs() {
fn test_run_parallel_txs(max_resource_bounds: ResourceBoundsMapping) {
let block_context = BlockContext::create_for_account_testing();
let chain_info = &block_context.chain_info;
let zero_bounds = true;
Expand Down Expand Up @@ -232,7 +234,7 @@ fn test_run_parallel_txs() {
let constructor_calldata = calldata![ctor_grind_arg, ctor_storage_arg];
let deploy_tx_args = deploy_account_tx_args! {
class_hash,
max_fee: Fee(MAX_FEE),
resource_bounds: max_resource_bounds,
constructor_calldata: constructor_calldata.clone(),
};
let nonce_manager = &mut NonceManager::default();
Expand All @@ -241,7 +243,7 @@ fn test_run_parallel_txs() {
let account_tx_2 = AccountTransaction::DeployAccount(deploy_account_tx_2);

let deployed_account_balance_key = get_fee_token_var_address(account_address);
let fee_token_address = chain_info.fee_token_address(&FeeType::Eth);
let fee_token_address = chain_info.fee_token_address(&FeeType::Strk);
state_2
.set_storage_at(fee_token_address, deployed_account_balance_key, felt!(BALANCE))
.unwrap();
Expand All @@ -255,8 +257,8 @@ fn test_run_parallel_txs() {
assert_eq!(result.is_err(), enforce_fee);
});
s.spawn(move || {
account_tx_2.execute(&mut state_2, &block_context_2, true, true).unwrap();

let result = account_tx_2.execute(&mut state_2, &block_context_2, true, true);
result.unwrap();
// Check that the constructor wrote ctor_arg to the storage.
let storage_key = get_storage_var_address("ctor_arg", &[]);
let deployed_contract_address = calculate_contract_address(
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl Default for DeployAccountTxArgs {
max_fee: Fee::default(),
signature: TransactionSignature::default(),
deployer_address: ContractAddress::default(),
// TODO(Meshi, 01/09/2024): Change default version to THREE.
version: TransactionVersion::ONE,
version: TransactionVersion::THREE,
resource_bounds: default_testing_resource_bounds(),
tip: Tip::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ fn test_infinite_recursion(
#[case(TransactionVersion::ONE)]
#[case(TransactionVersion::THREE)]
fn test_max_fee_limit_validate(
max_fee: Fee,
block_context: BlockContext,
#[case] version: TransactionVersion,
max_resource_bounds: ResourceBoundsMapping,
Expand Down Expand Up @@ -307,7 +306,7 @@ fn test_max_fee_limit_validate(
chain_info,
deploy_account_tx_args! {
class_hash: grindy_class_hash,
max_fee,
resource_bounds: max_resource_bounds.clone(),
constructor_calldata: calldata![ctor_grind_arg, ctor_storage_arg],
},
);
Expand All @@ -323,7 +322,7 @@ fn test_max_fee_limit_validate(
chain_info,
deploy_account_tx_args! {
class_hash: grindy_class_hash,
max_fee,
resource_bounds: max_resource_bounds.clone(),
constructor_calldata: calldata![ctor_grind_arg, ctor_storage_arg],
},
);
Expand Down Expand Up @@ -983,7 +982,7 @@ fn test_insufficient_max_fee_reverts(

#[rstest]
fn test_deploy_account_constructor_storage_write(
max_fee: Fee,
max_resource_bounds: ResourceBoundsMapping,
block_context: BlockContext,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
) {
Expand All @@ -1001,7 +1000,7 @@ fn test_deploy_account_constructor_storage_write(
chain_info,
deploy_account_tx_args! {
class_hash,
max_fee,
resource_bounds: max_resource_bounds,
constructor_calldata: constructor_calldata.clone(),
},
);
Expand Down
17 changes: 11 additions & 6 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ fn assert_failure_if_resource_bounds_exceed_balance(
#[rstest]
fn test_max_fee_exceeds_balance(
block_context: BlockContext,
max_resource_bounds: ResourceBoundsMapping,
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion,
) {
let block_context = &block_context;
Expand Down Expand Up @@ -811,7 +812,7 @@ fn test_max_fee_exceeds_balance(
// Deploy.
let invalid_tx = AccountTransaction::DeployAccount(deploy_account_tx(
deploy_account_tx_args! {
max_fee: Fee(MAX_FEE),
resource_bounds: max_resource_bounds,
class_hash: test_contract.get_class_hash()
},
&mut NonceManager::default(),
Expand Down Expand Up @@ -1220,6 +1221,7 @@ fn test_declare_tx(
fn test_deploy_account_tx(
#[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] cairo_version: CairoVersion,
#[values(false, true)] use_kzg_da: bool,
max_resource_bounds: ResourceBoundsMapping,
) {
let block_context = &BlockContext::create_for_account_testing_with_kzg(use_kzg_da);
let versioned_constants = &block_context.versioned_constants;
Expand All @@ -1229,7 +1231,7 @@ fn test_deploy_account_tx(
let account_class_hash = account.get_class_hash();
let state = &mut test_state(chain_info, BALANCE, &[(account, 1)]);
let deploy_account = deploy_account_tx(
deploy_account_tx_args! { max_fee: Fee(MAX_FEE), class_hash: account_class_hash },
deploy_account_tx_args! { resource_bounds: max_resource_bounds.clone(), class_hash: account_class_hash },
&mut nonce_manager,
);

Expand Down Expand Up @@ -1369,7 +1371,7 @@ fn test_deploy_account_tx(
// Negative flow.
// Deploy to an existing address.
let deploy_account = deploy_account_tx(
deploy_account_tx_args! { max_fee: Fee(MAX_FEE), class_hash: account_class_hash },
deploy_account_tx_args! { resource_bounds: max_resource_bounds, class_hash: account_class_hash },
&mut nonce_manager,
);
let account_tx = AccountTransaction::DeployAccount(deploy_account);
Expand All @@ -1388,21 +1390,24 @@ fn test_deploy_account_tx(
}

#[rstest]
fn test_fail_deploy_account_undeclared_class_hash(block_context: BlockContext) {
fn test_fail_deploy_account_undeclared_class_hash(
block_context: BlockContext,
max_resource_bounds: ResourceBoundsMapping,
) {
let block_context = &block_context;
let chain_info = &block_context.chain_info;
let state = &mut test_state(chain_info, BALANCE, &[]);
let mut nonce_manager = NonceManager::default();
let undeclared_hash = class_hash!("0xdeadbeef");
let deploy_account = deploy_account_tx(
deploy_account_tx_args! { max_fee: Fee(MAX_FEE), class_hash: undeclared_hash },
deploy_account_tx_args! {resource_bounds: max_resource_bounds, class_hash: undeclared_hash },
&mut nonce_manager,
);

// Fund account, so as not to fail pre-validation.
state
.set_storage_at(
chain_info.fee_token_address(&FeeType::Eth),
chain_info.fee_token_address(&FeeType::Strk),
get_fee_token_var_address(deploy_account.contract_address),
felt!(BALANCE),
)
Expand Down

0 comments on commit e386bd4

Please sign in to comment.