Skip to content

Commit

Permalink
chore(blockifier): invoke() declare() deploy_account() change ret val…
Browse files Browse the repository at this point in the history
… to api_tx
  • Loading branch information
avivg-starkware committed Dec 3, 2024
1 parent 0502be4 commit 48dec19
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 93 deletions.
13 changes: 7 additions & 6 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::test_utils::{
BALANCE,
DEFAULT_STRK_L1_GAS_PRICE,
};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::test_utils::{
account_invoke_tx,
Expand Down Expand Up @@ -120,7 +121,7 @@ fn test_declare(
let declared_contract = FeatureContract::Empty(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 1)]);

let tx = declare_tx(
let declare_tx = declare_tx(
declare_tx_args! {
sender_address: account_contract.get_instance_address(0),
class_hash: declared_contract.get_class_hash(),
Expand All @@ -129,8 +130,8 @@ fn test_declare(
resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()),
},
calculate_class_info_for_testing(declared_contract.get_class()),
)
.into();
);
let tx = AccountTransaction { tx: declare_tx, only_query: false }.into();
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

Expand All @@ -143,15 +144,15 @@ fn test_deploy_account(
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 0)]);

let tx = deploy_account_tx(
let deploy_account_tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_contract.get_class_hash(),
resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()),
version,
},
&mut NonceManager::default(),
)
.into();
);
let tx = AccountTransaction { tx: deploy_account_tx, only_query: false }.into();
let expected_bouncer_weights = BouncerWeights {
state_diff_size: 3,
message_segment_length: 0,
Expand Down
9 changes: 7 additions & 2 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ 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, 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};
use crate::transaction::transactions::ExecutableTransaction;
Expand Down Expand Up @@ -225,7 +226,7 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
let mut state_2 = TransactionalState::create_transactional(&mut versioned_state_proxy_2);

// Prepare transactions
let deploy_account_tx_1 = deploy_account_tx(
let tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_without_validation.get_class_hash(),
resource_bounds: l1_resource_bounds(
Expand All @@ -235,6 +236,7 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
},
&mut NonceManager::default(),
);
let deploy_account_tx_1 = AccountTransaction { tx, only_query: false };
let enforce_fee = deploy_account_tx_1.enforce_fee();

let class_hash = grindy_account.get_class_hash();
Expand All @@ -247,7 +249,10 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
constructor_calldata: constructor_calldata.clone(),
};
let nonce_manager = &mut NonceManager::default();
let delpoy_account_tx_2 = deploy_account_tx(deploy_tx_args, nonce_manager);
let delpoy_account_tx_2 = AccountTransaction {
tx: deploy_account_tx(deploy_tx_args, nonce_manager),
only_query: false,
};
let account_address = delpoy_account_tx_2.sender_address();
let tx_context = block_context.to_tx_context(&delpoy_account_tx_2);
let fee_type = tx_context.tx_info.fee_type();
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn test_deploy_before_declare(
let test_class_hash = test_contract.get_class_hash();
let test_class_info = calculate_class_info_for_testing(test_contract.get_class());
let test_compiled_class_hash = test_contract.get_compiled_class_hash();
let declare_tx = declare_tx(
let tx = declare_tx(
declare_tx_args! {
sender_address: account_address_0,
resource_bounds: default_all_resource_bounds,
Expand All @@ -561,6 +561,7 @@ fn test_deploy_before_declare(
},
test_class_info.clone(),
);
let declare_tx = AccountTransaction { tx, only_query: false };

// Deploy test contract.
let invoke_tx = account_invoke_tx(invoke_tx_args! {
Expand Down
8 changes: 4 additions & 4 deletions crates/blockifier/src/test_utils/declare.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use starknet_api::contract_class::ClassInfo;
use starknet_api::executable_transaction::AccountTransaction as ExecutableTransaction;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::declare::{executable_declare_tx, DeclareTxArgs};

use crate::transaction::account_transaction::AccountTransaction;

// TODO(AvivG): remove this func & file.
pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> AccountTransaction {
// TODO(AvivG): see into making 'executable_declare_tx' ret type AccountTransaction.
let declare_tx = executable_declare_tx(declare_tx_args, class_info);

AccountTransaction { tx: ExecutableTransaction::Declare(declare_tx), only_query: false }
AccountTransaction::Declare(declare_tx)
}
11 changes: 4 additions & 7 deletions crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use starknet_api::executable_transaction::AccountTransaction as ExecutableTransaction;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::deploy_account::{executable_deploy_account_tx, DeployAccountTxArgs};
use starknet_api::test_utils::NonceManager;

use crate::transaction::account_transaction::AccountTransaction;

// TODO(AvivG): remove this func & file.
pub fn deploy_account_tx(
deploy_tx_args: DeployAccountTxArgs,
nonce_manager: &mut NonceManager,
) -> AccountTransaction {
// TODO(AvivG): see into making 'executable_deploy_account_tx' ret type AccountTransaction.
let deploy_account_tx = executable_deploy_account_tx(deploy_tx_args, nonce_manager);

AccountTransaction {
tx: ExecutableTransaction::DeployAccount(deploy_account_tx),
only_query: false,
}
AccountTransaction::DeployAccount(deploy_account_tx)
}
11 changes: 4 additions & 7 deletions crates/blockifier/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use starknet_api::executable_transaction::AccountTransaction as ExecutableTransaction;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs};

use crate::transaction::account_transaction::AccountTransaction;

// TODO(AvivG): remove this func & file.
pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction {
let only_query = invoke_args.only_query;
let invoke_tx = ExecutableTransaction::Invoke(executable_invoke_tx(invoke_args));

AccountTransaction { tx: invoke_tx, only_query }
// TODO(AvivG): see into making 'executable_invoke_tx' ret type AccountTransaction.
AccountTransaction::Invoke(executable_invoke_tx(invoke_args))
}
6 changes: 4 additions & 2 deletions crates/blockifier/src/test_utils/transfers_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use starknet_api::abi::abi_utils::selector_from_name;
use starknet_api::core::ContractAddress;
use starknet_api::executable_transaction::AccountTransaction as ApiExecutableTransaction;
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::constants::TRANSFER_ENTRY_POINT_NAME;
use starknet_api::transaction::fields::Fee;
Expand Down Expand Up @@ -143,7 +144,8 @@ impl TransfersGenerator {
let recipient_address = self.get_next_recipient();
self.sender_index = (self.sender_index + 1) % self.account_addresses.len();

let account_tx = self.generate_transfer(sender_address, recipient_address);
let tx = self.generate_transfer(sender_address, recipient_address);
let account_tx = AccountTransaction { tx, only_query: false };
txs.push(Transaction::Account(account_tx));
}
let results = self.executor.execute_txs(&txs);
Expand All @@ -159,7 +161,7 @@ impl TransfersGenerator {
&mut self,
sender_address: ContractAddress,
recipient_address: ContractAddress,
) -> AccountTransaction {
) -> ApiExecutableTransaction {
let nonce = self.nonce_manager.next(sender_address);

let entry_point_selector = selector_from_name(TRANSFER_ENTRY_POINT_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn test_fee_enforcement(
) {
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0);
let state = &mut test_state(&block_context.chain_info, BALANCE, &[(account, 1)]);
let deploy_account_tx = deploy_account_tx(
let tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account.get_class_hash(),
max_fee: Fee(if zero_bounds { 0 } else { MAX_FEE.0 }),
Expand All @@ -212,6 +212,7 @@ fn test_fee_enforcement(
},
&mut NonceManager::default(),
);
let deploy_account_tx = AccountTransaction { tx, only_query: false };

let enforce_fee = deploy_account_tx.enforce_fee();
assert_ne!(zero_bounds, enforce_fee);
Expand Down Expand Up @@ -451,7 +452,7 @@ fn test_max_fee_limit_validate(
let class_info = calculate_class_info_for_testing(grindy_validate_account.get_class());

// Declare the grindy-validation account.
let account_tx = declare_tx(
let tx = declare_tx(
declare_tx_args! {
class_hash: grindy_class_hash,
sender_address: account_address,
Expand All @@ -460,6 +461,7 @@ fn test_max_fee_limit_validate(
},
class_info,
);
let account_tx = AccountTransaction { tx, only_query: false };
account_tx.execute(&mut state, &block_context, true, true).unwrap();

// Deploy grindy account with a lot of grind in the constructor.
Expand Down
23 changes: 15 additions & 8 deletions crates/blockifier/src/transaction/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ pub fn deploy_and_fund_account(
deploy_tx_args: DeployAccountTxArgs,
) -> (AccountTransaction, ContractAddress) {
// Deploy an account contract.
let deploy_account_tx = deploy_account_tx(deploy_tx_args, nonce_manager);
let deploy_account_tx = AccountTransaction {
tx: deploy_account_tx(deploy_tx_args, nonce_manager),
only_query: false,
};
let account_address = deploy_account_tx.sender_address();

// Update the balance of the about-to-be deployed account contract in the erc20 contract, so it
Expand Down Expand Up @@ -235,7 +238,7 @@ pub fn create_account_tx_for_validate_test(
};
let class_hash = declared_contract.get_class_hash();
let class_info = calculate_class_info_for_testing(declared_contract.get_class());
declare_tx(
let tx = declare_tx(
declare_tx_args! {
max_fee,
resource_bounds,
Expand All @@ -247,7 +250,8 @@ pub fn create_account_tx_for_validate_test(
compiled_class_hash: declared_contract.get_compiled_class_hash(),
},
class_info,
)
);
AccountTransaction { tx, only_query: false }
}
TransactionType::DeployAccount => {
// We do not use the sender address here because the transaction generates the actual
Expand All @@ -256,7 +260,7 @@ pub fn create_account_tx_for_validate_test(
true => constants::FELT_TRUE,
false => constants::FELT_FALSE,
})];
deploy_account_tx(
let tx = deploy_account_tx(
deploy_account_tx_args! {
max_fee,
resource_bounds,
Expand All @@ -267,26 +271,29 @@ pub fn create_account_tx_for_validate_test(
constructor_calldata,
},
nonce_manager,
)
);
AccountTransaction { tx, only_query: false }
}
TransactionType::InvokeFunction => {
let execute_calldata = create_calldata(sender_address, "foo", &[]);
invoke_tx(invoke_tx_args! {
let tx = invoke_tx(invoke_tx_args! {
max_fee,
resource_bounds,
signature,
sender_address,
calldata: execute_calldata,
version: tx_version,
nonce: nonce_manager.next(sender_address),
})
});
AccountTransaction { tx, only_query: false }
}
_ => panic!("{tx_type:?} is not an account transaction."),
}
}

pub fn account_invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction {
invoke_tx(invoke_args)
let only_query = invoke_args.only_query;
AccountTransaction { tx: invoke_tx(invoke_args), only_query }
}

pub fn run_invoke_tx(
Expand Down
Loading

0 comments on commit 48dec19

Please sign in to comment.