fix: update examples (#485)
This commit is contained in:
@ -1,17 +1,13 @@
|
||||
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
||||
|
||||
#![no_std]
|
||||
#![allow(unreachable_code)]
|
||||
#![allow(unused_attributes)]
|
||||
|
||||
#[cfg(not(test))]
|
||||
extern crate solana_sdk_bpf_no_std;
|
||||
extern crate solana_sdk_bpf_utils;
|
||||
|
||||
use solana_sdk_bpf_utils::entrypoint::*;
|
||||
use solana_sdk_bpf_utils::log::*;
|
||||
use solana_sdk_bpf_utils::{entrypoint, info};
|
||||
extern crate solana_sdk;
|
||||
use solana_sdk::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::SUCCESS, info, log::*, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct SStruct {
|
||||
x: u64,
|
||||
y: u64,
|
||||
@ -24,28 +20,22 @@ fn return_sstruct() -> SStruct {
|
||||
}
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(ka: &mut [SolKeyedAccount], info: &SolClusterInfo, data: &[u8]) -> bool {
|
||||
fn process_instruction(program_id: &Pubkey, accounts: &mut [AccountInfo], data: &[u8]) -> u32 {
|
||||
info!("Program identifier:");
|
||||
sol_log_key(&info.program_id);
|
||||
program_id.log();
|
||||
|
||||
// Log the provided account keys and instruction input data. In the case of
|
||||
// the no-op program, no account keys or input data are expected but real
|
||||
// programs will have specific requirements so they can do their work.
|
||||
info!("Account keys and instruction input data:");
|
||||
sol_log_params(ka, data);
|
||||
sol_log_params(accounts, data);
|
||||
|
||||
{
|
||||
// Test - arch config
|
||||
#[cfg(not(target_arch = "bpf"))]
|
||||
panic!();
|
||||
}
|
||||
|
||||
{
|
||||
// Test - use core methods, unwrap
|
||||
// Test - use std methods, unwrap
|
||||
|
||||
// valid bytes, in a stack-allocated array
|
||||
let sparkle_heart = [240, 159, 146, 150];
|
||||
let result_str = core::str::from_utf8(&sparkle_heart).unwrap();
|
||||
let result_str = std::str::from_utf8(&sparkle_heart).unwrap();
|
||||
assert_eq!(4, result_str.len());
|
||||
assert_eq!("💖", result_str);
|
||||
info!(result_str);
|
||||
@ -58,6 +48,21 @@ fn process_instruction(ka: &mut [SolKeyedAccount], info: &SolClusterInfo, data:
|
||||
assert_eq!(s.x + s.y + s.z, 6);
|
||||
}
|
||||
|
||||
info!("Success");
|
||||
true
|
||||
{
|
||||
// Test - arch config
|
||||
#[cfg(not(target_arch = "bpf"))]
|
||||
panic!();
|
||||
}
|
||||
|
||||
SUCCESS
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_return_sstruct() {
|
||||
assert_eq!(SStruct { x: 1, y: 2, z: 3 }, return_sstruct());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user