sdk: Add test to trigger KeypairPubkeyMismatch (#18326)

This commit is contained in:
Jon Cinque 2021-06-30 20:27:13 +02:00 committed by GitHub
parent 8d9a6deda4
commit bb18ec8893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -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);
}
}