From 9a18f759f94e64bca72a2980f035bc7ff5798b12 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Tue, 8 Oct 2019 18:56:45 +0100 Subject: [PATCH] Adds run_bitcoind fixture --- test/unit/test_inspector.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/test/unit/test_inspector.py b/test/unit/test_inspector.py index 8e777d7..1a1eb78 100644 --- a/test/unit/test_inspector.py +++ b/test/unit/test_inspector.py @@ -1,10 +1,14 @@ +import time +import pytest from os import urandom +from threading import Thread from pisa import logging from pisa.errors import * from pisa.inspector import Inspector from pisa.appointment import Appointment from pisa.block_processor import BlockProcessor +from test.simulator.bitcoind_sim import run_simulator from pisa.conf import MIN_DISPUTE_DELTA, SUPPORTED_CIPHERS, SUPPORTED_HASH_FUNCTIONS inspector = Inspector() @@ -14,6 +18,18 @@ NO_HEX_STINGS = ["R" * 64, urandom(31).hex() + "PP", "$"*64, " "*64] WRONG_TYPES = [[], '', urandom(32).hex(), 3.2, 2.0, (), object, {}, " "*32, object()] WRONG_TYPES_NO_STR = [[], urandom(32), 3.2, 2.0, (), object, {}, object()] +logging.getLogger().disabled = True + + +@pytest.fixture(autouse=True) +def run_bitcoind(): + bitcoind_thread = Thread(target=run_simulator) + bitcoind_thread.daemon = True + bitcoind_thread.start() + + # It takes a little bit of time to start the simulator (otherwise the requests are sent too early and they fail) + time.sleep(0.1) + def test_check_locator(): # Right appointment type, size and format @@ -187,8 +203,6 @@ def test_check_hash_function(): def test_inspect(): - # Running this required bitcoind to be running (or mocked) since the block height is queried by inspect. - # At this point every single check function has been already tested, let's test inspect with an invalid and a valid # appointments. @@ -217,14 +231,3 @@ def test_inspect(): appointment.encrypted_blob.data == encrypted_blob and appointment.cipher == cipher and appointment.hash_function == hash_function) - -logging.getLogger().disabled = True - -test_check_locator() -test_check_start_time() -test_check_end_time() -test_check_delta() -test_check_blob() -test_check_cipher() -test_check_hash_function() -test_inspect()