Adds tests for check_tx_in_chain

This commit is contained in:
Sergi Delgado Segura
2019-11-20 13:01:56 +00:00
parent 05961f1632
commit 3dad5b7c71

View File

@@ -4,7 +4,7 @@ from pisa import c_logger
from pisa.carrier import Carrier
from test.simulator.utils import sha256d
from test.simulator.transaction import TX
from test.unit.conftest import generate_blocks, get_random_value_hex
from test.unit.conftest import generate_blocks, generate_block, get_random_value_hex
from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
c_logger.disabled = True
@@ -72,3 +72,24 @@ def test_get_non_existing_transaction():
tx_info = Carrier.get_transaction(get_random_value_hex(32))
assert tx_info is None
def test_check_tx_in_chain(carrier):
# Let's starts by looking for a random transaction
random_tx = TX.create_dummy_transaction()
random_txid = sha256d(random_tx)
tx_in_chain, confirmations = carrier.check_tx_in_chain(random_txid)
assert tx_in_chain is False and confirmations is None
# We can now broadcast the transaction and check again
carrier.send_transaction(random_tx, random_txid)
tx_in_chain, confirmations = carrier.check_tx_in_chain(random_txid)
# The tx should be on mempool now, so same
assert tx_in_chain is False and confirmations is None
# Finally we can mine a block and check again
generate_block()
tx_in_chain, confirmations = carrier.check_tx_in_chain(random_txid)
assert tx_in_chain is True and confirmations == 1