diff --git a/crates/mempool_test_utils/src/starknet_api_test_utils.rs b/crates/mempool_test_utils/src/starknet_api_test_utils.rs index d453622065b..aacb36d0e82 100644 --- a/crates/mempool_test_utils/src/starknet_api_test_utils.rs +++ b/crates/mempool_test_utils/src/starknet_api_test_utils.rs @@ -194,6 +194,10 @@ type SharedNonceManager = Rc>; /// let undeployed_account = tx_generator.account_with_id(2).account; /// // Generate a transfer to fund the undeployed account. /// let transfer_tx = tx_generator.account_with_id_mut(0).generate_transfer(&undeployed_account); +/// // Generate a deploy account transaction for the undeployed account. +/// let deploy_account_tx = tx_generator.account_with_id_mut(2).generate_deploy_account(); +/// // Mark the undeployed account as deployed. +/// tx_generator.account_with_id_mut(2).mark_deployed(); /// ``` // Note: when moving this to starknet api crate, see if blockifier's // [blockifier::transaction::test_utils::FaultyAccountTxCreatorArgs] can be made to use this. @@ -278,6 +282,7 @@ pub struct AccountTransactionGenerator { pub account: Contract, pub is_deployed: bool, nonce_manager: SharedNonceManager, + contract_address_salt: ContractAddressSalt, } impl AccountTransactionGenerator { @@ -366,6 +371,27 @@ impl AccountTransactionGenerator { rpc_invoke_tx(invoke_args) } + pub fn generate_deploy_account(&mut self) -> RpcTransaction { + assert!( + !self.is_deployed, + "Cannot deploy an already deployed account: the first transaction of every account \ + must be a deploy account transaction." + ); + let nonce = self.next_nonce(); + assert_ne!(nonce, nonce!(0), "The deploy account tx should have nonce 0."); + let deploy_account_args = deploy_account_tx_args!( + class_hash: self.account.class_hash(), + resource_bounds: test_valid_resource_bounds(), + contract_address_salt: ContractAddressSalt(self.contract_address_salt.0) + ); + rpc_deploy_account_tx(deploy_account_args) + } + + pub fn mark_deployed(&mut self) { + // TODO: Assert that the account is actually deployed once we have a StateReader. + self.is_deployed = true; + } + pub fn sender_address(&self) -> ContractAddress { self.account.sender_address } @@ -395,6 +421,7 @@ impl AccountTransactionGenerator { account: Contract::new_for_account(account, &default_deploy_account_tx), nonce_manager, is_deployed, + contract_address_salt, }; // Bump the account nonce after transaction creation. account_tx_generator.next_nonce();