Skip to content

Commit

Permalink
test(mempool): enable l2 gas resource for mempool-test
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Aug 20, 2024
1 parent 053ae9a commit 2e76774
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
10 changes: 8 additions & 2 deletions crates/gateway/src/gateway_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mempool_test_utils::starknet_api_test_utils::{create_executable_tx, invoke_t
use mockall::predicate::eq;
use starknet_api::core::ContractAddress;
use starknet_api::rpc_transaction::RpcTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_api::transaction::{ResourceBoundsMapping, TransactionHash};
use starknet_mempool_types::communication::MockMempoolClient;
use starknet_mempool_types::mempool_types::{Account, AccountState, MempoolInput};
use starknet_sierra_compile::config::SierraToCasmCompilationConfig;
Expand Down 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(),
ResourceBoundsMapping::default(),
),
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,
executable_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: executable_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
8 changes: 6 additions & 2 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ pub fn executable_resource_bounds_mapping() -> ResourceBoundsMapping {
max_amount: VALID_L1_GAS_MAX_AMOUNT,
max_price_per_unit: VALID_L1_GAS_MAX_PRICE_PER_UNIT,
},
ResourceBounds::default(),
ResourceBounds {
max_amount: VALID_L1_GAS_MAX_AMOUNT,
max_price_per_unit: VALID_L1_GAS_MAX_PRICE_PER_UNIT,
},
)
}

Expand Down Expand Up @@ -547,14 +550,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

0 comments on commit 2e76774

Please sign in to comment.