use light_token::instruction::{Transfer, LIGHT_TOKEN_PROGRAM_ID};
use solana_instruction::{AccountMeta, Instruction};
use solana_pubkey::Pubkey;
#[test]
fn test_transfer_basic() {
let source = Pubkey::new_from_array([1u8; 32]);
let destination = Pubkey::new_from_array([2u8; 32]);
let authority = Pubkey::new_from_array([3u8; 32]);
let fee_payer = Pubkey::new_from_array([4u8; 32]);
let instruction = Transfer {
source,
destination,
amount: 100,
authority,
fee_payer,
}
.instruction()
.expect("Failed to create instruction");
let expected = Instruction {
program_id: LIGHT_TOKEN_PROGRAM_ID,
accounts: vec![
AccountMeta::new(source, false),
AccountMeta::new(destination, false),
AccountMeta::new_readonly(authority, true),
AccountMeta::new_readonly(Pubkey::default(), false),
AccountMeta::new(fee_payer, true),
],
data: vec![
3u8, 100, 0, 0, 0, 0, 0, 0, 0, ],
};
assert_eq!(
instruction, expected,
"Transfer instruction should match expected"
);
}
#[test]
fn test_transfer_with_max_top_up() {
let source = Pubkey::new_from_array([1u8; 32]);
let destination = Pubkey::new_from_array([2u8; 32]);
let authority = Pubkey::new_from_array([3u8; 32]);
let fee_payer = Pubkey::new_from_array([4u8; 32]);
let instruction = Transfer {
source,
destination,
amount: 100,
authority,
fee_payer,
}
.with_max_top_up(500)
.instruction()
.expect("Failed to create instruction");
let expected = Instruction {
program_id: LIGHT_TOKEN_PROGRAM_ID,
accounts: vec![
AccountMeta::new(source, false),
AccountMeta::new(destination, false),
AccountMeta::new_readonly(authority, true),
AccountMeta::new_readonly(Pubkey::default(), false),
AccountMeta::new(fee_payer, true),
],
data: vec![
3u8, 100, 0, 0, 0, 0, 0, 0, 0, 244, 1, ],
};
assert_eq!(
instruction, expected,
"Transfer instruction with max_top_up should match expected"
);
}