Skip to content

Commit

Permalink
add some simple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Nov 17, 2022
1 parent ea7ed8b commit 71ecfc6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions core/src/read_write_account_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,48 @@ impl ReadWriteAccountSet {
self.write_set.clear();
}
}

#[cfg(test)]
mod tests {
use {super::ReadWriteAccountSet, solana_sdk::pubkey::Pubkey};

#[test]
pub fn test_write_write_conflict() {
let mut account_locks = ReadWriteAccountSet::default();
let account = Pubkey::new_unique();
assert!(account_locks.can_write(&account));
account_locks.add_write(&account);
assert!(!account_locks.can_write(&account));
}

#[test]
pub fn test_read_write_conflict() {
let mut account_locks = ReadWriteAccountSet::default();
let account = Pubkey::new_unique();
assert!(account_locks.can_read(&account));
account_locks.add_read(&account);
assert!(!account_locks.can_write(&account));
assert!(account_locks.can_read(&account));
}

#[test]
pub fn test_write_read_conflict() {
let mut account_locks = ReadWriteAccountSet::default();
let account = Pubkey::new_unique();
assert!(account_locks.can_write(&account));
account_locks.add_write(&account);
assert!(!account_locks.can_write(&account));
assert!(!account_locks.can_read(&account));
}

#[test]
pub fn test_write_write_non_conflict() {
let mut account_locks = ReadWriteAccountSet::default();
let account1 = Pubkey::new_unique();
let account2 = Pubkey::new_unique();
assert!(account_locks.can_write(&account1));
account_locks.add_write(&account1);
assert!(account_locks.can_write(&account2));
assert!(account_locks.can_read(&account2));
}
}

0 comments on commit 71ecfc6

Please sign in to comment.