Skip to content

Commit

Permalink
refactor(blockifier): change return type of invoke_tx deploy_account_…
Browse files Browse the repository at this point in the history
…tx to account_transaction
  • Loading branch information
avivg-starkware committed Nov 7, 2024
1 parent 35360cd commit 309672f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
3 changes: 2 additions & 1 deletion crates/blockifier/src/test_utils/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::transaction::transactions::DeclareTransaction;
pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> AccountTransaction {
let tx_hash = declare_tx_args.tx_hash;
let declare_tx = starknet_api::test_utils::declare::declare_tx(declare_tx_args);
let executable_declare = DeclareTransaction::new(declare_tx, tx_hash, class_info).unwrap();

AccountTransaction::Declare(DeclareTransaction::new(declare_tx, tx_hash, class_info).unwrap())
executable_declare.into()
}
3 changes: 2 additions & 1 deletion crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ pub fn deploy_account_tx(
);
let executable_deploy_account_tx =
DeployAccountTransaction::new(deploy_account_tx, tx_hash, contract_address);
AccountTransaction::DeployAccount(executable_deploy_account_tx)

executable_deploy_account_tx.into()
}
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction {
true => InvokeTransaction::new_for_query(invoke_tx, tx_hash),
false => InvokeTransaction::new(invoke_tx, tx_hash),
};
AccountTransaction::Invoke(invoke_tx)
invoke_tx.into()
}
20 changes: 19 additions & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mod flavors_test;
mod post_execution_test;

/// Represents a paid Starknet transaction.
#[derive(Clone, Debug, derive_more::From)]
#[derive(Clone, Debug)]
pub enum AccountTransaction {
Declare(DeclareTransaction),
DeployAccount(DeployAccountTransaction),
Expand Down Expand Up @@ -142,6 +142,24 @@ impl TryFrom<starknet_api::executable_transaction::Transaction> for AccountTrans
}
}

impl From<DeclareTransaction> for AccountTransaction {
fn from(tx: DeclareTransaction) -> Self {
Self::Declare(tx)
}
}

impl From<DeployAccountTransaction> for AccountTransaction {
fn from(tx: DeployAccountTransaction) -> Self {
Self::DeployAccount(tx)
}
}

impl From<InvokeTransaction> for AccountTransaction {
fn from(tx: InvokeTransaction) -> Self {
Self::Invoke(tx)
}
}

impl HasRelatedFeeType for AccountTransaction {
fn version(&self) -> TransactionVersion {
match self {
Expand Down
21 changes: 10 additions & 11 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,17 +759,16 @@ fn test_fail_declare(block_context: BlockContext, max_fee: Fee) {
state.set_contract_class(class_hash, contract_class.clone().try_into().unwrap()).unwrap();
state.set_compiled_class_hash(class_hash, declare_tx.compiled_class_hash).unwrap();
let class_info = calculate_class_info_for_testing(contract_class);
let declare_account_tx = AccountTransaction::Declare(
DeclareTransaction::new(
starknet_api::transaction::DeclareTransaction::V2(DeclareTransactionV2 {
nonce: next_nonce,
..declare_tx
}),
TransactionHash::default(),
class_info,
)
.unwrap(),
);
let declare_account_tx: AccountTransaction = DeclareTransaction::new(
starknet_api::transaction::DeclareTransaction::V2(DeclareTransactionV2 {
nonce: next_nonce,
..declare_tx
}),
TransactionHash::default(),
class_info,
)
.unwrap()
.into();

// Fail execution, assert nonce and balance are unchanged.
let tx_info = declare_account_tx.create_tx_info();
Expand Down

0 comments on commit 309672f

Please sign in to comment.