SOL転送

完全なテスト

tests/transfer_test.rs
use litesvm::LiteSVM;
use solana_sdk::{
signature::{Keypair, Signer},
system_instruction,
transaction::Transaction,
};
#[test]
fn test_sol_transfer() {
let mut svm = LiteSVM::new();
// Create accounts
let alice = Keypair::new();
let bob = Keypair::new();
// Fund alice with 10 SOL
svm.airdrop(&alice.pubkey(), 10_000_000_000).unwrap();
// Create transfer instruction
let transfer_ix = system_instruction::transfer(
&alice.pubkey(),
&bob.pubkey(),
1_000_000_000, // 1 SOL
);
// Build transaction
let tx = Transaction::new_signed_with_payer(
&[transfer_ix],
Some(&alice.pubkey()),
&[&alice],
svm.latest_blockhash(),
);
// Send and verify
let result = svm.send_transaction(tx).unwrap();
// Check balances
assert_eq!(svm.get_balance(&bob.pubkey()).unwrap(), 1_000_000_000);
assert!(svm.get_balance(&alice.pubkey()).unwrap() < 9_000_000_000);
println!("Transfer successful!");
println!("Compute units used: {}", result.compute_units_consumed);
println!("Transaction logs:\n{}", result.pretty_logs());
}

重要なポイント

  1. アカウント作成: Keypair::new() を使用してテストアカウントを作成する
  2. 資金調達: airdrop() を使用してアカウントにSOLを入金する
  3. システム命令: SOL転送には system_instruction::transfer() を使用する
  4. 残高確認: 転送を確認するためにトランザクション後の残高を確認する
  5. トランザクション手数料: トランザクション手数料のため、Aliceの残高は9 SOLをわずかに下回る

Is this page helpful?

目次

ページを編集
© 2026 Solana Foundation. 無断転載を禁じます。