Adds methods to get seeded random values and fixes create_txs

This commit is contained in:
Sergi Delgado Segura
2020-01-21 19:11:50 +01:00
parent 7bf65c40f5
commit 0f45e8fe11

View File

@@ -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 = {