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

style: avoid repetion in Transaction variant names #222

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/blockifier/src/blockifier/stateful_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<S: StateReader> StatefulValidator<S> {
}

fn execute(&mut self, tx: AccountTransaction) -> StatefulValidatorResult<()> {
self.tx_executor.execute(&Transaction::AccountTransaction(tx))?;
self.tx_executor.execute(&Transaction::Account(tx))?;
Ok(())
}

Expand Down
12 changes: 6 additions & 6 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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 = Transaction::AccountTransaction(declare_tx(
let tx = Transaction::Account(declare_tx(
declare_tx_args! {
sender_address: account_contract.get_instance_address(0),
class_hash: declared_contract.get_class_hash(),
Expand All @@ -136,7 +136,7 @@ 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 = Transaction::AccountTransaction(AccountTransaction::DeployAccount(deploy_account_tx(
let tx = Transaction::Account(AccountTransaction::DeployAccount(deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_contract.get_class_hash(),
resource_bounds: l1_resource_bounds(0, DEFAULT_STRK_L1_GAS_PRICE),
Expand Down Expand Up @@ -209,7 +209,7 @@ fn test_invoke(

let calldata =
create_calldata(test_contract.get_instance_address(0), entry_point_name, &entry_point_args);
let tx = Transaction::AccountTransaction(account_invoke_tx(invoke_tx_args! {
let tx = Transaction::Account(account_invoke_tx(invoke_tx_args! {
sender_address: account_contract.get_instance_address(0),
calldata,
version,
Expand All @@ -222,7 +222,7 @@ fn test_l1_handler(block_context: BlockContext) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let state = test_state(&block_context.chain_info, BALANCE, &[(test_contract, 1)]);

let tx = Transaction::L1HandlerTransaction(L1HandlerTransaction::create_for_testing(
let tx = Transaction::L1Handler(L1HandlerTransaction::create_for_testing(
Fee(1908000000000000),
test_contract.get_instance_address(0),
));
Expand Down Expand Up @@ -264,7 +264,7 @@ fn test_bouncing(#[case] initial_bouncer_weights: BouncerWeights, #[case] n_even
tx_executor.bouncer.set_accumulated_weights(initial_bouncer_weights);

tx_executor
.execute(&Transaction::AccountTransaction(emit_n_events_tx(
.execute(&Transaction::Account(emit_n_events_tx(
n_events,
account_address,
contract_address,
Expand Down Expand Up @@ -301,7 +301,7 @@ fn test_execute_txs_bouncing() {
emit_n_events_tx(1, account_address, contract_address, nonce!(3_u32)),
]
.into_iter()
.map(Transaction::AccountTransaction)
.map(Transaction::Account)
.collect();

// Run.
Expand Down
18 changes: 8 additions & 10 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn test_commit_tx() {
trivial_calldata_invoke_tx(account_address, test_contract_address, nonce!(10_u8)),
]
.into_iter()
.map(Transaction::AccountTransaction)
.map(Transaction::Account)
.collect::<Vec<Transaction>>();
let mut bouncer = Bouncer::new(block_context.bouncer_config.clone());
let cached_state =
Expand Down Expand Up @@ -200,7 +200,7 @@ fn test_commit_tx_when_sender_is_sequencer() {
let (sequencer_balance_key_low, sequencer_balance_key_high) =
get_sequencer_balance_keys(&block_context);

let sequencer_tx = [Transaction::AccountTransaction(trivial_calldata_invoke_tx(
let sequencer_tx = [Transaction::Account(trivial_calldata_invoke_tx(
account_address,
test_contract_address,
nonce!(0_u8),
Expand Down Expand Up @@ -313,7 +313,7 @@ fn test_worker_execute(max_resource_bounds: ResourceBoundsMapping) {

let txs = [tx_success, tx_failure, tx_revert]
.into_iter()
.map(Transaction::AccountTransaction)
.map(Transaction::Account)
.collect::<Vec<Transaction>>();

let mut bouncer = Bouncer::new(block_context.bouncer_config.clone());
Expand Down Expand Up @@ -475,7 +475,7 @@ fn test_worker_validate(max_resource_bounds: ResourceBoundsMapping) {

let txs = [account_tx0, account_tx1]
.into_iter()
.map(Transaction::AccountTransaction)
.map(Transaction::Account)
.collect::<Vec<Transaction>>();

let mut bouncer = Bouncer::new(block_context.bouncer_config.clone());
Expand Down Expand Up @@ -586,10 +586,8 @@ fn test_deploy_before_declare(
nonce: nonce!(0_u8)
});

let txs = [declare_tx, invoke_tx]
.into_iter()
.map(Transaction::AccountTransaction)
.collect::<Vec<Transaction>>();
let txs =
[declare_tx, invoke_tx].into_iter().map(Transaction::Account).collect::<Vec<Transaction>>();

let mut bouncer = Bouncer::new(block_context.bouncer_config.clone());
let worker_executor =
Expand Down Expand Up @@ -654,7 +652,7 @@ fn test_worker_commit_phase(max_resource_bounds: ResourceBoundsMapping) {

let txs = (0..3)
.map(|_| {
Transaction::AccountTransaction(account_invoke_tx(invoke_tx_args! {
Transaction::Account(account_invoke_tx(invoke_tx_args! {
sender_address,
calldata: calldata.clone(),
resource_bounds: max_resource_bounds.clone(),
Expand Down Expand Up @@ -744,7 +742,7 @@ fn test_worker_commit_phase_with_halt() {

let txs = (0..2)
.map(|_| {
Transaction::AccountTransaction(emit_n_events_tx(
Transaction::Account(emit_n_events_tx(
n_events,
sender_address,
test_contract_address,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/transfers_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl TransfersGenerator {
self.sender_index = (self.sender_index + 1) % self.account_addresses.len();

let account_tx = self.generate_transfer(sender_address, recipient_address);
txs.push(Transaction::AccountTransaction(account_tx));
txs.push(Transaction::Account(account_tx));
}
let results = self.executor.execute_txs(&txs);
assert_eq!(results.len(), self.config.n_txs);
Expand Down
22 changes: 10 additions & 12 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use crate::transaction::transactions::{
// TODO: Move into transaction.rs, makes more sense to be defined there.
#[derive(Clone, Debug, derive_more::From)]
pub enum Transaction {
AccountTransaction(AccountTransaction),
L1HandlerTransaction(L1HandlerTransaction),
Account(AccountTransaction),
L1Handler(L1HandlerTransaction),
}

impl Transaction {
Expand All @@ -47,7 +47,7 @@ impl Transaction {
) -> TransactionExecutionResult<Self> {
match tx {
StarknetApiTransaction::L1Handler(l1_handler) => {
Ok(Self::L1HandlerTransaction(L1HandlerTransaction {
Ok(Self::L1Handler(L1HandlerTransaction {
tx: l1_handler,
tx_hash,
paid_fee_on_l1: paid_fee_on_l1
Expand All @@ -63,7 +63,7 @@ impl Transaction {
}
false => DeclareTransaction::new(declare, tx_hash, non_optional_class_info),
};
Ok(Self::AccountTransaction(AccountTransaction::Declare(declare_tx?)))
Ok(Self::Account(AccountTransaction::Declare(declare_tx?)))
}
StarknetApiTransaction::DeployAccount(deploy_account) => {
let contract_address = match deployed_contract_address {
Expand All @@ -85,14 +85,14 @@ impl Transaction {
DeployAccountTransaction::new(deploy_account, tx_hash, contract_address)
}
};
Ok(Self::AccountTransaction(AccountTransaction::DeployAccount(deploy_account_tx)))
Ok(Self::Account(AccountTransaction::DeployAccount(deploy_account_tx)))
}
StarknetApiTransaction::Invoke(invoke) => {
let invoke_tx = match only_query {
true => InvokeTransaction::new_for_query(invoke, tx_hash),
false => InvokeTransaction::new(invoke, tx_hash),
};
Ok(Self::AccountTransaction(AccountTransaction::Invoke(invoke_tx)))
Ok(Self::Account(AccountTransaction::Invoke(invoke_tx)))
}
_ => unimplemented!(),
}
Expand All @@ -102,8 +102,8 @@ impl Transaction {
impl TransactionInfoCreator for Transaction {
fn create_tx_info(&self) -> TransactionInfo {
match self {
Self::AccountTransaction(account_tx) => account_tx.create_tx_info(),
Self::L1HandlerTransaction(l1_handler_tx) => l1_handler_tx.create_tx_info(),
Self::Account(account_tx) => account_tx.create_tx_info(),
Self::L1Handler(l1_handler_tx) => l1_handler_tx.create_tx_info(),
}
}
}
Expand Down Expand Up @@ -171,12 +171,10 @@ impl<U: UpdatableState> ExecutableTransaction<U> for Transaction {
// AccountTransaction::execute_raw.
let concurrency_mode = execution_flags.concurrency_mode;
let tx_execution_info = match self {
Self::AccountTransaction(account_tx) => {
Self::Account(account_tx) => {
account_tx.execute_raw(state, block_context, execution_flags)?
}
Self::L1HandlerTransaction(tx) => {
tx.execute_raw(state, block_context, execution_flags)?
}
Self::L1Handler(tx) => tx.execute_raw(state, block_context, execution_flags)?,
};

// Check if the transaction is too large to fit any block.
Expand Down
2 changes: 1 addition & 1 deletion crates/native_blockifier/src/py_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn py_account_tx(
tx: &PyAny,
optional_py_class_info: Option<PyClassInfo>,
) -> NativeBlockifierResult<AccountTransaction> {
let Transaction::AccountTransaction(account_tx) = py_tx(tx, optional_py_class_info)? else {
let Transaction::Account(account_tx) = py_tx(tx, optional_py_class_info)? else {
panic!("Not an account transaction.");
};

Expand Down
Loading