fix: remove deprecated bpf-sdk, localnet, and examples

BREAKING CHANGE: Removed binaries solana-localnet and solana-bpf-sdk-install.
Please install the Solana CLI tools to download the BPF SDK and to
install the solana-test-validator binary intead.
This commit is contained in:
Justin Starry
2021-03-15 15:35:41 +08:00
committed by Justin Starry
parent f46f346710
commit e9b08b5e7f
26 changed files with 33 additions and 472 deletions

View File

@ -17,52 +17,7 @@ use(chaiAsPromised);
if (process.env.TEST_LIVE) {
describe('BPF Loader', () => {
it('load BPF C program', async () => {
const data = await fs.readFile('test/fixtures/noop-c/noop.so');
const connection = new Connection(url, 'confirmed');
const {feeCalculator} = await connection.getRecentBlockhash();
const fees =
feeCalculator.lamportsPerSignature *
BpfLoader.getMinNumSignatures(data.length);
const payerBalance = await connection.getMinimumBalanceForRentExemption(
0,
);
const executableBalance = await connection.getMinimumBalanceForRentExemption(
data.length,
);
const from = new Account();
await helpers.airdrop({
connection,
address: from.publicKey,
amount: payerBalance + fees + executableBalance,
});
const program = new Account();
await BpfLoader.load(
connection,
from,
program,
data,
BPF_LOADER_PROGRAM_ID,
);
// Check that program loading costed exactly `fees + executableBalance`
const fromBalance = await connection.getBalance(from.publicKey);
expect(fromBalance).to.eq(payerBalance);
const transaction = new Transaction().add({
keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}],
programId: program.publicKey,
});
await sendAndConfirmTransaction(connection, transaction, [from], {
commitment: 'confirmed',
preflightCommitment: 'confirmed',
});
}).timeout(5000);
describe('load BPF Rust program', () => {
describe('load BPF program', () => {
const connection = new Connection(url, 'confirmed');
let program = new Account();
@ -72,7 +27,7 @@ if (process.env.TEST_LIVE) {
before(async function () {
this.timeout(60_000);
programData = await fs.readFile(
'test/fixtures/noop-rust/solana_bpf_rust_noop.so',
'test/fixtures/noop-program/solana_bpf_rust_noop.so',
);
const {feeCalculator} = await connection.getRecentBlockhash();

View File

@ -927,7 +927,7 @@ describe('Connection', () => {
},
});
// Block 0 never has any transactions in automation localnet
// Block 0 never has any transactions in test validator
const block0 = await connection.getConfirmedBlock(0);
const blockhash0 = block0.blockhash;
expect(block0.transactions).to.have.length(0);

View File

@ -1,7 +0,0 @@
#!/usr/bin/env bash
set -ex
cd "$(dirname "$0")"
make -C ../../../examples/bpf-c-noop/
cp ../../../examples/bpf-c-noop/out/noop.so .

View File

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

View File

@ -0,0 +1,23 @@
[package]
name = "solana-bpf-rust-noop"
version = "0.1.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/"
documentation = "https://docs.rs/solana-bpf-rust-noop"
edition = "2018"
[dependencies]
num-derive = "0.2"
num-traits = "0.2"
solana-program = "1.4.16"
thiserror = "1.0"
[workspace]
members = []
[lib]
name = "solana_bpf_rust_noop"
crate-type = ["cdylib"]

View File

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

7
web3.js/test/fixtures/noop-program/build.sh vendored Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -ex
cd "$(dirname "$0")"
cargo build-bpf
cp ./target/deploy/solana_bpf_rust_noop.so .

Binary file not shown.

View File

@ -0,0 +1,70 @@
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
use solana_program::{
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, log::*, pubkey::Pubkey,
};
#[derive(Debug, PartialEq)]
struct SStruct {
x: u64,
y: u64,
z: u64,
}
#[inline(never)]
fn return_sstruct() -> SStruct {
SStruct { x: 1, y: 2, z: 3 }
}
entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
msg!("Program identifier:");
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.
msg!("Account keys and instruction input data:");
sol_log_params(accounts, instruction_data);
{
// Test - use std methods, unwrap
// valid bytes, in a stack-allocated array
let sparkle_heart = [240, 159, 146, 150];
let result_str = std::str::from_utf8(&sparkle_heart).unwrap();
assert_eq!(4, result_str.len());
assert_eq!("💖", result_str);
msg!(result_str);
}
{
// Test - struct return
let s = return_sstruct();
assert_eq!(s.x + s.y + s.z, 6);
}
{
// Test - arch config
#[cfg(not(target_arch = "bpf"))]
panic!();
}
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_return_sstruct() {
assert_eq!(SStruct { x: 1, y: 2, z: 3 }, return_sstruct());
}
}

View File

@ -1,7 +0,0 @@
#!/usr/bin/env bash
set -ex
cd "$(dirname "$0")"
cargo build-bpf --manifest-path=../../../examples/bpf-rust-noop/Cargo.toml
cp ../../../examples/bpf-rust-noop/target/deploy/solana_bpf_rust_noop.so .