전체 테스트
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());}
핵심 사항
- 프로그램 배포:
add_program()를 사용하여 바이트에서 프로그램 배포 - include_bytes!: 컴파일 시점에 컴파일된 프로그램을 삽입
- 프로그램 ID:
target/deploy/의 keypair 사용 - 명령어: 프로그램 ID, 계정, 데이터로 커스텀 명령어 생성
- 로그 검증: 트랜잭션 로그를 확인하여 프로그램 실행 검증
더 자세한 배포 정보는 이 섹션을 참고하세요.
Is this page helpful?