Add rust duplicate account test program (#7897)

automerge
This commit is contained in:
Jack May 2020-01-21 10:59:19 -08:00 committed by Grimes
parent bb950ec93e
commit 1a18f0ca55
6 changed files with 86 additions and 0 deletions

View File

@ -1987,6 +1987,14 @@ dependencies = [
"solana-sdk-bpf-test 0.23.0",
]
[[package]]
name = "solana-bpf-rust-dup-accounts"
version = "0.23.0"
dependencies = [
"solana-sdk 0.23.0",
"solana-sdk-bpf-test 0.23.0",
]
[[package]]
name = "solana-bpf-rust-external-spend"
version = "0.23.0"

View File

@ -37,6 +37,7 @@ members = [
"rust/128bit_dep",
"rust/alloc",
"rust/dep_crate",
"rust/dup_accounts",
"rust/external_spend",
"rust/iter",
"rust/many_args",

View File

@ -70,6 +70,7 @@ fn main() {
"128bit",
"alloc",
"dep_crate",
"dup_accounts",
"iter",
"many_args",
"external_spend",

View File

@ -0,0 +1,26 @@
# Note: This crate must be built using do.sh
[package]
name = "solana-bpf-rust-dup-accounts"
version = "0.23.0"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-sdk = { path = "../../../../sdk/", version = "0.23.0", default-features = false }
[dev_dependencies]
solana-sdk-bpf-test = { path = "../../../../sdk/bpf/rust/test", version = "0.23.0" }
[features]
program = ["solana-sdk/program"]
default = ["program"]
[lib]
name = "solana_bpf_rust_dup_accounts"
crate-type = ["cdylib"]

View File

@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []

View File

@ -0,0 +1,48 @@
//! @brief Example Rust-based BPF program that tests duplicate accounts passed via accounts
extern crate solana_sdk;
use solana_sdk::{
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, pubkey::Pubkey,
};
entrypoint!(process_instruction);
fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], data: &[u8]) -> u32 {
const FAILURE: u32 = 1;
match data[0] {
1 => {
info!("modify first account data");
accounts[2].data[0] = 1;
}
2 => {
info!("modify first account data");
accounts[3].data[0] = 2;
}
3 => {
info!("modify both account data, should fail");
accounts[2].data[0] = 1;
accounts[3].data[0] = 2;
}
4 => {
info!("modify first account lamports");
*accounts[1].lamports -= 1;
*accounts[2].lamports += 1;
}
5 => {
info!("modify first account lamports");
*accounts[1].lamports -= 2;
*accounts[3].lamports += 2;
}
6 => {
info!("modify both account lamports, should fail");
*accounts[1].lamports -= 1;
*accounts[2].lamports += 1;
*accounts[3].lamports += 2;
}
_ => {
info!("Unrecognized command");
return FAILURE;
}
}
SUCCESS
}