Skip to content

Commit

Permalink
clean up no longer needed feature_set in test (solana-labs#34530)
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones authored Dec 19, 2023
1 parent 4a8582e commit c722976
Showing 1 changed file with 51 additions and 120 deletions.
171 changes: 51 additions & 120 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,6 @@ fn test_bank_tx_compute_unit_fee() {
.create_fee_calculator()
.lamports_per_signature,
&FeeStructure::default(),
false,
);

let (expected_fee_collected, expected_fee_burned) =
Expand Down Expand Up @@ -2830,7 +2829,6 @@ fn test_bank_blockhash_compute_unit_fee_structure() {
&SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap(),
cheap_lamports_per_signature,
&FeeStructure::default(),
false,
);
assert_eq!(
bank.get_balance(&mint_keypair.pubkey()),
Expand All @@ -2847,7 +2845,6 @@ fn test_bank_blockhash_compute_unit_fee_structure() {
&SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap(),
expensive_lamports_per_signature,
&FeeStructure::default(),
false,
);
assert_eq!(
bank.get_balance(&mint_keypair.pubkey()),
Expand Down Expand Up @@ -2959,7 +2956,6 @@ fn test_filter_program_errors_and_collect_compute_unit_fee() {
.create_fee_calculator()
.lamports_per_signature,
&FeeStructure::default(),
false,
) * 2
)
.0
Expand Down Expand Up @@ -9997,16 +9993,7 @@ fn calculate_test_fee(
message: &SanitizedMessage,
lamports_per_signature: u64,
fee_structure: &FeeStructure,
support_set_accounts_data_size_limit_ix: bool,
) -> u64 {
let mut feature_set = FeatureSet::all_enabled();

if !support_set_accounts_data_size_limit_ix {
feature_set.deactivate(
&solana_sdk::feature_set::include_loaded_accounts_data_size_in_fee_calculation::id(),
);
}

let budget_limits = process_compute_budget_instructions(message.program_instructions_iter())
.unwrap_or_default()
.into();
Expand All @@ -10019,57 +10006,48 @@ fn test_calculate_fee() {
// Default: no fee.
let message =
SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap();
for support_set_accounts_data_size_limit_ix in [true, false] {
assert_eq!(
calculate_test_fee(
&message,
0,
&FeeStructure {
lamports_per_signature: 0,
..FeeStructure::default()
},
support_set_accounts_data_size_limit_ix,
),
0
);
}
assert_eq!(
calculate_test_fee(
&message,
0,
&FeeStructure {
lamports_per_signature: 0,
..FeeStructure::default()
},
),
0
);

// One signature, a fee.
for support_set_accounts_data_size_limit_ix in [true, false] {
assert_eq!(
calculate_test_fee(
&message,
1,
&FeeStructure {
lamports_per_signature: 1,
..FeeStructure::default()
},
support_set_accounts_data_size_limit_ix,
),
1
);
}
assert_eq!(
calculate_test_fee(
&message,
1,
&FeeStructure {
lamports_per_signature: 1,
..FeeStructure::default()
},
),
1
);

// Two signatures, double the fee.
let key0 = Pubkey::new_unique();
let key1 = Pubkey::new_unique();
let ix0 = system_instruction::transfer(&key0, &key1, 1);
let ix1 = system_instruction::transfer(&key1, &key0, 1);
let message = SanitizedMessage::try_from(Message::new(&[ix0, ix1], Some(&key0))).unwrap();
for support_set_accounts_data_size_limit_ix in [true, false] {
assert_eq!(
calculate_test_fee(
&message,
2,
&FeeStructure {
lamports_per_signature: 2,
..FeeStructure::default()
},
support_set_accounts_data_size_limit_ix,
),
4
);
}
assert_eq!(
calculate_test_fee(
&message,
2,
&FeeStructure {
lamports_per_signature: 2,
..FeeStructure::default()
},
),
4
);
}

#[test]
Expand All @@ -10085,35 +10063,21 @@ fn test_calculate_fee_compute_units() {

let message =
SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap();
for support_set_accounts_data_size_limit_ix in [true, false] {
assert_eq!(
calculate_test_fee(
&message,
1,
&fee_structure,
support_set_accounts_data_size_limit_ix,
),
max_fee + lamports_per_signature
);
}
assert_eq!(
calculate_test_fee(&message, 1, &fee_structure,),
max_fee + lamports_per_signature
);

// Three signatures, two instructions, no unit request

let ix0 = system_instruction::transfer(&Pubkey::new_unique(), &Pubkey::new_unique(), 1);
let ix1 = system_instruction::transfer(&Pubkey::new_unique(), &Pubkey::new_unique(), 1);
let message =
SanitizedMessage::try_from(Message::new(&[ix0, ix1], Some(&Pubkey::new_unique()))).unwrap();
for support_set_accounts_data_size_limit_ix in [true, false] {
assert_eq!(
calculate_test_fee(
&message,
1,
&fee_structure,
support_set_accounts_data_size_limit_ix,
),
max_fee + 3 * lamports_per_signature
);
}
assert_eq!(
calculate_test_fee(&message, 1, &fee_structure,),
max_fee + 3 * lamports_per_signature
);

// Explicit fee schedule

Expand Down Expand Up @@ -10144,18 +10108,11 @@ fn test_calculate_fee_compute_units() {
Some(&Pubkey::new_unique()),
))
.unwrap();
for support_set_accounts_data_size_limit_ix in [true, false] {
let fee = calculate_test_fee(
&message,
1,
&fee_structure,
support_set_accounts_data_size_limit_ix,
);
assert_eq!(
fee,
lamports_per_signature + prioritization_fee_details.get_fee()
);
}
let fee = calculate_test_fee(&message, 1, &fee_structure);
assert_eq!(
fee,
lamports_per_signature + prioritization_fee_details.get_fee()
);
}
}

Expand Down Expand Up @@ -10187,7 +10144,6 @@ fn test_calculate_prioritization_fee() {
&message,
fee_structure.lamports_per_signature,
&fee_structure,
true,
);
assert_eq!(
fee,
Expand Down Expand Up @@ -10225,17 +10181,7 @@ fn test_calculate_fee_secp256k1() {
Some(&key0),
))
.unwrap();
for support_set_accounts_data_size_limit_ix in [true, false] {
assert_eq!(
calculate_test_fee(
&message,
1,
&fee_structure,
support_set_accounts_data_size_limit_ix,
),
2
);
}
assert_eq!(calculate_test_fee(&message, 1, &fee_structure,), 2);

secp_instruction1.data = vec![0];
secp_instruction2.data = vec![10];
Expand All @@ -10244,17 +10190,7 @@ fn test_calculate_fee_secp256k1() {
Some(&key0),
))
.unwrap();
for support_set_accounts_data_size_limit_ix in [true, false] {
assert_eq!(
calculate_test_fee(
&message,
1,
&fee_structure,
support_set_accounts_data_size_limit_ix,
),
11
);
}
assert_eq!(calculate_test_fee(&message, 1, &fee_structure,), 11);
}

#[test]
Expand Down Expand Up @@ -11996,19 +11932,14 @@ fn test_calculate_fee_with_congestion_multiplier() {
// assert when lamports_per_signature is less than BASE_LAMPORTS, turnning on/off
// congestion_multiplier has no effect on fee.
assert_eq!(
calculate_test_fee(&message, cheap_lamports_per_signature, &fee_structure, true,),
calculate_test_fee(&message, cheap_lamports_per_signature, &fee_structure),
signature_fee * signature_count
);

// assert when lamports_per_signature is more than BASE_LAMPORTS, turnning on/off
// congestion_multiplier will change calculated fee.
assert_eq!(
calculate_test_fee(
&message,
expensive_lamports_per_signature,
&fee_structure,
true,
),
calculate_test_fee(&message, expensive_lamports_per_signature, &fee_structure,),
signature_fee * signature_count
);
}
Expand Down Expand Up @@ -12039,7 +11970,7 @@ fn test_calculate_fee_with_request_heap_frame_flag() {
// assert when request_heap_frame is presented in tx, prioritization fee will be counted
// into transaction fee
assert_eq!(
calculate_test_fee(&message, lamports_per_signature, &fee_structure, true),
calculate_test_fee(&message, lamports_per_signature, &fee_structure),
signature_fee + request_cu * lamports_per_cu
);
}
Expand Down

0 comments on commit c722976

Please sign in to comment.