From 1790fe31e0b651c0a1dce23d8ff7ba474cc42c49 Mon Sep 17 00:00:00 2001 From: Omer Yacine Date: Wed, 30 Aug 2023 17:13:48 +0300 Subject: [PATCH] Make random appointments variable in size --- teos-common/src/test_utils.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/teos-common/src/test_utils.rs b/teos-common/src/test_utils.rs index dd0a3336..0b5a95b2 100644 --- a/teos-common/src/test_utils.rs +++ b/teos-common/src/test_utils.rs @@ -5,10 +5,9 @@ use rand::distributions::Standard; use rand::prelude::Distribution; use rand::Rng; -use bitcoin::consensus; use bitcoin::hashes::Hash; use bitcoin::secp256k1::SecretKey; -use bitcoin::Txid; +use bitcoin::{consensus, Script, Transaction, TxOut, Txid}; use crate::appointment::{Appointment, Locator}; use crate::cryptography; @@ -48,7 +47,15 @@ pub fn generate_random_appointment(dispute_txid: Option<&Txid>) -> Appointment { }; let tx_bytes = Vec::from_hex(TX_HEX).unwrap(); - let penalty_tx = consensus::deserialize(&tx_bytes).unwrap(); + let mut penalty_tx: Transaction = consensus::deserialize(&tx_bytes).unwrap(); + + // Append a random-sized OP_RETURN to make each transcation random in size. + penalty_tx.output.push(TxOut { + value: 0, + script_pubkey: Script::new_op_return(&cryptography::get_random_bytes( + get_random_int::() % 81, + )), + }); let mut raw_locator: [u8; 16] = cryptography::get_random_bytes(16).try_into().unwrap(); raw_locator.copy_from_slice(&dispute_txid[..16]);