Respect RefCell when calling invoke (#12858) (#12891)

* Respect RefCell when calling invoke

* nudge

(cherry picked from commit 969f7b015b)

Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
mergify[bot]
2020-10-15 02:15:36 +00:00
committed by GitHub
parent ceeeb3c9dd
commit bc96332899
3 changed files with 157 additions and 13 deletions

View File

@@ -144,6 +144,92 @@ fn process_instruction(
);
}
info!("Test refcell usage");
{
let writable = INVOKED_ARGUMENT_INDEX;
let readable = INVOKED_PROGRAM_INDEX;
let instruction = create_instruction(
*accounts[INVOKED_PROGRAM_INDEX].key,
&[
(accounts[writable].key, true, true),
(accounts[readable].key, false, false),
],
vec![TEST_RETURN_ERROR, 1, 2, 3, 4, 5],
);
// success with this account configuration as a check
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::Custom(42))
);
{
// writable but lamports borrow_mut'd
let _ref_mut = accounts[writable].try_borrow_mut_lamports()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::AccountBorrowFailed)
);
}
{
// writable but data borrow_mut'd
let _ref_mut = accounts[writable].try_borrow_mut_data()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::AccountBorrowFailed)
);
}
{
// writable but lamports borrow'd
let _ref_mut = accounts[writable].try_borrow_lamports()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::AccountBorrowFailed)
);
}
{
// writable but data borrow'd
let _ref_mut = accounts[writable].try_borrow_data()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::AccountBorrowFailed)
);
}
{
// readable but lamports borrow_mut'd
let _ref_mut = accounts[readable].try_borrow_mut_lamports()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::AccountBorrowFailed)
);
}
{
// readable but data borrow_mut'd
let _ref_mut = accounts[readable].try_borrow_mut_data()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::AccountBorrowFailed)
);
}
{
// readable but lamports borrow'd
let _ref_mut = accounts[readable].try_borrow_lamports()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::Custom(42))
);
}
{
// readable but data borrow'd
let _ref_mut = accounts[readable].try_borrow_data()?;
assert_eq!(
invoke(&instruction, accounts),
Err(ProgramError::Custom(42))
);
}
}
info!("Test create_program_address");
{
assert_eq!(