Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

derive TransactionCost::{PartialEq, Eq} #31626

Merged
merged 2 commits into from
May 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
writable_accounts only content matters
  • Loading branch information
apfitzge committed May 15, 2023
commit 8fdb16e4e6251a0f18650ae6d73630627d87ce4e
23 changes: 22 additions & 1 deletion runtime/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use {
const MAX_WRITABLE_ACCOUNTS: usize = 256;

// costs are stored in number of 'compute unit's
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct TransactionCost {
pub writable_accounts: Vec<Pubkey>,
pub signature_cost: u64,
Expand All @@ -55,6 +55,27 @@ impl Default for TransactionCost {
}
}

#[cfg(test)]
impl PartialEq for TransactionCost {
fn eq(&self, other: &Self) -> bool {
fn to_hash_set(v: &[Pubkey]) -> std::collections::HashSet<&Pubkey> {
v.iter().collect()
}

self.signature_cost == other.signature_cost
&& self.write_lock_cost == other.write_lock_cost
&& self.data_bytes_cost == other.data_bytes_cost
&& self.builtins_execution_cost == other.builtins_execution_cost
&& self.bpf_execution_cost == other.bpf_execution_cost
&& self.account_data_size == other.account_data_size
&& self.is_simple_vote == other.is_simple_vote
&& to_hash_set(&self.writable_accounts) == to_hash_set(&other.writable_accounts)
}
}

#[cfg(test)]
impl Eq for TransactionCost {}

impl TransactionCost {
pub fn new_with_capacity(capacity: usize) -> Self {
Self {
Expand Down