Skip to content

Commit

Permalink
sdk: Add test to trigger KeypairPubkeyMismatch (solana-labs#18326)
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque authored Jun 30, 2021
1 parent 8d9a6de commit bb18ec8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sdk/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit bb18ec8

Please sign in to comment.