diff --git a/test/unit/conftest.py b/test/unit/conftest.py index 2c0bdea..e337de9 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -32,3 +32,8 @@ def generate_block(): sleep(0.5) +def generate_blocks(n): + for _ in range(n): + generate_block() + + diff --git a/test/unit/test_carrier.py b/test/unit/test_carrier.py index d73c749..6671283 100644 --- a/test/unit/test_carrier.py +++ b/test/unit/test_carrier.py @@ -6,7 +6,7 @@ from os import urandom from pisa.carrier import Carrier from test.simulator.utils import sha256d from test.simulator.transaction import TX -from test.unit.conftest import generate_block +from test.unit.conftest import generate_blocks from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR logging.getLogger().disabled = True @@ -43,8 +43,7 @@ def test_send_double_spending_transaction(carrier): sent_txs.append(txid) # Wait for a block to be mined - for _ in range(2): - generate_block() + generate_blocks(2) # Try to send it again receipt2 = carrier.send_transaction(tx, txid) diff --git a/test/unit/test_watcher.py b/test/unit/test_watcher.py index 90c2ae7..6997a99 100644 --- a/test/unit/test_watcher.py +++ b/test/unit/test_watcher.py @@ -14,8 +14,8 @@ from pisa.appointment import Appointment from pisa.tools import check_txid_format from test.simulator.utils import sha256d from test.simulator.transaction import TX -from test.unit.conftest import generate_block from pisa.utils.auth_proxy import AuthServiceProxy +from test.unit.conftest import generate_block, generate_blocks from pisa.conf import EXPIRY_DELTA, BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT logging.getLogger().disabled = True @@ -137,20 +137,17 @@ def test_do_watch(watcher): # Broadcast the first two for dispute_tx in dispute_txs[:2]: - r = bitcoin_cli.sendrawtransaction(dispute_tx) + bitcoin_cli.sendrawtransaction(dispute_tx) # After leaving some time for the block to be mined and processed, the number of appointments should have reduced # by two - for _ in range(START_TIME_OFFSET + END_TIME_OFFSET): - generate_block() + generate_blocks(START_TIME_OFFSET + END_TIME_OFFSET) assert len(watcher.appointments) == APPOINTMENTS - 2 # The rest of appointments will timeout after the end (2) + EXPIRY_DELTA # Wait for an additional block to be safe - - for _ in range(EXPIRY_DELTA + START_TIME_OFFSET + END_TIME_OFFSET): - generate_block() + generate_blocks(EXPIRY_DELTA + START_TIME_OFFSET + END_TIME_OFFSET) assert len(watcher.appointments) == 0 assert watcher.asleep is True