mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Updates tests to work with new version of bitcoind_mock
This commit is contained in:
@@ -18,8 +18,7 @@ from pisa.chain_monitor import ChainMonitor
|
|||||||
from common.appointment import Appointment
|
from common.appointment import Appointment
|
||||||
from common.tools import compute_locator
|
from common.tools import compute_locator
|
||||||
|
|
||||||
from bitcoind_mock.utils import sha256d
|
from bitcoind_mock.transaction import create_dummy_transaction
|
||||||
from bitcoind_mock.transaction import TX
|
|
||||||
from bitcoind_mock.bitcoind import BitcoindMock
|
from bitcoind_mock.bitcoind import BitcoindMock
|
||||||
from bitcoind_mock.conf import BTC_RPC_HOST, BTC_RPC_PORT
|
from bitcoind_mock.conf import BTC_RPC_HOST, BTC_RPC_PORT
|
||||||
|
|
||||||
@@ -97,12 +96,12 @@ def generate_dummy_appointment_data(real_height=True, start_time_offset=5, end_t
|
|||||||
else:
|
else:
|
||||||
current_height = 10
|
current_height = 10
|
||||||
|
|
||||||
dispute_tx = TX.create_dummy_transaction()
|
dispute_tx = create_dummy_transaction()
|
||||||
dispute_txid = sha256d(dispute_tx)
|
dispute_txid = dispute_tx.tx_id.hex()
|
||||||
penalty_tx = TX.create_dummy_transaction(dispute_txid)
|
penalty_tx = create_dummy_transaction(dispute_txid)
|
||||||
|
|
||||||
dummy_appointment_data = {
|
dummy_appointment_data = {
|
||||||
"tx": penalty_tx,
|
"tx": penalty_tx.hex(),
|
||||||
"tx_id": dispute_txid,
|
"tx_id": dispute_txid,
|
||||||
"start_time": current_height + start_time_offset,
|
"start_time": current_height + start_time_offset,
|
||||||
"end_time": current_height + end_time_offset,
|
"end_time": current_height + end_time_offset,
|
||||||
@@ -133,7 +132,7 @@ def generate_dummy_appointment_data(real_height=True, start_time_offset=5, end_t
|
|||||||
|
|
||||||
data = {"appointment": appointment_data, "signature": signature, "public_key": pk_hex}
|
data = {"appointment": appointment_data, "signature": signature, "public_key": pk_hex}
|
||||||
|
|
||||||
return data, dispute_tx
|
return data, dispute_tx.hex()
|
||||||
|
|
||||||
|
|
||||||
def generate_dummy_appointment(real_height=True, start_time_offset=5, end_time_offset=30):
|
def generate_dummy_appointment(real_height=True, start_time_offset=5, end_time_offset=30):
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pisa.carrier import Carrier
|
from pisa.carrier import Carrier
|
||||||
from bitcoind_mock.utils import sha256d
|
from bitcoind_mock.transaction import create_dummy_transaction
|
||||||
from bitcoind_mock.transaction import TX
|
|
||||||
from test.pisa.unit.conftest import generate_blocks, get_random_value_hex
|
from test.pisa.unit.conftest import generate_blocks, get_random_value_hex
|
||||||
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
|
||||||
|
|
||||||
@@ -21,27 +20,26 @@ def carrier():
|
|||||||
|
|
||||||
|
|
||||||
def test_send_transaction(run_bitcoind, carrier):
|
def test_send_transaction(run_bitcoind, carrier):
|
||||||
tx = TX.create_dummy_transaction()
|
tx = create_dummy_transaction()
|
||||||
txid = sha256d(tx)
|
|
||||||
|
|
||||||
receipt = carrier.send_transaction(tx, txid)
|
receipt = carrier.send_transaction(tx.hex(), tx.tx_id.hex())
|
||||||
|
|
||||||
assert receipt.delivered is True
|
assert receipt.delivered is True
|
||||||
|
|
||||||
|
|
||||||
def test_send_double_spending_transaction(carrier):
|
def test_send_double_spending_transaction(carrier):
|
||||||
# We can test what happens if the same transaction is sent twice
|
# We can test what happens if the same transaction is sent twice
|
||||||
tx = TX.create_dummy_transaction()
|
tx = create_dummy_transaction()
|
||||||
txid = sha256d(tx)
|
txid = tx.tx_id.hex()
|
||||||
|
|
||||||
receipt = carrier.send_transaction(tx, txid)
|
receipt = carrier.send_transaction(tx.hex(), txid)
|
||||||
sent_txs.append(txid)
|
sent_txs.append(txid)
|
||||||
|
|
||||||
# Wait for a block to be mined
|
# Wait for a block to be mined
|
||||||
generate_blocks(2)
|
generate_blocks(2)
|
||||||
|
|
||||||
# Try to send it again
|
# Try to send it again
|
||||||
receipt2 = carrier.send_transaction(tx, txid)
|
receipt2 = carrier.send_transaction(tx.hex(), txid)
|
||||||
|
|
||||||
# The carrier should report delivered True for both, but in the second case the transaction was already delivered
|
# The carrier should report delivered True for both, but in the second case the transaction was already delivered
|
||||||
# (either by himself or someone else)
|
# (either by himself or someone else)
|
||||||
@@ -51,8 +49,7 @@ def test_send_double_spending_transaction(carrier):
|
|||||||
|
|
||||||
def test_send_transaction_invalid_format(carrier):
|
def test_send_transaction_invalid_format(carrier):
|
||||||
# Test sending a transaction that does not fits the format
|
# Test sending a transaction that does not fits the format
|
||||||
tx = TX.create_dummy_transaction()
|
txid = create_dummy_transaction().tx_id.hex()
|
||||||
txid = sha256d(tx)
|
|
||||||
receipt = carrier.send_transaction(txid, txid)
|
receipt = carrier.send_transaction(txid, txid)
|
||||||
|
|
||||||
assert receipt.delivered is False and receipt.reason == RPC_DESERIALIZATION_ERROR
|
assert receipt.delivered is False and receipt.reason == RPC_DESERIALIZATION_ERROR
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ from pisa.chain_monitor import ChainMonitor
|
|||||||
from pisa.tools import bitcoin_cli
|
from pisa.tools import bitcoin_cli
|
||||||
|
|
||||||
from common.constants import LOCATOR_LEN_HEX
|
from common.constants import LOCATOR_LEN_HEX
|
||||||
|
from bitcoind_mock.transaction import create_dummy_transaction, create_tx_from_hex
|
||||||
from bitcoind_mock.utils import sha256d
|
|
||||||
from bitcoind_mock.transaction import TX
|
|
||||||
from test.pisa.unit.conftest import generate_block, generate_blocks, get_random_value_hex
|
from test.pisa.unit.conftest import generate_block, generate_blocks, get_random_value_hex
|
||||||
|
|
||||||
|
|
||||||
@@ -55,7 +53,7 @@ def create_dummy_tracker_data(random_txid=False, penalty_rawtx=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
penalty_txid = sha256d(penalty_rawtx)
|
penalty_txid = create_tx_from_hex(penalty_rawtx).tx_id.hex()
|
||||||
|
|
||||||
if random_txid is True:
|
if random_txid is True:
|
||||||
penalty_txid = get_random_value_hex(32)
|
penalty_txid = get_random_value_hex(32)
|
||||||
@@ -270,7 +268,7 @@ def test_add_tracker_already_confirmed(responder):
|
|||||||
uuid = uuid4().hex
|
uuid = uuid4().hex
|
||||||
confirmations = i + 1
|
confirmations = i + 1
|
||||||
locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end = create_dummy_tracker_data(
|
locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end = create_dummy_tracker_data(
|
||||||
penalty_rawtx=TX.create_dummy_transaction()
|
penalty_rawtx=create_dummy_transaction().hex()
|
||||||
)
|
)
|
||||||
|
|
||||||
responder.add_tracker(uuid, locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end, confirmations)
|
responder.add_tracker(uuid, locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end, confirmations)
|
||||||
@@ -283,7 +281,7 @@ def test_do_watch(temp_db_manager, chain_monitor):
|
|||||||
responder = Responder(temp_db_manager, chain_monitor)
|
responder = Responder(temp_db_manager, chain_monitor)
|
||||||
chain_monitor.attach_responder(responder.block_queue, False)
|
chain_monitor.attach_responder(responder.block_queue, False)
|
||||||
|
|
||||||
trackers = [create_dummy_tracker(penalty_rawtx=TX.create_dummy_transaction()) for _ in range(20)]
|
trackers = [create_dummy_tracker(penalty_rawtx=create_dummy_transaction().hex()) for _ in range(20)]
|
||||||
|
|
||||||
# Let's set up the trackers first
|
# Let's set up the trackers first
|
||||||
for tracker in trackers:
|
for tracker in trackers:
|
||||||
@@ -402,18 +400,18 @@ def test_get_completed_trackers(db_manager, chain_monitor):
|
|||||||
# A complete tracker is a tracker that has reached the appointment end with enough confs (> MIN_CONFIRMATIONS)
|
# A complete tracker is a tracker that has reached the appointment end with enough confs (> MIN_CONFIRMATIONS)
|
||||||
# We'll create three type of transactions: end reached + enough conf, end reached + no enough conf, end not reached
|
# We'll create three type of transactions: end reached + enough conf, end reached + no enough conf, end not reached
|
||||||
trackers_end_conf = {
|
trackers_end_conf = {
|
||||||
uuid4().hex: create_dummy_tracker(penalty_rawtx=TX.create_dummy_transaction()) for _ in range(10)
|
uuid4().hex: create_dummy_tracker(penalty_rawtx=create_dummy_transaction().hex()) for _ in range(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
trackers_end_no_conf = {}
|
trackers_end_no_conf = {}
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
tracker = create_dummy_tracker(penalty_rawtx=TX.create_dummy_transaction())
|
tracker = create_dummy_tracker(penalty_rawtx=create_dummy_transaction().hex())
|
||||||
responder.unconfirmed_txs.append(tracker.penalty_txid)
|
responder.unconfirmed_txs.append(tracker.penalty_txid)
|
||||||
trackers_end_no_conf[uuid4().hex] = tracker
|
trackers_end_no_conf[uuid4().hex] = tracker
|
||||||
|
|
||||||
trackers_no_end = {}
|
trackers_no_end = {}
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
tracker = create_dummy_tracker(penalty_rawtx=TX.create_dummy_transaction())
|
tracker = create_dummy_tracker(penalty_rawtx=create_dummy_transaction().hex())
|
||||||
tracker.appointment_end += 10
|
tracker.appointment_end += 10
|
||||||
trackers_no_end[uuid4().hex] = tracker
|
trackers_no_end[uuid4().hex] = tracker
|
||||||
|
|
||||||
@@ -463,7 +461,7 @@ def test_rebroadcast(db_manager, chain_monitor):
|
|||||||
for i in range(20):
|
for i in range(20):
|
||||||
uuid = uuid4().hex
|
uuid = uuid4().hex
|
||||||
locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end = create_dummy_tracker_data(
|
locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end = create_dummy_tracker_data(
|
||||||
penalty_rawtx=TX.create_dummy_transaction()
|
penalty_rawtx=create_dummy_transaction().hex()
|
||||||
)
|
)
|
||||||
|
|
||||||
tracker = TransactionTracker(locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end)
|
tracker = TransactionTracker(locator, dispute_txid, penalty_txid, penalty_rawtx, appointment_end)
|
||||||
|
|||||||
Reference in New Issue
Block a user