Skip to content

Commit

Permalink
test(mempool): enable l2 gas resource for mempool-test (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 authored Aug 21, 2024
1 parent ac0ea24 commit e57df3a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
8 changes: 7 additions & 1 deletion crates/gateway/src/gateway_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ async fn test_add_tx() {
.with(eq(MempoolInput {
// TODO(Arni): Use external_to_executable_tx instead of `create_executable_tx`. Consider
// creating a `convertor for testing` that does not do the compilation.
tx: create_executable_tx(sender_address, tx_hash, *tx.tip(), *tx.nonce()),
tx: create_executable_tx(
sender_address,
tx_hash,
*tx.tip(),
*tx.nonce(),
tx.resource_bounds().clone().into(),
),
account: Account { sender_address, state: AccountState { nonce: *tx.nonce() } },
}))
.return_once(|_| Ok(()));
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/stateful_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn stateful_validator(block_context: BlockContext) -> StatefulTransactionValidat
invoke_tx(CairoVersion::Cairo1),
Ok(ValidateInfo{
tx_hash: TransactionHash(felt!(
"0x152b8dd0c30e95fa3a4ee7a9398fcfc46fb00c048b4fdcfa9958c64d65899b8"
"0x3b93426272b6e281bc9bde29b91a9fb100c2f9689388c62360b2be2f4e7b493"
)),
sender_address: contract_address!("0xc0020000"),
account_nonce: Nonce::default()
Expand Down
12 changes: 10 additions & 2 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::cmp::Reverse;
use std::collections::HashMap;

use assert_matches::assert_matches;
use mempool_test_utils::starknet_api_test_utils::create_executable_tx;
use mempool_test_utils::starknet_api_test_utils::{
create_executable_tx,
test_resource_bounds_mapping,
};
use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use starknet_api::core::{ContractAddress, Nonce, PatriciaKey};
Expand Down Expand Up @@ -151,7 +154,7 @@ fn add_tx_expect_error(mempool: &mut Mempool, input: &MempoolInput, expected_err
/// 5. add_tx_input!(tip: 1, tx_hash: 2)
macro_rules! add_tx_input {
(tip: $tip:expr, tx_hash: $tx_hash:expr, sender_address: $sender_address:expr,
tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr) => {{
tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr, resource_bounds: $resource_bounds:expr) => {{
let sender_address = contract_address!($sender_address);
let account_nonce = Nonce(felt!($account_nonce));
let account = Account { sender_address, state: AccountState {nonce: account_nonce}};
Expand All @@ -161,9 +164,14 @@ macro_rules! add_tx_input {
TransactionHash(StarkHash::from($tx_hash)),
Tip($tip),
Nonce(felt!($tx_nonce)),
$resource_bounds,
);
MempoolInput { tx, account }
}};
(tip: $tip:expr, tx_hash: $tx_hash:expr, sender_address: $sender_address:expr,
tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr) => {{
add_tx_input!(tip: $tip, tx_hash: $tx_hash, sender_address: $sender_address, tx_nonce: $tx_nonce, account_nonce: $account_nonce, resource_bounds: test_resource_bounds_mapping().into())
}};
(tx_hash: $tx_hash:expr, sender_address: $sender_address:expr, tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr) => {
add_tx_input!(tip: 0, tx_hash: $tx_hash, sender_address: $sender_address, tx_nonce: $tx_nonce, account_nonce: $account_nonce)
};
Expand Down
18 changes: 12 additions & 6 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ use crate::{

pub const VALID_L1_GAS_MAX_AMOUNT: u64 = 203484;
pub const VALID_L1_GAS_MAX_PRICE_PER_UNIT: u128 = 100000000000;
pub const VALID_L2_GAS_MAX_AMOUNT: u64 = 203484;
pub const VALID_L2_GAS_MAX_PRICE_PER_UNIT: u128 = 100000000000;
pub const TEST_SENDER_ADDRESS: u128 = 0x1000;

// Utils.
Expand Down Expand Up @@ -104,13 +106,16 @@ pub fn zero_resource_bounds_mapping() -> ResourceBoundsMapping {
create_resource_bounds_mapping(ResourceBounds::default(), ResourceBounds::default())
}

pub fn executable_resource_bounds_mapping() -> ResourceBoundsMapping {
pub fn test_resource_bounds_mapping() -> ResourceBoundsMapping {
create_resource_bounds_mapping(
ResourceBounds {
max_amount: VALID_L1_GAS_MAX_AMOUNT,
max_price_per_unit: VALID_L1_GAS_MAX_PRICE_PER_UNIT,
},
ResourceBounds::default(),
ResourceBounds {
max_amount: VALID_L2_GAS_MAX_AMOUNT,
max_price_per_unit: VALID_L2_GAS_MAX_PRICE_PER_UNIT,
},
)
}

Expand Down Expand Up @@ -138,7 +143,7 @@ pub fn declare_tx() -> RpcTransaction {
external_declare_tx(declare_tx_args!(
signature: TransactionSignature(vec![Felt::ZERO]),
sender_address: account_address,
resource_bounds: executable_resource_bounds_mapping(),
resource_bounds: test_resource_bounds_mapping(),
nonce,
class_hash: compiled_class_hash,
contract_class,
Expand Down Expand Up @@ -256,7 +261,7 @@ impl AccountTransactionGenerator {
pub fn generate_default_invoke(&mut self) -> RpcTransaction {
let invoke_args = invoke_tx_args!(
sender_address: self.sender_address(),
resource_bounds: executable_resource_bounds_mapping(),
resource_bounds: test_resource_bounds_mapping(),
nonce: self.next_nonce(),
calldata: create_trivial_calldata(self.test_contract_address()),
);
Expand All @@ -270,7 +275,7 @@ impl AccountTransactionGenerator {
let deploy_account_args = deploy_account_tx_args!(
nonce,
class_hash: self.account.get_class_hash(),
resource_bounds: executable_resource_bounds_mapping()
resource_bounds: test_resource_bounds_mapping()
);
external_deploy_account_tx(deploy_account_args)
}
Expand Down Expand Up @@ -547,14 +552,15 @@ pub fn create_executable_tx(
tx_hash: TransactionHash,
tip: Tip,
nonce: Nonce,
resource_bounds: ExecutableResourceBoundsMapping,
) -> Transaction {
Transaction::Invoke(InvokeTransaction {
tx: starknet_api::transaction::InvokeTransaction::V3(
starknet_api::transaction::InvokeTransactionV3 {
sender_address,
tip,
nonce,
resource_bounds: ExecutableResourceBoundsMapping::default(),
resource_bounds,
signature: TransactionSignature::default(),
calldata: Calldata::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Transaction {
sender_address,
tip: *rpc_tx.tip(),
nonce: *rpc_tx.nonce(),
resource_bounds: ResourceBoundsMapping::default(),
resource_bounds: rpc_tx.resource_bounds().clone().into(),
signature: TransactionSignature::default(),
calldata: Calldata::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
Expand Down

0 comments on commit e57df3a

Please sign in to comment.