Skip to content

Commit 9fa4f2f

Browse files
apollo_gateway: test account tx in mempool influence on validation
1 parent d2d5f77 commit 9fa4f2f

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,
@@ -434,3 +436,41 @@ async fn test_reject_future_declares(
434436
.map_err(|err| err.code);
435437
assert_eq!(result, expected_result_code);
436438
}
439+
440+
#[rstest]
441+
#[case(Ok(true), false)] // account tx in mempool → skip validation
442+
#[case(Ok(false), true)] // account tx not in mempool → run validation
443+
#[case(Err(MempoolClientError::MempoolError(MempoolError::MempoolFull)), true)]
444+
#[tokio::test]
445+
async fn test_account_tx_in_mempool_influence_on_validation(
446+
#[case] is_account_tx_in_mempool: Result<bool, MempoolClientError>,
447+
#[case] expected_validate: bool,
448+
) {
449+
let sender_nonce = nonce!(0);
450+
let executable_tx = executable_invoke_tx(invoke_tx_args!(nonce: nonce!(1)));
451+
452+
let mut mock_blockifier_validator = MockBlockifierStatefulValidatorTrait::new();
453+
mock_blockifier_validator
454+
.expect_validate()
455+
.withf(move |tx| tx.execution_flags.validate == expected_validate)
456+
.returning(|_| Ok(()));
457+
458+
let mut stateful_validator = StatefulTransactionValidator {
459+
config: StatefulTransactionValidatorConfig {
460+
validate_resource_bounds: false,
461+
..Default::default()
462+
},
463+
blockifier_stateful_tx_validator: mock_blockifier_validator,
464+
};
465+
466+
// Blockifier mock asserts validate flag matches expectation.
467+
tokio::task::spawn_blocking(move || {
468+
let _ = stateful_validator.run_transaction_validations(
469+
&executable_tx,
470+
sender_nonce,
471+
is_account_tx_in_mempool,
472+
);
473+
})
474+
.await
475+
.unwrap();
476+
}

0 commit comments

Comments
 (0)