Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed May 16, 2024
1 parent 9cc2377 commit f41a7b0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ mod tests {
// default loaded_accounts_data_size_limit
const DEFAULT_PAGE_COST: u64 = 8;
let expected_loaded_accounts_data_size_cost =
solana_program_runtime::compute_budget_processor::MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES
solana_program_runtime::compute_budget_processor::DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_BYTES
as u64
/ ACCOUNT_DATA_COST_PAGE_SIZE
* DEFAULT_PAGE_COST;
Expand Down
15 changes: 11 additions & 4 deletions cost-model/src/transaction_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ mod tests {
crate::cost_model::CostModel,
solana_sdk::{
feature_set::FeatureSet,
fee::ACCOUNT_DATA_COST_PAGE_SIZE,
hash::Hash,
message::SimpleAddressLoader,
reserved_account_keys::ReservedAccountKeys,
Expand Down Expand Up @@ -246,16 +247,22 @@ mod tests {
)
.unwrap();

// expected vote tx cost: 2 write locks, 1 sig, 1 vote ix, 8cu of loaded accounts size,
// expected vote tx cost: 2 write locks, 1 sig, 1 vote ix, 8cu of ix data bytes,
let expected_vote_cost = SIMPLE_VOTE_USAGE_COST;
// expected non-vote tx cost would include default loaded accounts size cost (16384) additionally
let expected_none_vote_cost = 20535;
// expected non-vote tx cost would include default loaded accounts size cost additionally
const DEFAULT_PAGE_COST: u64 = 8;
let expected_loaded_accounts_data_size_cost =
solana_program_runtime::compute_budget_processor::DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_BYTES
as u64
/ ACCOUNT_DATA_COST_PAGE_SIZE
* DEFAULT_PAGE_COST;
let min_none_vote_cost = SIMPLE_VOTE_USAGE_COST + expected_loaded_accounts_data_size_cost;

let vote_cost = CostModel::calculate_cost(&vote_transaction, &FeatureSet::all_enabled());
let none_vote_cost =
CostModel::calculate_cost(&none_vote_transaction, &FeatureSet::all_enabled());

assert_eq!(expected_vote_cost, vote_cost.sum());
assert_eq!(expected_none_vote_cost, none_vote_cost.sum());
assert!(min_none_vote_cost < none_vote_cost.sum());
}
}
2 changes: 1 addition & 1 deletion program-runtime/src/compute_budget_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ mod tests {
// budget is set to default data size
let expected_result = Ok(ComputeBudgetLimits {
compute_unit_limit: DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT,
loaded_accounts_bytes: MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
loaded_accounts_bytes: DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_BYTES,
..ComputeBudgetLimits::default()
});

Expand Down
2 changes: 1 addition & 1 deletion svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ mod tests {

let result_default_limit = Ok(Some(
NonZeroUsize::new(
usize::try_from(compute_budget_processor::MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES)
usize::try_from(compute_budget_processor::DEFAULT_LOADED_ACCOUNTS_DATA_SIZE_BYTES)
.unwrap(),
)
.unwrap(),
Expand Down

0 comments on commit f41a7b0

Please sign in to comment.