Skip to content

Commit

Permalink
test(starknet_api): chage default resource bounds to all (#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
TzahiTaub authored Nov 5, 2024
1 parent 135c179 commit 48bfb45
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Default for FaultyAccountTxCreatorArgs {
contract_address_salt: ContractAddressSalt::default(),
validate_constructor: false,
max_fee: Fee::default(),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
declared_contract: None,
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ fn test_validate_accounts_tx(
* the address of
* faulty_account. */
contract_address_salt: salt_manager.next_salt(),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
});
let error = account_tx.execute(state, block_context, charge_fee, true).unwrap_err();
Expand All @@ -1967,7 +1967,7 @@ fn test_validate_accounts_tx(
scenario: GET_BLOCK_HASH,
contract_address_salt: salt_manager.next_salt(),
additional_data: None,
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
});
let error = account_tx.execute(state, block_context, charge_fee, true).unwrap_err();
Expand All @@ -1982,7 +1982,7 @@ fn test_validate_accounts_tx(
let account_tx = create_account_tx_for_validate_test_nonce_0(FaultyAccountTxCreatorArgs {
scenario: GET_SEQUENCER_ADDRESS,
contract_address_salt: salt_manager.next_salt(),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
});
let error = account_tx.execute(state, block_context, charge_fee, true).unwrap_err();
Expand All @@ -2005,7 +2005,7 @@ fn test_validate_accounts_tx(
contract_address_salt: salt_manager.next_salt(),
additional_data: None,
declared_contract: Some(FeatureContract::TestContract(declared_contract_cairo_version)),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
},
);
Expand All @@ -2022,7 +2022,7 @@ fn test_validate_accounts_tx(
declared_contract: Some(FeatureContract::AccountWithLongValidate(
declared_contract_cairo_version,
)),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
},
);
Expand All @@ -2042,7 +2042,7 @@ fn test_validate_accounts_tx(
declared_contract: Some(FeatureContract::AccountWithoutValidations(
declared_contract_cairo_version,
)),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
},
);
Expand All @@ -2058,7 +2058,7 @@ fn test_validate_accounts_tx(
contract_address_salt: salt_manager.next_salt(),
additional_data: Some(vec![Felt::from(CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE)]),
declared_contract: Some(FeatureContract::Empty(declared_contract_cairo_version)),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
},
);
Expand All @@ -2080,7 +2080,7 @@ fn test_validate_accounts_tx(
Felt::ZERO, // Sequencer address for validate.
]),
declared_contract: Some(FeatureContract::Empty(declared_contract_cairo_version)),
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
..default_args
},
);
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_api/src/test_utils/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Default for DeclareTxArgs {
signature: TransactionSignature::default(),
sender_address: ContractAddress::default(),
version: TransactionVersion::THREE,
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
tip: Tip::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_api/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Default for DeployAccountTxArgs {
signature: TransactionSignature::default(),
deployer_address: ContractAddress::default(),
version: TransactionVersion::THREE,
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
tip: Tip::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_api/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Default for InvokeTxArgs {
sender_address: ContractAddress::default(),
calldata: calldata![],
version: TransactionVersion::THREE,
resource_bounds: ValidResourceBounds::create_for_testing(),
resource_bounds: ValidResourceBounds::create_for_testing_no_fee_enforcement(),
tip: Tip::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
Expand Down
15 changes: 12 additions & 3 deletions crates/starknet_api/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,19 @@ impl ValidResourceBounds {
}
}

// TODO(Nimrod): Default testing bounds should probably be AllResourceBounds variant.
#[cfg(any(feature = "testing", test))]
pub fn create_for_testing() -> Self {
Self::L1Gas(ResourceBounds { max_amount: GasAmount(0), max_price_per_unit: GasPrice(1) })
pub fn create_for_testing_no_fee_enforcement() -> Self {
let default_l2_gas_amount = GasAmount(10000000000); // Sufficient to avoid out of gas errors.
let default_resource =
ResourceBounds { max_amount: GasAmount(0), max_price_per_unit: GasPrice(1) };
Self::AllResources(AllResourceBounds {
l1_gas: default_resource,
l2_gas: ResourceBounds {
max_amount: default_l2_gas_amount,
max_price_per_unit: GasPrice(0), // Set to zero for no enforce_fee mechanism.
},
l1_data_gas: default_resource,
})
}

/// Utility method to "zip" an amount vector and a price vector to get an AllResourceBounds.
Expand Down

0 comments on commit 48bfb45

Please sign in to comment.