From 0f45e8fe11a1ca8446acbf1d2056f3a5dc5537db Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Tue, 21 Jan 2020 19:11:50 +0100 Subject: [PATCH] Adds methods to get seeded random values and fixes create_txs --- test/pisa/e2e/conftest.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/pisa/e2e/conftest.py b/test/pisa/e2e/conftest.py index 72e6194..9585756 100644 --- a/test/pisa/e2e/conftest.py +++ b/test/pisa/e2e/conftest.py @@ -1,4 +1,5 @@ import pytest +import random from decimal import Decimal, getcontext import pisa.conf as conf @@ -16,6 +17,17 @@ def bitcoin_cli(): ) +@pytest.fixture(scope="session", autouse=True) +def prng_seed(): + random.seed(0) + + +def get_random_value_hex(nbytes): + pseudo_random_value = random.getrandbits(8 * nbytes) + prv_hex = "{:x}".format(pseudo_random_value) + return prv_hex.zfill(2 * nbytes) + + @pytest.fixture() def create_txs(bitcoin_cli): set_up_node(bitcoin_cli) @@ -24,8 +36,12 @@ def create_txs(bitcoin_cli): if len(utxos) == 0: raise ValueError("There're no UTXOs.") - commitment_tx_ins = {"txid": utxos[0].get("txid"), "vout": utxos[0].get("vout")} - commitment_tx_outs = {utxos[0].get("address"): utxos[0].get("amount") - Decimal(1 / pow(10, 5))} + utxo = utxos.pop(0) + while utxo.get("amount") < Decimal(2 / pow(10, 5)): + utxo = utxos.pop(0) + + commitment_tx_ins = {"txid": utxo.get("txid"), "vout": utxo.get("vout")} + commitment_tx_outs = {utxo.get("address"): utxo.get("amount") - Decimal(1 / pow(10, 5))} raw_commitment_tx = bitcoin_cli.createrawtransaction([commitment_tx_ins], commitment_tx_outs) signed_commitment_tx = bitcoin_cli.signrawtransactionwithwallet(raw_commitment_tx) @@ -61,8 +77,7 @@ def set_up_node(bitcoin_cli): bitcoin_cli.generatetoaddress(101, new_addr) -def build_appointment_data(bitcoin_cli, commitment_tx, penalty_tx): - commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid") +def build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx): current_height = bitcoin_cli.getblockcount() appointment_data = {