Adds generate_blocks

This commit is contained in:
Sergi Delgado Segura
2019-10-21 18:12:05 +01:00
parent 71ce7c46ec
commit 94156a67cc
3 changed files with 11 additions and 10 deletions

View File

@@ -32,3 +32,8 @@ def generate_block():
sleep(0.5) sleep(0.5)
def generate_blocks(n):
for _ in range(n):
generate_block()

View File

@@ -6,7 +6,7 @@ from os import urandom
from pisa.carrier import Carrier from pisa.carrier import Carrier
from test.simulator.utils import sha256d from test.simulator.utils import sha256d
from test.simulator.transaction import TX 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 from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
logging.getLogger().disabled = True logging.getLogger().disabled = True
@@ -43,8 +43,7 @@ def test_send_double_spending_transaction(carrier):
sent_txs.append(txid) sent_txs.append(txid)
# Wait for a block to be mined # Wait for a block to be mined
for _ in range(2): generate_blocks(2)
generate_block()
# Try to send it again # Try to send it again
receipt2 = carrier.send_transaction(tx, txid) receipt2 = carrier.send_transaction(tx, txid)

View File

@@ -14,8 +14,8 @@ from pisa.appointment import Appointment
from pisa.tools import check_txid_format from pisa.tools import check_txid_format
from test.simulator.utils import sha256d from test.simulator.utils import sha256d
from test.simulator.transaction import TX from test.simulator.transaction import TX
from test.unit.conftest import generate_block
from pisa.utils.auth_proxy import AuthServiceProxy 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 from pisa.conf import EXPIRY_DELTA, BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT
logging.getLogger().disabled = True logging.getLogger().disabled = True
@@ -137,20 +137,17 @@ def test_do_watch(watcher):
# Broadcast the first two # Broadcast the first two
for dispute_tx in dispute_txs[:2]: 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 # After leaving some time for the block to be mined and processed, the number of appointments should have reduced
# by two # by two
for _ in range(START_TIME_OFFSET + END_TIME_OFFSET): generate_blocks(START_TIME_OFFSET + END_TIME_OFFSET)
generate_block()
assert len(watcher.appointments) == APPOINTMENTS - 2 assert len(watcher.appointments) == APPOINTMENTS - 2
# The rest of appointments will timeout after the end (2) + EXPIRY_DELTA # The rest of appointments will timeout after the end (2) + EXPIRY_DELTA
# Wait for an additional block to be safe # Wait for an additional block to be safe
generate_blocks(EXPIRY_DELTA + START_TIME_OFFSET + END_TIME_OFFSET)
for _ in range(EXPIRY_DELTA + START_TIME_OFFSET + END_TIME_OFFSET):
generate_block()
assert len(watcher.appointments) == 0 assert len(watcher.appointments) == 0
assert watcher.asleep is True assert watcher.asleep is True