Deprecate Instruction::new (#15695)

This commit is contained in:
Jack May
2021-03-03 21:46:48 -08:00
committed by GitHub
parent d6ea2f392b
commit b53cb8eb2d
32 changed files with 272 additions and 207 deletions

View File

@ -5386,8 +5386,11 @@ pub(crate) mod tests {
AccountMeta::new(keypair2.pubkey(), true),
AccountMeta::new_readonly(read_only_keypair.pubkey(), false),
];
let deduct_instruction =
Instruction::new(mock_program_id, &MockInstruction::Deduction, account_metas);
let deduct_instruction = Instruction::new_with_bincode(
mock_program_id,
&MockInstruction::Deduction,
account_metas,
);
Transaction::new_signed_with_payer(
&[deduct_instruction],
Some(&payer.pubkey()),
@ -9788,7 +9791,7 @@ pub(crate) mod tests {
AccountMeta::new(to_pubkey, false),
AccountMeta::new(dup_pubkey, false),
];
let instruction = Instruction::new(mock_program_id, &10, account_metas);
let instruction = Instruction::new_with_bincode(mock_program_id, &10, account_metas);
let tx = Transaction::new_signed_with_payer(
&[instruction],
Some(&mint_keypair.pubkey()),
@ -9834,7 +9837,7 @@ pub(crate) mod tests {
AccountMeta::new(dup_pubkey, false),
AccountMeta::new(mock_program_id, false),
];
let instruction = Instruction::new(mock_program_id, &10, account_metas);
let instruction = Instruction::new_with_bincode(mock_program_id, &10, account_metas);
let tx = Transaction::new_signed_with_payer(
&[instruction],
Some(&mint_keypair.pubkey()),
@ -9860,7 +9863,8 @@ pub(crate) mod tests {
AccountMeta::new(to_pubkey, false),
];
let instruction = Instruction::new(solana_vote_program::id(), &10, account_metas);
let instruction =
Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas);
let mut tx = Transaction::new_signed_with_payer(
&[instruction],
Some(&mint_keypair.pubkey()),
@ -9930,7 +9934,8 @@ pub(crate) mod tests {
mock_ok_vote_processor,
);
let instruction = Instruction::new(solana_vote_program::id(), &10, account_metas);
let instruction =
Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas);
let mut tx = Transaction::new_signed_with_payer(
&[instruction],
Some(&mint_keypair.pubkey()),
@ -9963,7 +9968,8 @@ pub(crate) mod tests {
mock_ok_vote_processor,
);
let instruction = Instruction::new(solana_vote_program::id(), &10, account_metas);
let instruction =
Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas);
let mut tx = Transaction::new_signed_with_payer(
&[instruction],
Some(&mint_keypair.pubkey()),
@ -10020,7 +10026,8 @@ pub(crate) mod tests {
mock_ok_vote_processor,
);
let instruction = Instruction::new(solana_vote_program::id(), &10, account_metas);
let instruction =
Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas);
let mut tx = Transaction::new_signed_with_payer(
&[instruction],
Some(&mint_keypair.pubkey()),
@ -10267,7 +10274,7 @@ pub(crate) mod tests {
program2_account.executable = true;
bank.store_account(&program2_pubkey, &program2_account);
let instruction = Instruction::new(program2_pubkey, &10, vec![]);
let instruction = Instruction::new_with_bincode(program2_pubkey, &10, vec![]);
let tx = Transaction::new_signed_with_payer(
&[instruction.clone(), instruction],
Some(&mint_keypair.pubkey()),
@ -11515,7 +11522,11 @@ pub(crate) mod tests {
let bank = Bank::new(&genesis_config);
let tx = Transaction::new_signed_with_payer(
&[Instruction::new(native_loader::id(), &(), vec![])],
&[Instruction::new_with_bincode(
native_loader::id(),
&(),
vec![],
)],
Some(&mint_keypair.pubkey()),
&[&mint_keypair],
bank.last_blockhash(),
@ -11544,7 +11555,7 @@ pub(crate) mod tests {
0,
&native_loader::id(),
),
Instruction::new(
Instruction::new_with_bincode(
native_loader::id(),
&(),
vec![AccountMeta::new(to_keypair.pubkey(), false)],
@ -11571,7 +11582,7 @@ pub(crate) mod tests {
100,
&native_loader::id(),
),
Instruction::new(
Instruction::new_with_bincode(
native_loader::id(),
&(),
vec![AccountMeta::new(to_keypair.pubkey(), false)],

View File

@ -199,5 +199,5 @@ pub fn create_invoke_instruction<T: Serialize>(
data: &T,
) -> Instruction {
let account_metas = vec![AccountMeta::new(from_pubkey, true)];
Instruction::new(program_id, data, account_metas)
Instruction::new_with_bincode(program_id, data, account_metas)
}

View File

@ -1170,7 +1170,11 @@ mod tests {
AccountMeta::new(keys[owned_index], false),
];
let message = Message::new(
&[Instruction::new(program_ids[owned_index], &[0_u8], metas)],
&[Instruction::new_with_bytes(
program_ids[owned_index],
&[0],
metas,
)],
None,
);
@ -1701,7 +1705,7 @@ mod tests {
AccountMeta::new_readonly(to_pubkey, false),
];
let message = Message::new(
&[Instruction::new(
&[Instruction::new_with_bincode(
mock_system_program_id,
&MockSystemInstruction::Correct,
account_metas.clone(),
@ -1727,7 +1731,7 @@ mod tests {
assert_eq!(accounts[1].borrow().lamports, 0);
let message = Message::new(
&[Instruction::new(
&[Instruction::new_with_bincode(
mock_system_program_id,
&MockSystemInstruction::AttemptCredit { lamports: 50 },
account_metas.clone(),
@ -1757,7 +1761,7 @@ mod tests {
);
let message = Message::new(
&[Instruction::new(
&[Instruction::new_with_bincode(
mock_system_program_id,
&MockSystemInstruction::AttemptDataChange { data: 50 },
account_metas,
@ -1872,7 +1876,7 @@ mod tests {
// Try to borrow mut the same account
let message = Message::new(
&[Instruction::new(
&[Instruction::new_with_bincode(
mock_program_id,
&MockSystemInstruction::BorrowFail,
account_metas.clone(),
@ -1902,7 +1906,7 @@ mod tests {
// Try to borrow mut the same account in a safe way
let message = Message::new(
&[Instruction::new(
&[Instruction::new_with_bincode(
mock_program_id,
&MockSystemInstruction::MultiBorrowMut,
account_metas.clone(),
@ -1926,7 +1930,7 @@ mod tests {
// Do work on the same account but at different location in keyed_accounts[]
let message = Message::new(
&[Instruction::new(
&[Instruction::new_with_bincode(
mock_program_id,
&MockSystemInstruction::DoWork {
lamports: 10,
@ -2041,7 +2045,7 @@ mod tests {
// not owned account modified by the caller (before the invoke)
accounts[0].borrow_mut().data[0] = 1;
let instruction = Instruction::new(
let instruction = Instruction::new_with_bincode(
callee_program_id,
&MockInstruction::NoopSuccess,
metas.clone(),
@ -2079,7 +2083,8 @@ mod tests {
];
for case in cases {
let instruction = Instruction::new(callee_program_id, &case.0, metas.clone());
let instruction =
Instruction::new_with_bincode(callee_program_id, &case.0, metas.clone());
let message = Message::new(&[instruction], None);
let caller_privileges = message
.account_keys

View File

@ -1353,7 +1353,7 @@ mod tests {
AccountMeta::new(alice_pubkey, false),
AccountMeta::new(mallory_pubkey, true),
];
let malicious_instruction = Instruction::new(
let malicious_instruction = Instruction::new_with_bincode(
system_program::id(),
&SystemInstruction::Transfer { lamports: 10 },
account_metas,