Skip to content

Commit b5bfbc6

Browse files
starknet_os_flow_tests: utility method to fund address
1 parent 75c61ac commit b5bfbc6

File tree

2 files changed

+38
-60
lines changed

2 files changed

+38
-60
lines changed

crates/starknet_os_flow_tests/src/test_manager.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use blockifier::state::stateful_compression_test_utils::decompress;
1111
use blockifier::test_utils::ALIAS_CONTRACT_ADDRESS;
1212
use blockifier::transaction::objects::TransactionExecutionInfo;
1313
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
14+
use blockifier_test_utils::calldata::create_calldata;
1415
use blockifier_test_utils::contracts::FeatureContract;
1516
use itertools::Itertools;
1617
use starknet_api::abi::abi_utils::get_fee_token_var_address;
@@ -26,10 +27,11 @@ use starknet_api::executable_transaction::{
2627
L1HandlerTransaction,
2728
Transaction as StarknetApiTransaction,
2829
};
30+
use starknet_api::invoke_tx_args;
2931
use starknet_api::state::{SierraContractClass, StorageKey};
3032
use starknet_api::test_utils::invoke::{invoke_tx, InvokeTxArgs};
3133
use starknet_api::test_utils::{NonceManager, CHAIN_ID_FOR_TESTS};
32-
use starknet_api::transaction::fields::Calldata;
34+
use starknet_api::transaction::fields::{Calldata, Tip};
3335
use starknet_api::transaction::MessageToL1;
3436
use starknet_committer::block_committer::input::{IsSubset, StarknetStorageKey, StateDiff};
3537
use starknet_os::io::os_input::{
@@ -60,6 +62,7 @@ use crate::initial_state::{
6062
OsExecutionContracts,
6163
};
6264
use crate::state_trait::FlowTestState;
65+
use crate::tests::NON_TRIVIAL_RESOURCE_BOUNDS;
6366
use crate::utils::{
6467
commit_state_diff,
6568
create_cached_state_input_and_commitment_infos,
@@ -371,6 +374,32 @@ impl<S: FlowTestState> TestManager<S> {
371374
});
372375
}
373376

377+
pub(crate) fn add_fund_address_tx_with_default_amount(
378+
&mut self,
379+
address: ContractAddress,
380+
nonce_manager: &mut NonceManager,
381+
) {
382+
let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS.max_possible_fee(Tip(0)).0;
383+
self.add_fund_address_tx(address, nonce_manager, transfer_amount);
384+
}
385+
386+
pub(crate) fn add_fund_address_tx(
387+
&mut self,
388+
address: ContractAddress,
389+
nonce_manager: &mut NonceManager,
390+
amount: u128,
391+
) {
392+
let transfer_tx_args = invoke_tx_args! {
393+
sender_address: *FUNDED_ACCOUNT_ADDRESS,
394+
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
395+
calldata: create_calldata(
396+
*STRK_FEE_TOKEN_ADDRESS, "transfer", &[**address, Felt::from(amount), Felt::ZERO]
397+
),
398+
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
399+
};
400+
self.add_invoke_tx_from_args(transfer_tx_args, &CHAIN_ID_FOR_TESTS, None);
401+
}
402+
374403
/// Executes the test using default block contexts, starting from the given block number.
375404
pub(crate) async fn execute_test_with_default_block_contexts(
376405
self,

crates/starknet_os_flow_tests/src/tests.rs

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,17 +1034,7 @@ async fn test_v1_bound_accounts_cairo1() {
10341034

10351035
// Transfer funds to the account.
10361036
let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS.max_possible_fee(max_tip).0;
1037-
let transfer_tx_args = invoke_tx_args! {
1038-
sender_address: *FUNDED_ACCOUNT_ADDRESS,
1039-
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
1040-
calldata: create_calldata(
1041-
*STRK_FEE_TOKEN_ADDRESS,
1042-
"transfer",
1043-
&[**v1_bound_account_address, Felt::from(transfer_amount), Felt::ZERO]
1044-
),
1045-
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
1046-
};
1047-
test_manager.add_invoke_tx_from_args(transfer_tx_args, &CHAIN_ID_FOR_TESTS, None);
1037+
test_manager.add_fund_address_tx(v1_bound_account_address, &mut nonce_manager, transfer_amount);
10481038

10491039
// Create an invoke tx, compute the hash, sign the hash and update the signature on the tx.
10501040
let invoke_tx_args = invoke_tx_args! {
@@ -1627,18 +1617,8 @@ async fn test_new_class_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_multi
16271617
)
16281618
.unwrap();
16291619
// Fund the address.
1630-
let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS.max_possible_fee(Tip(0)).0;
1631-
let transfer_tx_args = invoke_tx_args! {
1632-
sender_address: *FUNDED_ACCOUNT_ADDRESS,
1633-
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
1634-
calldata: create_calldata(
1635-
*STRK_FEE_TOKEN_ADDRESS,
1636-
"transfer",
1637-
&[**faulty_account_address, Felt::from(transfer_amount), Felt::ZERO]
1638-
),
1639-
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
1640-
};
1641-
test_manager.add_invoke_tx_from_args(transfer_tx_args, &CHAIN_ID_FOR_TESTS, None);
1620+
test_manager
1621+
.add_fund_address_tx_with_default_amount(faulty_account_address, &mut nonce_manager);
16421622

16431623
// Create a DeployAccount transaction.
16441624
let deploy_tx_args = deploy_account_tx_args! {
@@ -1789,18 +1769,8 @@ async fn test_deprecated_tx_info() {
17891769
.unwrap();
17901770

17911771
// Fund the address.
1792-
let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS.max_possible_fee(Tip(0)).0;
1793-
let transfer_tx_args = invoke_tx_args! {
1794-
sender_address: *FUNDED_ACCOUNT_ADDRESS,
1795-
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
1796-
calldata: create_calldata(
1797-
*STRK_FEE_TOKEN_ADDRESS,
1798-
"transfer",
1799-
&[**tx_info_account_address, Felt::from(transfer_amount), Felt::ZERO]
1800-
),
1801-
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
1802-
};
1803-
test_manager.add_invoke_tx_from_args(transfer_tx_args, &CHAIN_ID_FOR_TESTS, None);
1772+
test_manager
1773+
.add_fund_address_tx_with_default_amount(tx_info_account_address, &mut nonce_manager);
18041774

18051775
// Deploy the account.
18061776
let deploy_tx_args = deploy_account_tx_args! {
@@ -2078,18 +2048,8 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) {
20782048
.unwrap();
20792049

20802050
// Fund the address.
2081-
let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS.max_possible_fee(Tip(0)).0;
2082-
let transfer_tx_args = invoke_tx_args! {
2083-
sender_address: *FUNDED_ACCOUNT_ADDRESS,
2084-
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
2085-
calldata: create_calldata(
2086-
*STRK_FEE_TOKEN_ADDRESS,
2087-
"transfer",
2088-
&[**block_info_account_address, Felt::from(transfer_amount), Felt::ZERO]
2089-
),
2090-
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
2091-
};
2092-
test_manager.add_invoke_tx_from_args(transfer_tx_args, &CHAIN_ID_FOR_TESTS, None);
2051+
test_manager
2052+
.add_fund_address_tx_with_default_amount(block_info_account_address, &mut nonce_manager);
20932053

20942054
// Deploy the contract using a DeployAccount transaction.
20952055
let deploy_account_tx_args = deploy_account_tx_args! {
@@ -2166,18 +2126,7 @@ async fn test_initial_sierra_gas() {
21662126
.await;
21672127

21682128
// Fund the account.
2169-
let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS.max_possible_fee(Tip(0)).0;
2170-
let fund_tx_args = invoke_tx_args! {
2171-
sender_address: *FUNDED_ACCOUNT_ADDRESS,
2172-
nonce: nonce_manager.next(*FUNDED_ACCOUNT_ADDRESS),
2173-
calldata: create_calldata(
2174-
*STRK_FEE_TOKEN_ADDRESS,
2175-
"transfer",
2176-
&[**account_address, Felt::from(transfer_amount), Felt::ZERO]
2177-
),
2178-
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
2179-
};
2180-
test_manager.add_invoke_tx_from_args(fund_tx_args, &CHAIN_ID_FOR_TESTS, None);
2129+
test_manager.add_fund_address_tx_with_default_amount(account_address, &mut nonce_manager);
21812130

21822131
// Test invoke gas limits.
21832132
let os_constants = &VersionedConstants::latest_constants().os_constants;

0 commit comments

Comments
 (0)