Skip to content
Open
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
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.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ spl-token-2022-interface = "2.0.0"
# pinocchio
pinocchio = "=0.8.1"
pinocchio-log = "0.4.0"

# testing
litesvm = "0.8.1"
solana-instruction = "3.0.0"
solana-keypair = "3.0.1"
solana-pubkey = "3.0.0"
solana-transaction = "3.0.1"
solana-native-token = "3.0.0"
9 changes: 8 additions & 1 deletion basics/pda-rent-payer/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.workspace = true
solana-instruction.workspace = true
solana-keypair.workspace = true
solana-pubkey.workspace = true
solana-transaction.workspace = true
solana-native-token.workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::state::RentVault;

#[derive(BorshDeserialize, BorshSerialize)]
pub struct InitRentVaultArgs {
fund_lamports: u64,
pub fund_lamports: u64,
}

pub fn init_rent_vault(
Expand Down
70 changes: 70 additions & 0 deletions basics/pda-rent-payer/native/program/tests/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use litesvm::LiteSVM;
use pda_rent_payer_program::instructions::InitRentVaultArgs;
use pda_rent_payer_program::processor::MyInstruction;
use solana_instruction::{AccountMeta, Instruction};
use solana_keypair::{Keypair, Signer};
use solana_native_token::LAMPORTS_PER_SOL;
use solana_pubkey::Pubkey;
use solana_transaction::Transaction;

#[test]
fn test_pda_rent_payer() {
let program_id = Pubkey::new_unique();
let program_bytes = include_bytes!("../../../../../target/deploy/pda_rent_payer_program.so");

let mut svm = LiteSVM::new();
svm.add_program(program_id, program_bytes).unwrap();

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

let rent_value_pda = Pubkey::find_program_address(&[b"rent_vault"], &program_id).0;

let args = InitRentVaultArgs {
fund_lamports: 1000000000,
};

let data = borsh::to_vec(&MyInstruction::InitRentVault(args)).unwrap();

let ix = Instruction {
program_id,
accounts: vec![
AccountMeta::new(rent_value_pda, false),
AccountMeta::new(payer.pubkey(), true),
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 new_account = Keypair::new();

let data = borsh::to_vec(&MyInstruction::CreateNewAccount).unwrap();

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

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

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