Skip to content

Commit 4aa38b4

Browse files
committed
Improve duplicated account assert
1 parent dffde26 commit 4aa38b4

File tree

1 file changed

+13
-1
lines changed
  • sdk/pinocchio/src/entrypoint

1 file changed

+13
-1
lines changed

sdk/pinocchio/src/entrypoint/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,15 +870,27 @@ mod tests {
870870
assert_eq!(account_info.data_len(), i);
871871
}
872872

873+
// Last unique account.
874+
let duplicated = unsafe { accounts[unique - 1].assume_init_ref() };
875+
873876
// Duplicated accounts should have the same `data_len` as the
874877
// last unique account.
875878
for account in accounts[unique..].iter() {
876879
let account_info = unsafe { account.assume_init_ref() };
877-
let duplicated = unsafe { accounts[unique - 1].assume_init_ref() };
878880

879881
assert_eq!(account_info.raw, duplicated.raw);
880882
assert_eq!(account_info.data_len(), duplicated.data_len());
883+
884+
let borrowed = account_info.try_borrow_mut_data().unwrap();
885+
// Only one mutable borrow at the same time should be allowed
886+
// on the duplicated account.
887+
assert!(duplicated.try_borrow_mut_data().is_err());
888+
drop(borrowed);
881889
}
890+
891+
// There should not be any mutable borrow on the duplicated account
892+
// at this point.
893+
assert!(duplicated.try_borrow_mut_data().is_ok());
882894
}
883895

884896
#[test]

0 commit comments

Comments
 (0)