Skip to content

Commit 3241c60

Browse files
committed
Fix tests in transaction.rs
1 parent 04fc58d commit 3241c60

1 file changed

Lines changed: 89 additions & 23 deletions

File tree

transaction-context/src/transaction.rs

Lines changed: 89 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,40 +1843,82 @@ mod tests {
18431843
let dedup_map = TransactionContext::deduplicate_accounts(&mut instruction_accounts);
18441844

18451845
// Check that the dedup_map correctly maps duplicate accounts
1846-
assert_eq!(*dedup_map.first().unwrap(), 0); // First account 0 at index 0
1847-
assert_eq!(*dedup_map.get(1).unwrap(), 1); // First account 1 at index 1
1848-
assert_eq!(*dedup_map.get(2).unwrap(), 3); // Account 2 at index 3
1846+
assert_eq!(
1847+
*dedup_map.first().unwrap(),
1848+
0,
1849+
"account must be a duplicate of itself"
1850+
);
1851+
assert_eq!(
1852+
*dedup_map.get(1).unwrap(),
1853+
1,
1854+
"account must be a duplicate of itself"
1855+
);
1856+
assert_eq!(
1857+
*dedup_map.get(2).unwrap(),
1858+
3,
1859+
"account must be a duplicate of itself"
1860+
);
18491861

18501862
// Check that duplicate accounts are properly merged
18511863
let acc = instruction_accounts.first().unwrap();
18521864
assert_eq!(acc.index_in_transaction, 0);
1853-
assert!(!acc.is_signer()); // Not a signer because account 1 is not signer
1854-
assert!(acc.is_writable()); // Writable because account 0 is writable
1865+
assert!(
1866+
!acc.is_signer(),
1867+
"Must not be a signer because account 1 is not signer"
1868+
);
1869+
assert!(
1870+
acc.is_writable(),
1871+
"Must be writable because account 0 is writable"
1872+
);
18551873

18561874
let acc = instruction_accounts.get(1).unwrap();
18571875
assert_eq!(acc.index_in_transaction, 1);
1858-
assert!(acc.is_signer()); // Signer because account 1 is signer
1859-
assert!(!acc.is_writable()); // Not writable because account 1 is not writable
1876+
assert!(
1877+
acc.is_signer(),
1878+
"Must be signer because account 1 is signer"
1879+
);
1880+
assert!(
1881+
!acc.is_writable(),
1882+
"Must not be writable because account 1 is not writable"
1883+
);
18601884

18611885
let acc = instruction_accounts.get(2).unwrap();
18621886
assert_eq!(acc.index_in_transaction, 0);
1863-
assert!(!acc.is_signer()); // Should be merged from account 1
1864-
assert!(acc.is_writable()); // Should be merged from account 0
1887+
assert!(!acc.is_signer(), "Should be merged from account 1");
1888+
assert!(acc.is_writable(), "Should be merged from account 0");
18651889

18661890
let acc = instruction_accounts.get(3).unwrap();
18671891
assert_eq!(acc.index_in_transaction, 2);
1868-
assert!(!acc.is_signer()); // Not a signer
1869-
assert!(acc.is_writable()); // Writable
1892+
assert!(!acc.is_signer());
1893+
assert!(acc.is_writable());
18701894

18711895
let acc = instruction_accounts.get(4).unwrap();
18721896
assert_eq!(acc.index_in_transaction, 1);
1873-
assert!(acc.is_signer()); // Signer because account 1 is signer
1874-
assert!(!acc.is_writable()); // Not writable because account 1 is not writable
1897+
assert!(
1898+
acc.is_signer(),
1899+
"Must be signer because account 1 is signer"
1900+
);
1901+
assert!(
1902+
!acc.is_writable(),
1903+
"Must not be writable because account 1 is not writable"
1904+
);
18751905

18761906
// Verify that the deduplication map correctly identifies duplicates
1877-
assert_eq!(*dedup_map.first().unwrap(), 0); // First occurrence of account 0 at index 0
1878-
assert_eq!(*dedup_map.get(1).unwrap(), 1); // First occurrence of account 1 at index 1
1879-
assert_eq!(*dedup_map.get(2).unwrap(), 3); // First occurrence of account 2 at index 3
1907+
assert_eq!(
1908+
*dedup_map.first().unwrap(),
1909+
0,
1910+
"account must be a duplicate of itself"
1911+
);
1912+
assert_eq!(
1913+
*dedup_map.get(1).unwrap(),
1914+
1,
1915+
"account must be a duplicate of itself"
1916+
);
1917+
assert_eq!(
1918+
*dedup_map.get(2).unwrap(),
1919+
3,
1920+
"account must be a duplicate of itself"
1921+
);
18801922
}
18811923

18821924
#[test]
@@ -1890,9 +1932,21 @@ mod tests {
18901932
let dedup_map = TransactionContext::deduplicate_accounts(&mut instruction_accounts);
18911933

18921934
// Check that the dedup_map correctly maps each account to itself
1893-
assert_eq!(*dedup_map.first().unwrap(), 0); // Account 0 at index 0
1894-
assert_eq!(*dedup_map.get(1).unwrap(), 1); // Account 1 at index 1
1895-
assert_eq!(*dedup_map.get(2).unwrap(), 2); // Account 2 at index 2
1935+
assert_eq!(
1936+
*dedup_map.first().unwrap(),
1937+
0,
1938+
"account must be a duplicate of itself"
1939+
);
1940+
assert_eq!(
1941+
*dedup_map.get(1).unwrap(),
1942+
1,
1943+
"account must be a duplicate of itself"
1944+
);
1945+
assert_eq!(
1946+
*dedup_map.get(2).unwrap(),
1947+
2,
1948+
"account must be a duplicate of itself"
1949+
);
18961950

18971951
// Check that accounts are not modified
18981952
let acc = instruction_accounts.first().unwrap();
@@ -1922,14 +1976,26 @@ mod tests {
19221976
let dedup_map = TransactionContext::deduplicate_accounts(&mut instruction_accounts);
19231977

19241978
// Check that all accounts map to the first occurrence (index 0)
1925-
assert_eq!(*dedup_map.first().unwrap(), 0); // Account 0 at index 0
1926-
assert_eq!(*dedup_map.get(1).unwrap(), u16::MAX);
1979+
assert_eq!(
1980+
*dedup_map.first().unwrap(),
1981+
0,
1982+
"account must be a duplicate of itself"
1983+
);
1984+
for idx in dedup_map.iter().skip(1) {
1985+
assert_eq!(*idx, u16::MAX);
1986+
}
19271987

19281988
// Check that the first account has combined flags
19291989
let acc = instruction_accounts.first().unwrap();
19301990
assert_eq!(acc.index_in_transaction, 0);
1931-
assert!(acc.is_signer()); // Should be signer because of second account
1932-
assert!(acc.is_writable()); // Should be writable because of first account
1991+
assert!(
1992+
acc.is_signer(),
1993+
"Should be signer because of second account"
1994+
);
1995+
assert!(
1996+
acc.is_writable(),
1997+
"Should be writable because of first account"
1998+
);
19331999

19342000
// Check that the other accounts have the same flags as the first
19352001
let acc = instruction_accounts.get(1).unwrap();

0 commit comments

Comments
 (0)