Skip to content

Commit beb17b3

Browse files
committed
add integration tests from old branch
1 parent 5456754 commit beb17b3

File tree

5 files changed

+1346
-85
lines changed

5 files changed

+1346
-85
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "write-to-account"
3+
version = "2.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
solana-program = { path = "../../../../sdk/program", version = "=2.1.0" }
8+
9+
[lib]
10+
crate-type = ["cdylib", "rlib"]
11+
12+
[workspace]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use solana_program::{
2+
account_info::{next_account_info, AccountInfo},
3+
entrypoint,
4+
entrypoint::ProgramResult,
5+
incinerator, msg,
6+
program_error::ProgramError,
7+
pubkey::Pubkey,
8+
};
9+
10+
entrypoint!(process_instruction);
11+
12+
fn process_instruction(
13+
_program_id: &Pubkey,
14+
accounts: &[AccountInfo],
15+
data: &[u8],
16+
) -> ProgramResult {
17+
let accounts_iter = &mut accounts.iter();
18+
let target_account_info = next_account_info(accounts_iter)?;
19+
match data[0] {
20+
// print account size
21+
0 => {
22+
msg!(
23+
"account size {}",
24+
target_account_info.try_borrow_data()?.len()
25+
);
26+
}
27+
// set account data
28+
1 => {
29+
let mut account_data = target_account_info.try_borrow_mut_data()?;
30+
account_data[0] = 100;
31+
}
32+
// deallocate account
33+
2 => {
34+
let incinerator_info = next_account_info(accounts_iter)?;
35+
if !incinerator::check_id(incinerator_info.key) {
36+
return Err(ProgramError::InvalidAccountData);
37+
}
38+
39+
let mut target_lamports = target_account_info.try_borrow_mut_lamports()?;
40+
let mut incinerator_lamports = incinerator_info.try_borrow_mut_lamports()?;
41+
42+
**incinerator_lamports = incinerator_lamports
43+
.checked_add(**target_lamports)
44+
.ok_or(ProgramError::ArithmeticOverflow)?;
45+
46+
**target_lamports = target_lamports
47+
.checked_sub(**target_lamports)
48+
.ok_or(ProgramError::InsufficientFunds)?;
49+
}
50+
// reallocate account
51+
3 => {
52+
let new_size = usize::from_le_bytes(data[1..9].try_into().unwrap());
53+
target_account_info.realloc(new_size, false)?;
54+
}
55+
// bad ixn
56+
_ => {
57+
return Err(ProgramError::InvalidArgument);
58+
}
59+
}
60+
61+
Ok(())
62+
}
Binary file not shown.

0 commit comments

Comments
 (0)