From bb18ec8893b34d7e7730094e157791f3195c537a Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Wed, 30 Jun 2021 20:27:13 +0200 Subject: [PATCH] sdk: Add test to trigger KeypairPubkeyMismatch (#18326) --- sdk/src/transaction.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 104de0eb7a..2125043ee5 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -990,4 +990,18 @@ mod tests { nonce_ix.accounts[0] = 255u8; assert_eq!(get_nonce_pubkey_from_instruction(&nonce_ix, &tx), None,); } + + #[test] + fn tx_keypair_pubkey_mismatch() { + let from_keypair = Keypair::new(); + let from_pubkey = from_keypair.pubkey(); + let to_pubkey = Pubkey::new_unique(); + let instructions = [system_instruction::transfer(&from_pubkey, &to_pubkey, 42)]; + let mut tx = Transaction::new_with_payer(&instructions, Some(&from_pubkey)); + let unused_keypair = Keypair::new(); + let err = tx + .try_partial_sign(&[&from_keypair, &unused_keypair], Hash::default()) + .unwrap_err(); + assert_eq!(err, SignerError::KeypairPubkeyMismatch); + } }