Skip to content

Commit

Permalink
Make random appointments variable in size
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Aug 30, 2023
1 parent ae91b73 commit 83614ec
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions teos-common/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
rand::thread_rng().gen_range(1..=80),
)),
});

let mut raw_locator: [u8; 16] = cryptography::get_random_bytes(16).try_into().unwrap();
raw_locator.copy_from_slice(&dispute_txid[..16]);
Expand Down

0 comments on commit 83614ec

Please sign in to comment.