Make it unappealing to build and sign transactions at the same time
Use a client to sign transactions. It'll need that keypair anyway to resign new blockhashes on retries.
This commit is contained in:
@ -641,4 +641,49 @@ mod tests {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_transaction_missing_key() {
|
||||
let keypair = Keypair::new();
|
||||
TransactionBuilder::default()
|
||||
.compile()
|
||||
.sign(&[&keypair], Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_transaction_missing_keypair() {
|
||||
let program_id = Pubkey::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let id0 = keypair0.pubkey();
|
||||
TransactionBuilder::default()
|
||||
.push(Instruction::new(program_id, &0, vec![(id0, true)]))
|
||||
.compile()
|
||||
.sign(&Vec::<&Keypair>::new(), Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_transaction_wrong_key() {
|
||||
let program_id = Pubkey::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let wrong_id = Pubkey::default();
|
||||
TransactionBuilder::default()
|
||||
.push(Instruction::new(program_id, &0, vec![(wrong_id, true)]))
|
||||
.compile()
|
||||
.sign(&[&keypair0], Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_correct_key() {
|
||||
let program_id = Pubkey::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let id0 = keypair0.pubkey();
|
||||
let mut tx = TransactionBuilder::default()
|
||||
.push(Instruction::new(program_id, &0, vec![(id0, true)]))
|
||||
.compile();
|
||||
tx.sign(&[&keypair0], Hash::default());
|
||||
assert_eq!(tx.instructions[0], Instruction::new(0, &0, vec![0]));
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use crate::hash::Hash;
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::signature::KeypairUtil;
|
||||
use crate::transaction::{Instruction, Transaction};
|
||||
use itertools::Itertools;
|
||||
|
||||
@ -104,13 +103,6 @@ impl TransactionBuilder {
|
||||
instructions,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a signed transaction.
|
||||
pub fn sign<T: KeypairUtil>(&self, keypairs: &[&T], recent_blockhash: Hash) -> Transaction {
|
||||
let mut tx = self.compile();
|
||||
tx.sign(keypairs, recent_blockhash);
|
||||
tx
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -227,50 +219,9 @@ mod tests {
|
||||
assert_eq!(tx.signatures.capacity(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_transaction_builder_missing_key() {
|
||||
let keypair = Keypair::new();
|
||||
TransactionBuilder::default().sign(&[&keypair], Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_transaction_builder_missing_keypair() {
|
||||
let program_id = Pubkey::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let id0 = keypair0.pubkey();
|
||||
TransactionBuilder::default()
|
||||
.push(Instruction::new(program_id, &0, vec![(id0, true)]))
|
||||
.sign(&Vec::<&Keypair>::new(), Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_transaction_builder_wrong_key() {
|
||||
let program_id = Pubkey::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let wrong_id = Pubkey::default();
|
||||
TransactionBuilder::default()
|
||||
.push(Instruction::new(program_id, &0, vec![(wrong_id, true)]))
|
||||
.sign(&[&keypair0], Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_builder_correct_key() {
|
||||
let program_id = Pubkey::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let id0 = keypair0.pubkey();
|
||||
let tx = TransactionBuilder::default()
|
||||
.push(Instruction::new(program_id, &0, vec![(id0, true)]))
|
||||
.sign(&[&keypair0], Hash::default());
|
||||
assert_eq!(tx.instructions[0], Instruction::new(0, &0, vec![0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_builder_fee() {
|
||||
let tx = TransactionBuilder::new(42).sign(&Vec::<&Keypair>::new(), Hash::default());
|
||||
assert_eq!(tx.fee, 42);
|
||||
assert_eq!(TransactionBuilder::new(42).compile().fee, 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -284,7 +235,7 @@ mod tests {
|
||||
.push(Instruction::new(program_id0, &0, vec![(id0, false)]))
|
||||
.push(Instruction::new(program_id1, &0, vec![(id1, true)]))
|
||||
.push(Instruction::new(program_id0, &0, vec![(id1, false)]))
|
||||
.sign(&[&keypair1], Hash::default());
|
||||
.compile();
|
||||
assert_eq!(tx.instructions[0], Instruction::new(0, &0, vec![1]));
|
||||
assert_eq!(tx.instructions[1], Instruction::new(1, &0, vec![0]));
|
||||
assert_eq!(tx.instructions[2], Instruction::new(0, &0, vec![0]));
|
||||
|
Reference in New Issue
Block a user