Test Completo
tests/program_test.rs
use litesvm::LiteSVM;use solana_sdk::{instruction::{AccountMeta, Instruction},pubkey::Pubkey,signature::{Keypair, Signer},transaction::Transaction,};#[test]fn test_program_deployment() {let mut svm = LiteSVM::new();// Deploy the programlet program_id = Pubkey::new_unique();let program_bytes = include_bytes!("../target/deploy/hello_world.so");svm.add_program(program_id, program_bytes).unwrap();// Create payer accountlet payer = Keypair::new();svm.airdrop(&payer.pubkey(), 10_000_000_000).unwrap();// Create instruction to call programlet instruction = Instruction {program_id,accounts: vec![AccountMeta::new(payer.pubkey(), true),],data: vec![], // Program-specific data};// Send transactionlet tx = Transaction::new_signed_with_payer(&[instruction],Some(&payer.pubkey()),&[&payer],svm.latest_blockhash(),);let result = svm.send_transaction(tx).unwrap();// Verify program was calledassert!(result.logs.iter().any(|log|log.contains(&format!("Program {} invoke", program_id))));println!("Program called successfully!");println!("Logs:\n{}", result.pretty_logs());}
Punti Chiave
- Distribuzione del Programma: Usa
add_program()per distribuire un programma dai byte - include_bytes!: Incorpora il programma compilato al momento della compilazione
- ID del Programma: Usa il keypair da
target/deploy/ - Istruzioni: Crea istruzioni personalizzate con ID del programma, account e dati
- Verifica dei Log: Controlla i log delle transazioni per verificare l'esecuzione del programma
Per informazioni più dettagliate sulla distribuzione, leggi questa sezione.
Is this page helpful?