Fixes test to work with session fixtures

Test were running fine standalone but failing / having Address reuse issues when running all together. Fixing that.
This commit is contained in:
Sergi Delgado Segura
2019-10-14 13:00:21 +01:00
parent e5ab943f8c
commit abe359f7d1
5 changed files with 11 additions and 84 deletions

View File

@@ -4,14 +4,12 @@ import pytest
import time
import requests
from hashlib import sha256
from threading import Thread
from binascii import unhexlify
from apps.cli.blob import Blob
from pisa.api import start_api
from pisa import HOST, PORT, logging
from pisa.utils.auth_proxy import AuthServiceProxy
from test.simulator.bitcoind_sim import run_simulator, TIME_BETWEEN_BLOCKS
from test.simulator.bitcoind_sim import TIME_BETWEEN_BLOCKS
from pisa.conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT, MAX_APPOINTMENTS
logging.getLogger().disabled = True
@@ -46,23 +44,6 @@ def generate_dummy_appointment(dispute_txid):
return appointment
@pytest.fixture(autouse=True, scope='session')
def run_api():
api_thread = Thread(target=start_api)
api_thread.daemon = True
api_thread.start()
# It takes a little bit of time to start the API (otherwise the requests are sent too early and they fail)
time.sleep(0.1)
@pytest.fixture(autouse=True, scope='session')
def run_bitcoind():
bitcoind_thread = Thread(target=run_simulator)
bitcoind_thread.daemon = True
bitcoind_thread.start()
@pytest.fixture
def new_appointment(dispute_txid=None):
appointment = create_appointment(dispute_txid)

View File

@@ -1,34 +1,21 @@
import pytest
from time import sleep
from os import urandom
from uuid import uuid4
from hashlib import sha256
from threading import Thread
from binascii import unhexlify
from pisa.block_processor import BlockProcessor
from test.simulator.bitcoind_sim import run_simulator
APPOINTMENT_COUNT = 100
TEST_SET_SIZE = 200
@pytest.fixture(autouse=True, scope='session')
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 API (otherwise the requests are sent too early and they fail)
sleep(0.1)
@pytest.fixture(scope='session')
@pytest.fixture(scope='module')
def txids():
return [urandom(32).hex() for _ in range(APPOINTMENT_COUNT)]
@pytest.fixture(scope='session')
@pytest.fixture(scope='module')
def locator_uuid_map(txids):
return {sha256(unhexlify(txid)).hexdigest(): uuid4().hex for txid in txids}

View File

@@ -1,11 +1,10 @@
import pytest
from os import urandom
from time import sleep
from threading import Thread
from pisa.carrier import Carrier
from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
from test.simulator.bitcoind_sim import run_simulator, TIME_BETWEEN_BLOCKS
from test.simulator.bitcoind_sim import TIME_BETWEEN_BLOCKS
# FIXME: This test do not fully cover the carrier since the simulator does not support every single error bitcoind may
# return for RPC_VERIFY_REJECTED and RPC_VERIFY_ERROR. Further development of the simulator / mocks or simulation
@@ -15,17 +14,7 @@ from test.simulator.bitcoind_sim import run_simulator, TIME_BETWEEN_BLOCKS
sent_txs = []
@pytest.fixture(autouse=True, scope='session')
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 API (otherwise the requests are sent too early and they fail)
sleep(0.1)
@pytest.fixture(scope='session')
@pytest.fixture(scope='module')
def carrier():
return Carrier()
@@ -45,7 +34,7 @@ def test_send_double_spending_transaction(carrier):
sent_txs.append(tx)
# Wait for a block to be mined
sleep(TIME_BETWEEN_BLOCKS)
sleep(2*TIME_BETWEEN_BLOCKS)
# Try to send it again
receipt2 = carrier.send_transaction(tx, tx)
@@ -53,7 +42,7 @@ def test_send_double_spending_transaction(carrier):
# The carrier should report delivered True for both, but in the second case the transaction was already delivered
# (either by himself or someone else)
assert(receipt.delivered is True)
assert (receipt2.delivered is True and receipt2.confirmations == 1
assert (receipt2.delivered is True and receipt2.confirmations >= 1
and receipt2.reason == RPC_VERIFY_ALREADY_IN_CHAIN)

View File

@@ -1,14 +1,10 @@
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()
@@ -21,16 +17,6 @@ WRONG_TYPES_NO_STR = [[], urandom(32), 3.2, 2.0, (), object, {}, object()]
logging.getLogger().disabled = True
@pytest.fixture(autouse=True, scope='session')
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
locator = urandom(32).hex()

View File

@@ -1,27 +1,11 @@
import pytest
from time import sleep
from multiprocessing import Process
from pisa import logging
from pisa import logging, bitcoin_cli
from pisa.tools import check_txid_format
from test.simulator.bitcoind_sim import run_simulator
from test.unit.conftest import bitcoind_process
from pisa.tools import can_connect_to_bitcoind, in_correct_network
logging.getLogger().disabled = True
@pytest.fixture(autouse=True, scope='session')
def run_bitcoind():
bitcoind_process = Process(target=run_simulator)
bitcoind_process.start()
# It takes a little bit of time to start the API (otherwise the requests are sent too early and they fail)
sleep(0.1)
return bitcoind_process
def test_in_correct_network():
# The simulator runs as if it was regtest, so every other network should fail
assert in_correct_network('mainnet') is False
@@ -33,9 +17,9 @@ def test_can_connect_to_bitcoind():
assert can_connect_to_bitcoind() is True
def test_can_connect_to_bitcoind_bitcoin_not_running(run_bitcoind):
def test_can_connect_to_bitcoind_bitcoin_not_running():
# Kill the simulator thread and test the check fails
run_bitcoind.kill()
bitcoind_process.kill()
assert can_connect_to_bitcoind() is False