Skip to content

Commit 3da6da4

Browse files
apollo_gateway: test flag allow_client_side_proving (#11404)
1 parent 7fec49d commit 3da6da4

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

crates/apollo_gateway/src/stateless_transaction_validator_test.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ static DEFAULT_VALIDATOR_CONFIG_FOR_TESTING: LazyLock<StatelessTransactionValida
139139
DEFAULT_VALIDATOR_CONFIG_FOR_TESTING.clone(),
140140
RpcTransactionArgs { proof_facts: ProofFacts::snos_proof_facts_for_testing(), proof: Proof::proof_for_testing(), ..Default::default()}
141141
)]
142-
// TODO(AvivG): Add case for client-side proving disabled.
142+
#[case::client_side_proving_disabled(
143+
StatelessTransactionValidatorConfig {
144+
allow_client_side_proving: false,
145+
..*DEFAULT_VALIDATOR_CONFIG_FOR_TESTING
146+
},
147+
RpcTransactionArgs::default()
148+
)]
143149
#[case::valid_tx(DEFAULT_VALIDATOR_CONFIG_FOR_TESTING.clone(), RpcTransactionArgs::default())]
144150
fn test_positive_flow(
145151
#[case] config: StatelessTransactionValidatorConfig,
@@ -334,7 +340,6 @@ fn test_invalid_max_l2_gas_amount(
334340
}),
335341
vec![TransactionType::Declare, TransactionType::Invoke],
336342
)]
337-
// TODO(AvivG): Add test for invalid proof fields.
338343
fn test_invalid_tx(
339344
#[case] rpc_tx_args: RpcTransactionArgs,
340345
#[case] expected_error: StatelessTransactionValidatorError,
@@ -587,4 +592,50 @@ fn test_declare_entry_points_not_sorted_by_selector(
587592
assert_eq!(tx_validator.validate(&tx), expected);
588593
}
589594

590-
// TODO(AvivG): Test allow_client_side_proving config.
595+
#[rstest]
596+
#[case::no_proof_data_allowed_when_disabled(false, None, None)]
597+
#[case::proof_facts_only(false, Some(ProofFacts::snos_proof_facts_for_testing()), None)]
598+
#[case::proof_only(false, None, Some(Proof::proof_for_testing()))]
599+
#[case::both_proof_and_facts(
600+
false,
601+
Some(ProofFacts::snos_proof_facts_for_testing()),
602+
Some(Proof::proof_for_testing())
603+
)]
604+
#[case::enabled_accepts_both(
605+
true,
606+
Some(ProofFacts::snos_proof_facts_for_testing()),
607+
Some(Proof::proof_for_testing())
608+
)]
609+
fn test_client_side_proving_flag(
610+
#[case] allow_client_side_proving: bool,
611+
#[case] proof_facts: Option<ProofFacts>,
612+
#[case] proof: Option<Proof>,
613+
) {
614+
let config = StatelessTransactionValidatorConfig {
615+
allow_client_side_proving,
616+
..*DEFAULT_VALIDATOR_CONFIG_FOR_TESTING
617+
};
618+
let tx_validator = StatelessTransactionValidator { config };
619+
620+
// Check for proof data before moving values.
621+
let has_proof_data = proof_facts.is_some() || proof.is_some();
622+
623+
let rpc_tx_args = RpcTransactionArgs {
624+
proof_facts: proof_facts.unwrap_or_default(),
625+
proof: proof.unwrap_or_default(),
626+
..Default::default()
627+
};
628+
629+
let tx = rpc_tx_for_testing(TransactionType::Invoke, rpc_tx_args);
630+
631+
// Disabled ⇒ reject txs with proof data.
632+
// Enabled ⇒ always accept.
633+
if !allow_client_side_proving && has_proof_data {
634+
assert_eq!(
635+
tx_validator.validate(&tx).unwrap_err(),
636+
StatelessTransactionValidatorError::ClientSideProvingNotAllowed
637+
);
638+
} else {
639+
assert_matches!(tx_validator.validate(&tx), Ok(()));
640+
}
641+
}

0 commit comments

Comments
 (0)