Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mempool_test_utils): util to generate deploy account txs #2805

Open
wants to merge 1 commit into
base: yair/transfers
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ type SharedNonceManager = Rc<RefCell<NonceManager>>;
/// 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.
Expand Down Expand Up @@ -273,6 +277,7 @@ pub struct AccountTransactionGenerator {
pub account: Contract,
pub is_deployed: bool,
nonce_manager: SharedNonceManager,
contract_address_salt: ContractAddressSalt,
}

impl AccountTransactionGenerator {
Expand Down Expand Up @@ -361,6 +366,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
}
Expand Down Expand Up @@ -390,6 +416,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();
Expand Down