From 3d4ed28c8bc6decd8b0481a2e96fe5e4401151ad Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 15 Jan 2020 15:41:57 +0100 Subject: [PATCH 1/6] Fixes wrong log messase --- apps/cli/blob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/cli/blob.py b/apps/cli/blob.py index d5c7c14..cd3ed23 100644 --- a/apps/cli/blob.py +++ b/apps/cli/blob.py @@ -4,6 +4,6 @@ import re class Blob: def __init__(self, data): if type(data) is not str or re.search(r"^[0-9A-Fa-f]+$", data) is None: - raise ValueError("Non-Hex character found in txid.") + raise ValueError("Non-Hex character found in transaction.") self.data = data From fb8c6c80d35cedb46bdb160fac413ea623478c14 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 15 Jan 2020 15:43:00 +0100 Subject: [PATCH 2/6] Updates tests to work with new version of bitcoind_mock --- test/pisa/unit/conftest.py | 13 ++++++------- test/pisa/unit/test_carrier.py | 19 ++++++++----------- test/pisa/unit/test_responder.py | 18 ++++++++---------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/test/pisa/unit/conftest.py b/test/pisa/unit/conftest.py index ff79fee..e70d2c7 100644 --- a/test/pisa/unit/conftest.py +++ b/test/pisa/unit/conftest.py @@ -18,8 +18,7 @@ from pisa.chain_monitor import ChainMonitor from common.appointment import Appointment from common.tools import compute_locator -from bitcoind_mock.utils import sha256d -from bitcoind_mock.transaction import TX +from bitcoind_mock.transaction import create_dummy_transaction from bitcoind_mock.bitcoind import BitcoindMock 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: current_height = 10 - dispute_tx = TX.create_dummy_transaction() - dispute_txid = sha256d(dispute_tx) - penalty_tx = TX.create_dummy_transaction(dispute_txid) + dispute_tx = create_dummy_transaction() + dispute_txid = dispute_tx.tx_id.hex() + penalty_tx = create_dummy_transaction(dispute_txid) dummy_appointment_data = { - "tx": penalty_tx, + "tx": penalty_tx.hex(), "tx_id": dispute_txid, "start_time": current_height + start_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} - return data, dispute_tx + return data, dispute_tx.hex() def generate_dummy_appointment(real_height=True, start_time_offset=5, end_time_offset=30): diff --git a/test/pisa/unit/test_carrier.py b/test/pisa/unit/test_carrier.py index a44c806..fe9540a 100644 --- a/test/pisa/unit/test_carrier.py +++ b/test/pisa/unit/test_carrier.py @@ -1,8 +1,7 @@ import pytest from pisa.carrier import Carrier -from bitcoind_mock.utils import sha256d -from bitcoind_mock.transaction import TX +from bitcoind_mock.transaction import create_dummy_transaction 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 @@ -21,27 +20,26 @@ def carrier(): def test_send_transaction(run_bitcoind, carrier): - tx = TX.create_dummy_transaction() - txid = sha256d(tx) + tx = create_dummy_transaction() - receipt = carrier.send_transaction(tx, txid) + receipt = carrier.send_transaction(tx.hex(), tx.tx_id.hex()) assert receipt.delivered is True def test_send_double_spending_transaction(carrier): # We can test what happens if the same transaction is sent twice - tx = TX.create_dummy_transaction() - txid = sha256d(tx) + tx = create_dummy_transaction() + txid = tx.tx_id.hex() - receipt = carrier.send_transaction(tx, txid) + receipt = carrier.send_transaction(tx.hex(), txid) sent_txs.append(txid) # Wait for a block to be mined generate_blocks(2) # 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 # (either by himself or someone else) @@ -51,8 +49,7 @@ def test_send_double_spending_transaction(carrier): def test_send_transaction_invalid_format(carrier): # Test sending a transaction that does not fits the format - tx = TX.create_dummy_transaction() - txid = sha256d(tx) + txid = create_dummy_transaction().tx_id.hex() receipt = carrier.send_transaction(txid, txid) assert receipt.delivered is False and receipt.reason == RPC_DESERIALIZATION_ERROR diff --git a/test/pisa/unit/test_responder.py b/test/pisa/unit/test_responder.py index f4704fd..f646186 100644 --- a/test/pisa/unit/test_responder.py +++ b/test/pisa/unit/test_responder.py @@ -13,9 +13,7 @@ from pisa.chain_monitor import ChainMonitor from pisa.tools import bitcoin_cli from common.constants import LOCATOR_LEN_HEX - -from bitcoind_mock.utils import sha256d -from bitcoind_mock.transaction import TX +from bitcoind_mock.transaction import create_dummy_transaction, create_tx_from_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: - penalty_txid = sha256d(penalty_rawtx) + penalty_txid = create_tx_from_hex(penalty_rawtx).tx_id.hex() if random_txid is True: penalty_txid = get_random_value_hex(32) @@ -270,7 +268,7 @@ def test_add_tracker_already_confirmed(responder): uuid = uuid4().hex confirmations = i + 1 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) @@ -283,7 +281,7 @@ def test_do_watch(temp_db_manager, chain_monitor): responder = Responder(temp_db_manager, chain_monitor) 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 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) # We'll create three type of transactions: end reached + enough conf, end reached + no enough conf, end not reached 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 = {} 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) trackers_end_no_conf[uuid4().hex] = tracker trackers_no_end = {} 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 trackers_no_end[uuid4().hex] = tracker @@ -463,7 +461,7 @@ def test_rebroadcast(db_manager, chain_monitor): for i in range(20): uuid = uuid4().hex 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) From 0ddace6256c1ed5cde046cfe00f5faab1b735fc4 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 15 Jan 2020 15:48:30 +0100 Subject: [PATCH 3/6] Updates requirements and adds dev requirements --- pisa/requirements-dev.txt | 3 +++ pisa/requirements.txt | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 pisa/requirements-dev.txt diff --git a/pisa/requirements-dev.txt b/pisa/requirements-dev.txt new file mode 100644 index 0000000..b18071f --- /dev/null +++ b/pisa/requirements-dev.txt @@ -0,0 +1,3 @@ +pytest +black +bitcoind_mock \ No newline at end of file diff --git a/pisa/requirements.txt b/pisa/requirements.txt index 024cf09..688603f 100644 --- a/pisa/requirements.txt +++ b/pisa/requirements.txt @@ -2,5 +2,4 @@ zmq flask cryptography requests -plyvel -pytest \ No newline at end of file +plyvel \ No newline at end of file From ce2cc81d8ba13e8512e89623813a9c54a2594e45 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 15 Jan 2020 16:05:55 +0100 Subject: [PATCH 4/6] Updates circleci Dependencies now also include dev-requirements and cli tests are now also enabled. bitcoind_mock is got from PyPi now instead of github. --- .circleci/config.yml | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d031def..fd9b2e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,7 +23,7 @@ jobs: # Download and cache dependencies - restore_cache: keys: - - v1-dependencies-{{ checksum "pisa/requirements.txt" }} + - v1-dependencies-{{ checksum "pisa/requirements.txt" }}-{{ checksum "pisa/requirements-dev.txt" }} # fallback to using the latest cache if no exact match is found - v1-dependencies- @@ -33,22 +33,12 @@ jobs: python3 -m venv venv . venv/bin/activate pip install -r pisa/requirements.txt + pip install -r pisa/requirements-dev.txt - save_cache: paths: - ./venv - key: v1-dependencies-{{ checksum "pisa/requirements.txt" }} - - # Get github dependencies (pending to add to PyPi) - - run: - name: get bitcoind mock - command: | - git clone git@github.com:sr-gi/bitcoind_mock.git - . venv/bin/activate - pip install -r bitcoind_mock/requirements.txt - cp bitcoind_mock/bitcoind_mock/sample_conf.py bitcoind_mock/bitcoind_mock/conf.py - mv bitcoind_mock/bitcoind_mock ~/repo/venv/lib/python3.6/site-packages - + key: v1-dependencies-{{ checksum "pisa/requirements.txt" }}-{{ checksum "pisa/requirements-dev.txt" }} # run tests! # this example uses Django's built-in test-runner @@ -71,11 +61,11 @@ jobs: . venv/bin/activate pytest test/common/unit -# - run: -# name: run cli unit tests -# command: | -# . venv/bin/activate -# pytest test/apps/cli/unit + - run: + name: run cli unit tests + command: | + . venv/bin/activate + pytest test/apps/cli/unit # - store_artifacts: # path: test-reports From 3dc1fbcb864baf029e8fe5278325ce1596758cf0 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 15 Jan 2020 16:33:04 +0100 Subject: [PATCH 5/6] Specifies minimum version for bitcoind_mock --- pisa/requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pisa/requirements-dev.txt b/pisa/requirements-dev.txt index b18071f..10481e4 100644 --- a/pisa/requirements-dev.txt +++ b/pisa/requirements-dev.txt @@ -1,3 +1,3 @@ pytest black -bitcoind_mock \ No newline at end of file +bitcoind_mock===0.0.4 From 5e4e773984c7f4034c5e215746daac92770b411d Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 15 Jan 2020 16:38:56 +0100 Subject: [PATCH 6/6] Adds cli requirements to circle-ci --- .circleci/config.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fd9b2e0..41711ad 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,7 +23,7 @@ jobs: # Download and cache dependencies - restore_cache: keys: - - v1-dependencies-{{ checksum "pisa/requirements.txt" }}-{{ checksum "pisa/requirements-dev.txt" }} + - v1-dependencies-{{ checksum "pisa/requirements.txt" }}-{{ checksum "pisa/requirements-dev.txt" }}-{{ checksum "apps/cli/requirements-dev.txt" }} # fallback to using the latest cache if no exact match is found - v1-dependencies- @@ -32,13 +32,14 @@ jobs: command: | python3 -m venv venv . venv/bin/activate - pip install -r pisa/requirements.txt + pip install -r pisa/requirements.txt pip install -r pisa/requirements-dev.txt + pip install -r apps/cli/requirements-dev.txt - save_cache: paths: - ./venv - key: v1-dependencies-{{ checksum "pisa/requirements.txt" }}-{{ checksum "pisa/requirements-dev.txt" }} + key: v1-dependencies-{{ checksum "pisa/requirements.txt" }}-{{ checksum "pisa/requirements-dev.txt" }}-{{ checksum "apps/cli/requirements-dev.txt" }} # run tests! # this example uses Django's built-in test-runner