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
137 changes: 137 additions & 0 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion basics/checking-accounts/native/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ 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-keypair = "3.0.1"
solana-native-token = "3.0.0"
solana-pubkey = "3.0.0"
solana-sdk = "3.0.0"
solana-transaction = "3.0.1"
62 changes: 62 additions & 0 deletions basics/checking-accounts/native/program/tests/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use litesvm::LiteSVM;
use solana_keypair::{Keypair, Signer};
use solana_native_token::LAMPORTS_PER_SOL;
use solana_pubkey::Pubkey;
use solana_system_interface::instruction::create_account;
use solana_transaction::{AccountMeta, Instruction, Transaction};

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

let payer = Keypair::new();
let account_to_change = Keypair::new();
let account_to_create = Keypair::new();

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");

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

let create_account_ix = create_account(
&payer.pubkey(),
&account_to_change.pubkey(),
LAMPORTS_PER_SOL,
0,
&program_id,
);

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

// verify tx was sent successfully
let _ = svm.send_transaction(tx).is_ok();

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

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

// verify tx was sent successfully
let _ = svm.send_transaction(tx).is_ok();
}
Loading