Remove fee-payer guesswork from Message and Transaction (#10776)
* Make Message::new_with_payer the default constructor * Remove Transaction::new_[un]signed_instructions These guess the fee-payer instead of stating it explicitly
This commit is contained in:
@ -11,6 +11,7 @@ use solana_sdk::{
|
||||
clock::MAX_RECENT_BLOCKHASHES,
|
||||
genesis_config::create_genesis_config,
|
||||
instruction::InstructionError,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
transaction::Transaction,
|
||||
@ -52,7 +53,8 @@ pub fn create_builtin_transactions(
|
||||
|
||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||
Transaction::new_signed_instructions(&[&rando0], &[instruction], blockhash)
|
||||
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||
Transaction::new(&[&rando0], message, blockhash)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@ -73,7 +75,8 @@ pub fn create_native_loader_transactions(
|
||||
|
||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||
Transaction::new_signed_instructions(&[&rando0], &[instruction], blockhash)
|
||||
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||
Transaction::new(&[&rando0], message, blockhash)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -4273,11 +4273,8 @@ mod tests {
|
||||
let bank = Bank::new(&genesis_config);
|
||||
let instructions =
|
||||
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&mint_keypair],
|
||||
&instructions,
|
||||
genesis_config.hash(),
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let tx = Transaction::new(&[&mint_keypair], message, genesis_config.hash());
|
||||
assert_eq!(
|
||||
bank.process_transaction(&tx).unwrap_err(),
|
||||
TransactionError::InstructionError(
|
||||
@ -4298,11 +4295,8 @@ mod tests {
|
||||
let bank = Bank::new(&genesis_config);
|
||||
let instructions =
|
||||
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&mint_keypair],
|
||||
&instructions,
|
||||
genesis_config.hash(),
|
||||
);
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let tx = Transaction::new(&[&mint_keypair], message, genesis_config.hash());
|
||||
bank.process_transaction(&tx).unwrap();
|
||||
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 0);
|
||||
assert_eq!(bank.get_balance(&key1), 1);
|
||||
@ -5452,7 +5446,7 @@ mod tests {
|
||||
let mut transfer_instruction =
|
||||
system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0);
|
||||
transfer_instruction.accounts[0].is_signer = false;
|
||||
let message = Message::new_with_payer(&[transfer_instruction], None);
|
||||
let message = Message::new(&[transfer_instruction], None);
|
||||
let tx = Transaction::new(&[&Keypair::new(); 0], message, bank.last_blockhash());
|
||||
|
||||
assert_eq!(
|
||||
@ -5633,9 +5627,10 @@ mod tests {
|
||||
10,
|
||||
);
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &vote_keypair],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
@ -5690,9 +5685,10 @@ mod tests {
|
||||
10,
|
||||
));
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &vote_keypair, &stake_keypair],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
@ -5889,9 +5885,10 @@ mod tests {
|
||||
);
|
||||
instructions[1].program_id = mock_vote_program_id();
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
@ -5933,9 +5930,10 @@ mod tests {
|
||||
1,
|
||||
);
|
||||
|
||||
let transaction = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||
let transaction = Transaction::new(
|
||||
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
||||
&instructions,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
|
||||
@ -6123,9 +6121,10 @@ mod tests {
|
||||
&nonce_authority,
|
||||
nonce_lamports,
|
||||
));
|
||||
let setup_tx = Transaction::new_signed_instructions(
|
||||
let message = Message::new(&setup_ixs, Some(&mint_keypair.pubkey()));
|
||||
let setup_tx = Transaction::new(
|
||||
&[mint_keypair, &custodian_keypair, &nonce_keypair],
|
||||
&setup_ixs,
|
||||
message,
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
bank.process_transaction(&setup_tx)?;
|
||||
@ -6286,14 +6285,9 @@ mod tests {
|
||||
let blockhash = bank.last_blockhash();
|
||||
bank.store_account(&nonce.pubkey(), &nonce_account);
|
||||
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&nonce],
|
||||
&[system_instruction::assign(
|
||||
&nonce.pubkey(),
|
||||
&Pubkey::new(&[9u8; 32]),
|
||||
)],
|
||||
blockhash,
|
||||
);
|
||||
let ix = system_instruction::assign(&nonce.pubkey(), &Pubkey::new(&[9u8; 32]));
|
||||
let message = Message::new(&[ix], Some(&nonce.pubkey()));
|
||||
let tx = Transaction::new(&[&nonce], message, blockhash);
|
||||
|
||||
let expect = Err(TransactionError::InstructionError(
|
||||
0,
|
||||
|
@ -60,7 +60,7 @@ impl AsyncClient for BankClient {
|
||||
instruction: Instruction,
|
||||
recent_blockhash: Hash,
|
||||
) -> Result<Signature> {
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||
self.async_send_message(&[keypair], message, recent_blockhash)
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ impl SyncClient for BankClient {
|
||||
|
||||
/// Create and process a transaction from a single instruction.
|
||||
fn send_instruction(&self, keypair: &Keypair, instruction: Instruction) -> Result<Signature> {
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||
self.send_message(&[keypair], message)
|
||||
}
|
||||
|
||||
@ -306,7 +306,7 @@ mod tests {
|
||||
.accounts
|
||||
.push(AccountMeta::new(jane_pubkey, true));
|
||||
|
||||
let message = Message::new(&[transfer_instruction]);
|
||||
let message = Message::new(&[transfer_instruction], Some(&john_pubkey));
|
||||
bank_client.send_message(&doe_keypairs, message).unwrap();
|
||||
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 42);
|
||||
}
|
||||
|
@ -906,7 +906,7 @@ mod tests {
|
||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let allocate_with_seed = Message::new_with_payer(
|
||||
let allocate_with_seed = Message::new(
|
||||
&[system_instruction::allocate_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
@ -959,7 +959,7 @@ mod tests {
|
||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, len1, &program);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
|
||||
@ -977,7 +977,7 @@ mod tests {
|
||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, len2, &program);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
}
|
||||
@ -1016,7 +1016,7 @@ mod tests {
|
||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let assign_with_seed = Message::new_with_payer(
|
||||
let assign_with_seed = Message::new(
|
||||
&[system_instruction::assign_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
|
@ -28,7 +28,7 @@ pub fn load_program<T: Client>(
|
||||
bank_client
|
||||
.send_message(
|
||||
&[from_keypair, &program_keypair],
|
||||
Message::new(&[instruction]),
|
||||
Message::new(&[instruction], Some(&from_keypair.pubkey())),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@ -37,7 +37,7 @@ pub fn load_program<T: Client>(
|
||||
for chunk in program.chunks(chunk_size) {
|
||||
let instruction =
|
||||
loader_instruction::write(&program_pubkey, loader_pubkey, offset, chunk.to_vec());
|
||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&from_keypair.pubkey()));
|
||||
bank_client
|
||||
.send_message(&[from_keypair, &program_keypair], message)
|
||||
.unwrap();
|
||||
@ -45,7 +45,7 @@ pub fn load_program<T: Client>(
|
||||
}
|
||||
|
||||
let instruction = loader_instruction::finalize(&program_pubkey, loader_pubkey);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&from_keypair.pubkey()));
|
||||
bank_client
|
||||
.send_message(&[from_keypair, &program_keypair], message)
|
||||
.unwrap();
|
||||
|
@ -606,7 +606,7 @@ mod tests {
|
||||
AccountMeta::new(keys[not_owned_index], false),
|
||||
AccountMeta::new(keys[owned_index], false),
|
||||
];
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[Instruction::new(program_ids[owned_index], &[0_u8], metas)],
|
||||
None,
|
||||
);
|
||||
@ -1103,11 +1103,14 @@ mod tests {
|
||||
AccountMeta::new(from_pubkey, true),
|
||||
AccountMeta::new_readonly(to_pubkey, false),
|
||||
];
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::Correct,
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::Correct,
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
@ -1115,11 +1118,14 @@ mod tests {
|
||||
assert_eq!(accounts[0].borrow().lamports, 100);
|
||||
assert_eq!(accounts[1].borrow().lamports, 0);
|
||||
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptCredit { lamports: 50 },
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptCredit { lamports: 50 },
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
@ -1131,11 +1137,14 @@ mod tests {
|
||||
))
|
||||
);
|
||||
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptDataChange { data: 50 },
|
||||
account_metas,
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_system_program_id,
|
||||
&MockSystemInstruction::AttemptDataChange { data: 50 },
|
||||
account_metas,
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
@ -1229,11 +1238,14 @@ mod tests {
|
||||
];
|
||||
|
||||
// Try to borrow mut the same account
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::BorrowFail,
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::BorrowFail,
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
assert_eq!(
|
||||
@ -1245,24 +1257,30 @@ mod tests {
|
||||
);
|
||||
|
||||
// Try to borrow mut the same account in a safe way
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::MultiBorrowMut,
|
||||
account_metas.clone(),
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::MultiBorrowMut,
|
||||
account_metas.clone(),
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
assert_eq!(result, Ok(()));
|
||||
|
||||
// Do work on the same account but at different location in keyed_accounts[]
|
||||
let message = Message::new(&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::DoWork {
|
||||
lamports: 10,
|
||||
data: 42,
|
||||
},
|
||||
account_metas,
|
||||
)]);
|
||||
let message = Message::new(
|
||||
&[Instruction::new(
|
||||
mock_program_id,
|
||||
&MockSystemInstruction::DoWork {
|
||||
lamports: 10,
|
||||
data: 42,
|
||||
},
|
||||
account_metas,
|
||||
)],
|
||||
Some(&from_pubkey),
|
||||
);
|
||||
let result =
|
||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||
assert_eq!(result, Ok(()));
|
||||
@ -1349,7 +1367,7 @@ mod tests {
|
||||
&MockInstruction::NoopSuccess,
|
||||
metas.clone(),
|
||||
);
|
||||
let message = Message::new_with_payer(&[instruction], None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
message_processor.process_cross_program_instruction(
|
||||
&message,
|
||||
@ -1376,7 +1394,7 @@ mod tests {
|
||||
|
||||
for case in cases {
|
||||
let instruction = Instruction::new(callee_program_id, &case.0, metas.clone());
|
||||
let message = Message::new_with_payer(&[instruction], None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
message_processor.process_cross_program_instruction(
|
||||
&message,
|
||||
|
@ -93,6 +93,7 @@ mod tests {
|
||||
account_utils::State as AccountUtilsState,
|
||||
hash::Hash,
|
||||
instruction::InstructionError,
|
||||
message::Message,
|
||||
nonce::{self, account::with_test_keyed_account, Account as NonceAccount, State},
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
@ -106,14 +107,12 @@ mod tests {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let nonce_keypair = Keypair::new();
|
||||
let nonce_pubkey = nonce_keypair.pubkey();
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&from_keypair, &nonce_keypair],
|
||||
&[
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
],
|
||||
Hash::default(),
|
||||
);
|
||||
let instructions = [
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&nonce_pubkey));
|
||||
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||
(from_pubkey, nonce_pubkey, tx)
|
||||
}
|
||||
|
||||
@ -141,14 +140,12 @@ mod tests {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let nonce_keypair = Keypair::new();
|
||||
let nonce_pubkey = nonce_keypair.pubkey();
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&from_keypair, &nonce_keypair],
|
||||
&[
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
],
|
||||
Hash::default(),
|
||||
);
|
||||
let instructions = [
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&from_pubkey));
|
||||
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
||||
}
|
||||
|
||||
@ -158,19 +155,17 @@ mod tests {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let nonce_keypair = Keypair::new();
|
||||
let nonce_pubkey = nonce_keypair.pubkey();
|
||||
let tx = Transaction::new_signed_instructions(
|
||||
&[&from_keypair, &nonce_keypair],
|
||||
&[
|
||||
system_instruction::withdraw_nonce_account(
|
||||
&nonce_pubkey,
|
||||
&nonce_pubkey,
|
||||
&from_pubkey,
|
||||
42,
|
||||
),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
],
|
||||
Hash::default(),
|
||||
);
|
||||
let instructions = [
|
||||
system_instruction::withdraw_nonce_account(
|
||||
&nonce_pubkey,
|
||||
&nonce_pubkey,
|
||||
&from_pubkey,
|
||||
42,
|
||||
),
|
||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||
];
|
||||
let message = Message::new(&instructions, Some(&nonce_pubkey));
|
||||
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
||||
}
|
||||
|
||||
|
@ -909,7 +909,7 @@ mod tests {
|
||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let allocate_with_seed = Message::new_with_payer(
|
||||
let allocate_with_seed = Message::new(
|
||||
&[system_instruction::allocate_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
@ -962,7 +962,7 @@ mod tests {
|
||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, len1, &program);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_keypair.pubkey()));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
|
||||
@ -980,7 +980,7 @@ mod tests {
|
||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, len2, &program);
|
||||
let message = Message::new(&[ix]);
|
||||
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||
assert!(r.is_ok());
|
||||
}
|
||||
@ -1019,7 +1019,7 @@ mod tests {
|
||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||
.unwrap();
|
||||
|
||||
let assign_with_seed = Message::new_with_payer(
|
||||
let assign_with_seed = Message::new(
|
||||
&[system_instruction::assign_with_seed(
|
||||
&alice_with_seed,
|
||||
&alice_pubkey,
|
||||
|
@ -53,7 +53,7 @@ fn fill_epoch_with_votes(
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let parent = bank.parent().unwrap();
|
||||
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[vote_instruction::vote(
|
||||
&vote_pubkey,
|
||||
&vote_pubkey,
|
||||
@ -119,15 +119,18 @@ fn test_stake_create_and_split_single_signature() {
|
||||
let lamports = 1_000_000;
|
||||
|
||||
// Create stake account with seed
|
||||
let message = Message::new(&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
));
|
||||
let message = Message::new(
|
||||
&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
),
|
||||
Some(&staker_pubkey),
|
||||
);
|
||||
|
||||
// only one signature required
|
||||
bank_client
|
||||
@ -139,7 +142,7 @@ fn test_stake_create_and_split_single_signature() {
|
||||
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &solana_stake_program::id())
|
||||
.unwrap();
|
||||
// Test split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&stake_instruction::split_with_seed(
|
||||
&stake_address, // original
|
||||
&staker_pubkey, // authorized
|
||||
@ -183,15 +186,18 @@ fn test_stake_create_and_split_to_existing_system_account() {
|
||||
let lamports = 1_000_000;
|
||||
|
||||
// Create stake account with seed
|
||||
let message = Message::new(&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
));
|
||||
let message = Message::new(
|
||||
&stake_instruction::create_account_with_seed(
|
||||
&staker_pubkey, // from
|
||||
&stake_address, // to
|
||||
&staker_pubkey, // base
|
||||
"stake", // seed
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
lamports,
|
||||
),
|
||||
Some(&staker_pubkey),
|
||||
);
|
||||
|
||||
bank_client
|
||||
.send_message(&[&staker_keypair], message)
|
||||
@ -212,7 +218,7 @@ fn test_stake_create_and_split_to_existing_system_account() {
|
||||
);
|
||||
|
||||
// Verify the split fails because the account is already in use
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&stake_instruction::split_with_seed(
|
||||
&stake_address, // original
|
||||
&staker_pubkey, // authorized
|
||||
@ -256,31 +262,37 @@ fn test_stake_account_lifetime() {
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
// Create Vote Account
|
||||
let message = Message::new(&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
));
|
||||
let message = Message::new(
|
||||
&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
||||
.expect("failed to create vote account");
|
||||
|
||||
let authorized = stake_state::Authorized::auto(&stake_pubkey);
|
||||
// Create stake account and delegate to vote account
|
||||
let message = Message::new(&stake_instruction::create_account_and_delegate_stake(
|
||||
&mint_pubkey,
|
||||
&stake_pubkey,
|
||||
&vote_pubkey,
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
1_000_000,
|
||||
));
|
||||
let message = Message::new(
|
||||
&stake_instruction::create_account_and_delegate_stake(
|
||||
&mint_pubkey,
|
||||
&stake_pubkey,
|
||||
&vote_pubkey,
|
||||
&authorized,
|
||||
&stake_state::Lockup::default(),
|
||||
1_000_000,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair, &stake_keypair], message)
|
||||
.expect("failed to create and delegate stake account");
|
||||
@ -295,7 +307,7 @@ fn test_stake_account_lifetime() {
|
||||
}
|
||||
|
||||
// Test that we cannot withdraw anything until deactivation
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&stake_pubkey,
|
||||
&stake_pubkey,
|
||||
@ -359,7 +371,7 @@ fn test_stake_account_lifetime() {
|
||||
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
// Test split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&stake_instruction::split(
|
||||
&stake_pubkey,
|
||||
&stake_pubkey,
|
||||
@ -376,7 +388,7 @@ fn test_stake_account_lifetime() {
|
||||
.is_ok());
|
||||
|
||||
// Deactivate the split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::deactivate_stake(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
@ -390,7 +402,7 @@ fn test_stake_account_lifetime() {
|
||||
let split_staked = get_staked(&bank, &split_stake_pubkey);
|
||||
|
||||
// Test that we cannot withdraw above what's staked
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
@ -412,7 +424,7 @@ fn test_stake_account_lifetime() {
|
||||
assert!(split_staked > 0);
|
||||
|
||||
// withdrawal in cooldown
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
@ -428,7 +440,7 @@ fn test_stake_account_lifetime() {
|
||||
.is_err());
|
||||
|
||||
// but we can withdraw unstaked
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
@ -453,7 +465,7 @@ fn test_stake_account_lifetime() {
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
|
||||
// Test that we can withdraw everything else out of the split
|
||||
let message = Message::new_with_payer(
|
||||
let message = Message::new(
|
||||
&[stake_instruction::withdraw(
|
||||
&split_stake_pubkey,
|
||||
&stake_pubkey,
|
||||
@ -494,17 +506,20 @@ fn test_create_stake_account_from_seed() {
|
||||
Pubkey::create_with_seed(&mint_pubkey, seed, &solana_stake_program::id()).unwrap();
|
||||
|
||||
// Create Vote Account
|
||||
let message = Message::new(&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
));
|
||||
let message = Message::new(
|
||||
&vote_instruction::create_account(
|
||||
&mint_pubkey,
|
||||
&vote_pubkey,
|
||||
&VoteInit {
|
||||
node_pubkey: identity_pubkey,
|
||||
authorized_voter: vote_pubkey,
|
||||
authorized_withdrawer: vote_pubkey,
|
||||
commission: 50,
|
||||
},
|
||||
10,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
||||
.expect("failed to create vote account");
|
||||
@ -522,6 +537,7 @@ fn test_create_stake_account_from_seed() {
|
||||
&stake_state::Lockup::default(),
|
||||
1_000_000,
|
||||
),
|
||||
Some(&mint_pubkey),
|
||||
);
|
||||
bank_client
|
||||
.send_message(&[&mint_keypair], message)
|
||||
|
Reference in New Issue
Block a user