Skip to content

Commit

Permalink
test: make the stateless tx validator a more correct unit test (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Jun 13, 2024
1 parent 50d38f0 commit bdfa197
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions crates/gateway/src/stateless_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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(),
);
Expand All @@ -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)]),
);
Expand Down

0 comments on commit bdfa197

Please sign in to comment.