Add Rust BPF Tick Height test (#4718)

This commit is contained in:
Jack May
2019-06-18 15:56:24 -07:00
committed by GitHub
parent e43a634944
commit fdb57bc5db
6 changed files with 77 additions and 1 deletions

View File

@ -0,0 +1,3 @@
/target/
Cargo.lock

View File

@ -0,0 +1,24 @@
# Note: This crate must be built using build.sh
[package]
name = "solana-bpf-rust-tick-height"
version = "0.16.0"
description = "Solana BPF noop 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]
byteorder = { version = "1", default-features = false }
solana-sdk-bpf-utils = { path = "../../../../sdk/bpf/rust/rust-utils", version = "0.16.0" }
[workspace]
members = []
[lib]
crate-type = ["cdylib"]
name = "solana_bpf_rust_tick_height"

View File

@ -0,0 +1,6 @@
[dependencies.compiler_builtins]
path = "../../../../sdk/bpf/dependencies/rust-bpf-sysroot/src/compiler-builtins"
features = ["c", "mem"]
[target.bpfel-unknown-unknown.dependencies]
alloc = { path = "../../../../sdk/bpf/dependencies/rust-bpf-sysroot/src/liballoc" }

View File

@ -0,0 +1,27 @@
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
#![no_std]
#![allow(unreachable_code)]
extern crate solana_sdk_bpf_utils;
use byteorder::{ByteOrder, LittleEndian};
use solana_sdk_bpf_utils::entrypoint;
use solana_sdk_bpf_utils::entrypoint::*;
use solana_sdk_bpf_utils::log::*;
entrypoint!(process_instruction);
fn process_instruction(
ka: &mut [Option<SolKeyedAccount>; MAX_ACCOUNTS],
_info: &SolClusterInfo,
_data: &[u8],
) -> bool {
sol_log("Tick Height:");
if let Some(k) = &ka[2] {
let tick_height = LittleEndian::read_u64(k.data);
assert_eq!(10u64, tick_height);
sol_log("Success");
return true
}
panic!();
}