From 71ecfc6e945f62e6000fdeb492acd5fd6e09e411 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 17 Nov 2022 15:16:26 -0600 Subject: [PATCH] add some simple tests --- core/src/read_write_account_set.rs | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/core/src/read_write_account_set.rs b/core/src/read_write_account_set.rs index 9126939b9369e0..ddfa319c2d7bc7 100644 --- a/core/src/read_write_account_set.rs +++ b/core/src/read_write_account_set.rs @@ -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)); + } +}