Use Option<[u8; N]> for JoinSplit pubkey and signature in a transaction

This commit is contained in:
Jack Grigg
2018-11-30 01:08:45 +00:00
parent 9b06205ed6
commit d707ebd321
3 changed files with 88 additions and 14 deletions
+40
View File
@@ -156,6 +156,46 @@ fn tx_read_write() {
assert_eq!(&data[..], &encoded[..]);
}
#[test]
fn tx_write_rejects_unexpected_joinsplit_pubkey() {
// Succeeds without a JoinSplit pubkey
{
let tx = TransactionData::new().freeze();
let mut encoded = Vec::new();
assert!(tx.write(&mut encoded).is_ok());
}
// Fails with an unexpected JoinSplit pubkey
{
let mut tx = TransactionData::new();
tx.joinsplit_pubkey = Some([0; 32]);
let tx = tx.freeze();
let mut encoded = Vec::new();
assert!(tx.write(&mut encoded).is_err());
}
}
#[test]
fn tx_write_rejects_unexpected_joinsplit_sig() {
// Succeeds without a JoinSplit signature
{
let tx = TransactionData::new().freeze();
let mut encoded = Vec::new();
assert!(tx.write(&mut encoded).is_ok());
}
// Fails with an unexpected JoinSplit signature
{
let mut tx = TransactionData::new();
tx.joinsplit_sig = Some([0; 64]);
let tx = tx.freeze();
let mut encoded = Vec::new();
assert!(tx.write(&mut encoded).is_err());
}
}
#[test]
fn tx_write_rejects_unexpected_binding_sig() {
// Succeeds without a binding signature