Add BPf loader finalize test via inner instruction (#15708)

This commit is contained in:
Jack May
2021-03-04 12:34:36 -08:00
committed by GitHub
parent 99f0d29dd1
commit fb3837260c
8 changed files with 142 additions and 8 deletions

View File

@ -0,0 +1,18 @@
[package]
name = "solana-bpf-rust-finalize"
version = "1.6.0"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
edition = "2018"
[dependencies]
solana-program = { path = "../../../../sdk/program", version = "1.6.0" }
[lib]
crate-type = ["cdylib"]
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

View File

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

View File

@ -0,0 +1,25 @@
//! @brief Example Rust-based BPF sanity program that finalizes a BPF program
#![allow(unreachable_code)]
extern crate solana_program;
use solana_program::{
account_info::AccountInfo, bpf_loader, entrypoint, entrypoint::ProgramResult,
loader_instruction, msg, program::invoke, pubkey::Pubkey,
};
entrypoint!(process_instruction);
fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
msg!("Finalize a program");
invoke(
&loader_instruction::finalize(&accounts[0].key.clone(), &bpf_loader::id()),
accounts,
)?;
msg!("check executable");
assert!(accounts[0].executable);
Ok(())
}