Skip to content

Commit ecc9ac9

Browse files
apollo_gateway: test account tx in mempool influence on validation
1 parent 14142cc commit ecc9ac9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

crates/apollo_gateway/src/stateful_transaction_validator_test.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use apollo_gateway_types::deprecated_gateway_error::{
44
StarknetError,
55
StarknetErrorCode,
66
};
7+
use apollo_mempool_types::communication::MempoolClientError;
8+
use apollo_mempool_types::errors::MempoolError;
79
use blockifier::blockifier::stateful_validator::{
810
MockStatefulValidatorTrait as MockBlockifierStatefulValidatorTrait,
911
StatefulValidatorError as BlockifierStatefulValidatorError,
@@ -426,3 +428,41 @@ async fn run_transaction_validation_test(
426428
.map_err(|err| err.code);
427429
assert_eq!(result, expected_result_code);
428430
}
431+
432+
#[rstest]
433+
#[case(Ok(true), false)] // account tx in mempool → skip validation
434+
#[case(Ok(false), true)] // account tx not in mempool → run validation
435+
#[case(Err(MempoolClientError::MempoolError(MempoolError::MempoolFull)), true)]
436+
#[tokio::test]
437+
async fn test_account_tx_in_mempool_influence_on_validation(
438+
#[case] is_account_tx_in_mempool: Result<bool, MempoolClientError>,
439+
#[case] expected_validate: bool,
440+
) {
441+
let sender_nonce = nonce!(0);
442+
let executable_tx = executable_invoke_tx(invoke_tx_args!(nonce: nonce!(1)));
443+
444+
let mut mock_blockifier_validator = MockBlockifierStatefulValidatorTrait::new();
445+
mock_blockifier_validator
446+
.expect_validate()
447+
.withf(move |tx| tx.execution_flags.validate == expected_validate)
448+
.returning(|_| Ok(()));
449+
450+
let mut stateful_validator = StatefulTransactionValidator {
451+
config: StatefulTransactionValidatorConfig {
452+
validate_resource_bounds: false,
453+
..Default::default()
454+
},
455+
blockifier_stateful_tx_validator: mock_blockifier_validator,
456+
};
457+
458+
// Blockifier mock asserts validate flag matches expectation.
459+
tokio::task::spawn_blocking(move || {
460+
let _ = stateful_validator.run_transaction_validations(
461+
&executable_tx,
462+
sender_nonce,
463+
is_account_tx_in_mempool,
464+
);
465+
})
466+
.await
467+
.unwrap();
468+
}

0 commit comments

Comments
 (0)