From bdfa19774d5008f5557907d102a16f9d28a92767 Mon Sep 17 00:00:00 2001 From: Arnon Hod Date: Thu, 13 Jun 2024 11:22:50 +0300 Subject: [PATCH] test: make the stateless tx validator a more correct unit test (#232) --- .../stateless_transaction_validator_test.rs | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/crates/gateway/src/stateless_transaction_validator_test.rs b/crates/gateway/src/stateless_transaction_validator_test.rs index 71ef72c53..8b650eafc 100644 --- a/crates/gateway/src/stateless_transaction_validator_test.rs +++ b/crates/gateway/src/stateless_transaction_validator_test.rs @@ -16,8 +16,8 @@ use crate::stateless_transaction_validator::{ const DEFAULT_VALIDATOR_CONFIG_FOR_TESTING: StatelessTransactionValidatorConfig = StatelessTransactionValidatorConfig { - validate_non_zero_l1_gas_fee: true, - validate_non_zero_l2_gas_fee: true, + validate_non_zero_l1_gas_fee: false, + validate_non_zero_l2_gas_fee: false, max_calldata_length: 1, max_signature_length: 1, @@ -46,18 +46,22 @@ const DEFAULT_VALIDATOR_CONFIG_FOR_TESTING: StatelessTransactionValidatorConfig )] #[case::non_empty_valid_calldata( DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, - non_zero_resource_bounds_mapping(), + zero_resource_bounds_mapping(), calldata![StarkFelt::from_u128(1)], TransactionSignature::default() )] #[case::non_empty_valid_signature( DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, - non_zero_resource_bounds_mapping(), + zero_resource_bounds_mapping(), calldata![], TransactionSignature(vec![StarkFelt::from_u128(1)]) )] #[case::valid_tx( - DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, + StatelessTransactionValidatorConfig{ + validate_non_zero_l1_gas_fee: true, + validate_non_zero_l2_gas_fee: true, + ..DEFAULT_VALIDATOR_CONFIG_FOR_TESTING + }, non_zero_resource_bounds_mapping(), calldata![], TransactionSignature::default() @@ -78,14 +82,22 @@ fn test_positive_flow( #[rstest] #[case::zero_l1_gas_resource_bounds( - DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, + StatelessTransactionValidatorConfig{ + validate_non_zero_l1_gas_fee: true, + validate_non_zero_l2_gas_fee: false, + ..DEFAULT_VALIDATOR_CONFIG_FOR_TESTING + }, zero_resource_bounds_mapping(), StatelessTransactionValidatorError::ZeroResourceBounds{ resource: Resource::L1Gas, resource_bounds: ResourceBounds::default() } )] #[case::zero_l2_gas_resource_bounds( - DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, + StatelessTransactionValidatorConfig{ + validate_non_zero_l1_gas_fee: false, + validate_non_zero_l2_gas_fee: true, + ..DEFAULT_VALIDATOR_CONFIG_FOR_TESTING + }, create_resource_bounds_mapping(NON_EMPTY_RESOURCE_BOUNDS, ResourceBounds::default()), StatelessTransactionValidatorError::ZeroResourceBounds{ resource: Resource::L2Gas, resource_bounds: ResourceBounds::default() @@ -117,7 +129,7 @@ fn test_calldata_too_long( StatelessTransactionValidator { config: DEFAULT_VALIDATOR_CONFIG_FOR_TESTING }; let tx = external_tx_for_testing( tx_type, - non_zero_resource_bounds_mapping(), + zero_resource_bounds_mapping(), calldata![StarkFelt::from_u128(1), StarkFelt::from_u128(2)], TransactionSignature::default(), ); @@ -140,7 +152,7 @@ fn test_signature_too_long( StatelessTransactionValidator { config: DEFAULT_VALIDATOR_CONFIG_FOR_TESTING }; let tx = external_tx_for_testing( tx_type, - non_zero_resource_bounds_mapping(), + zero_resource_bounds_mapping(), calldata![], TransactionSignature(vec![StarkFelt::from_u128(1), StarkFelt::from_u128(2)]), );