forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svm: improve integration test framework for SIMD83
- Loading branch information
Showing
5 changed files
with
252 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "write-to-account" | ||
version = "2.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
solana-program = { path = "../../../../sdk/program", version = "=2.1.0" } | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[workspace] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use solana_program::{ | ||
account_info::{next_account_info, AccountInfo}, | ||
entrypoint, | ||
entrypoint::ProgramResult, | ||
incinerator, msg, | ||
program_error::ProgramError, | ||
pubkey::Pubkey, | ||
}; | ||
|
||
entrypoint!(process_instruction); | ||
|
||
fn process_instruction( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
data: &[u8], | ||
) -> ProgramResult { | ||
let accounts_iter = &mut accounts.iter(); | ||
let target_account_info = next_account_info(accounts_iter)?; | ||
match data[0] { | ||
// print account size | ||
0 => { | ||
msg!( | ||
"account size {}", | ||
target_account_info.try_borrow_data()?.len() | ||
); | ||
} | ||
// set account data | ||
1 => { | ||
let mut account_data = target_account_info.try_borrow_mut_data()?; | ||
account_data[0] = 100; | ||
} | ||
// deallocate account | ||
2 => { | ||
let incinerator_info = next_account_info(accounts_iter)?; | ||
if !incinerator::check_id(incinerator_info.key) { | ||
return Err(ProgramError::InvalidAccountData); | ||
} | ||
|
||
let mut target_lamports = target_account_info.try_borrow_mut_lamports()?; | ||
let mut incinerator_lamports = incinerator_info.try_borrow_mut_lamports()?; | ||
|
||
**incinerator_lamports = incinerator_lamports | ||
.checked_add(**target_lamports) | ||
.ok_or(ProgramError::ArithmeticOverflow)?; | ||
|
||
**target_lamports = target_lamports | ||
.checked_sub(**target_lamports) | ||
.ok_or(ProgramError::InsufficientFunds)?; | ||
} | ||
// reallocate account | ||
3 => { | ||
let new_size = usize::from_le_bytes(data[1..9].try_into().unwrap()); | ||
target_account_info.realloc(new_size, false)?; | ||
} | ||
// bad ixn | ||
_ => { | ||
return Err(ProgramError::InvalidArgument); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Binary file added
BIN
+21.5 KB
svm/tests/example-programs/write-to-account/write_to_account_program.so
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.