Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/solana-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ jobs:
return 1
fi

# Run Rust unit tests
# Test
if ! pnpm build-and-test; then
echo "::error::tests failed for $project"
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi

# Run Rust unit tests
if [ -d "program" ]; then
echo "Running Rust unit tests for $project"
if ! cargo test --manifest-path=./program/Cargo.toml; then
Expand All @@ -146,14 +154,6 @@ jobs:
fi
fi

# Test
if ! pnpm build-and-test; then
echo "::error::tests failed for $project"
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi

echo "Build and tests succeeded for $project with $solana_version version."
cd - > /dev/null
return 0
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions basics/account-data/native/program/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ fn test_account_data() {

svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();

let program_bytes =
include_bytes!("../../../../../target/deploy/account_data_native_program.so");
let program_bytes = include_bytes!("../../tests/fixtures/account_data_native_program.so");

svm.add_program(program_id, program_bytes).unwrap();

Expand Down
3 changes: 1 addition & 2 deletions basics/checking-accounts/native/program/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ fn test_checking_accounts() {
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();

let program_id = Pubkey::new_unique();
let program_bytes =
include_bytes!("../../../../../target/deploy/checking_accounts_native_program.so");
let program_bytes = include_bytes!("../../tests/fixtures/checking_accounts_native_program.so");

svm.add_program(program_id, program_bytes).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion basics/checking-accounts/native/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { start } from 'solana-bankrun';

describe('Checking accounts', async () => {
const PROGRAM_ID = PublicKey.unique();
const context = await start([{ name: 'checking_accounts_program', programId: PROGRAM_ID }], []);
const context = await start([{ name: 'checking_accounts_native_program', programId: PROGRAM_ID }], []);
const client = context.banksClient;
const payer = context.payer;
const rent = await client.getRent();
Expand Down
2 changes: 1 addition & 1 deletion basics/program-derived-addresses/native/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { start } from 'solana-bankrun';

describe('PDAs', async () => {
const PROGRAM_ID = PublicKey.unique();
const context = await start([{ name: 'program_derived_addresses_program', programId: PROGRAM_ID }], []);
const context = await start([{ name: 'program_derived_addresses_native_program', programId: PROGRAM_ID }], []);
const client = context.banksClient;
const payer = context.payer;
const rent = await client.getRent();
Expand Down
1 change: 0 additions & 1 deletion basics/repository-layout/native/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ solana-program = "2.0"
crate-type = ["cdylib", "lib"]

[features]
anchor-debug = []
custom-heap = []
custom-panic = []

Expand Down
9 changes: 8 additions & 1 deletion basics/transfer-sol/native/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ solana-system-interface.workspace = true
crate-type = ["cdylib", "lib"]

[features]
anchor-debug = []
custom-heap = []
custom-panic = []

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }

[dev-dependencies]
litesvm = "0.8.1"
solana-instruction = "3.0.0"
solana-keypair = "3.0.1"
solana-native-token = "3.0.0"
solana-pubkey = "3.0.0"
solana-transaction = "3.0.1"
93 changes: 93 additions & 0 deletions basics/transfer-sol/native/program/tests/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use litesvm::LiteSVM;
use solana_instruction::{AccountMeta, Instruction};
use solana_keypair::{Keypair, Signer};
use solana_program::native_token::LAMPORTS_PER_SOL;
use solana_pubkey::Pubkey;
use solana_system_interface::instruction::create_account;
use solana_transaction::Transaction;
use transfer_sol_program::processor::TransferInstruction;

#[test]
fn test_transfer_sol() {
let mut svm = LiteSVM::new();

let program_id = Pubkey::new_unique();
let program_bytes = include_bytes!("../../tests/fixtures/transfer_sol_program.so");

svm.add_program(program_id, program_bytes).unwrap();

let payer = Keypair::new();
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();

let test_recipient1 = Keypair::new();
let test_recipient2 = Keypair::new();
let test_recipient3 = Keypair::new();

let payer_balance_before = svm.get_balance(&payer.pubkey()).unwrap();
let recipient_balance_before = svm.get_balance(&test_recipient1.pubkey()).unwrap_or(0);

let data = borsh::to_vec(&TransferInstruction::CpiTransfer(LAMPORTS_PER_SOL)).unwrap();

let ix = Instruction {
program_id,
accounts: vec![
AccountMeta::new(payer.pubkey(), true),
AccountMeta::new(test_recipient1.pubkey(), false),
AccountMeta::new(solana_system_interface::program::ID, false),
],
data,
};

let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&payer.pubkey()),
&[&payer],
svm.latest_blockhash(),
);

let _ = svm.send_transaction(tx).is_ok();

let payer_balance_after = svm.get_balance(&payer.pubkey()).unwrap();
let recipient_balance_after = svm.get_balance(&test_recipient1.pubkey()).unwrap_or(0);

assert!(payer_balance_before > payer_balance_after);
assert!(recipient_balance_before < recipient_balance_after);

let create_ix = create_account(
&payer.pubkey(),
&test_recipient2.pubkey(),
2 * LAMPORTS_PER_SOL,
0,
&program_id,
);

let tx = Transaction::new_signed_with_payer(
&[create_ix],
Some(&payer.pubkey()),
&[&payer, &test_recipient2],
svm.latest_blockhash(),
);

let _ = svm.send_transaction(tx).is_ok();

let data = borsh::to_vec(&TransferInstruction::ProgramTransfer(LAMPORTS_PER_SOL)).unwrap();

let ix = Instruction {
program_id,
accounts: vec![
AccountMeta::new(test_recipient2.pubkey(), true),
AccountMeta::new(test_recipient3.pubkey(), false),
AccountMeta::new(solana_system_interface::program::ID, false),
],
data,
};

let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&payer.pubkey()),
&[&payer, &test_recipient2],
svm.latest_blockhash(),
);

let _ = svm.send_transaction(tx).is_ok();
}