From a6b1f96aaf8f80ede08f02872fb2d04be4d0689c Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Tue, 5 Nov 2019 19:11:58 +0000 Subject: [PATCH] Adds dummy appointment and job methods to conftest and includes triggered param to test_api --- test/unit/conftest.py | 27 +++++++++++++++++++++++++++ test/unit/test_api.py | 7 ++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/test/unit/conftest.py b/test/unit/conftest.py index c461c5f..2a1f806 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -7,8 +7,10 @@ from threading import Thread from pisa.conf import DB_PATH from pisa.api import start_api +from pisa.responder import Job from pisa.watcher import Watcher from pisa.db_manager import DBManager +from pisa.appointment import Appointment from test.simulator.bitcoind_sim import run_simulator, HOST, PORT @@ -65,3 +67,28 @@ def generate_blocks(n): generate_block() +def generate_dummy_appointment(): + locator = get_random_value_hex(32) + encrypted_blob = get_random_value_hex(250) + start_time = 100 + end_time = 120 + dispute_delta = 20 + cipher = "AES-GCM-128" + hash_function = "SHA256" + + appointment_data = dict(locator=locator, start_time=start_time, end_time=end_time, dispute_delta=dispute_delta, + encrypted_blob=encrypted_blob, cipher=cipher, hash_function=hash_function, triggered=False) + + return Appointment.from_dict(appointment_data) + + +def generate_dummy_job(): + dispute_txid = get_random_value_hex(32) + justice_txid = get_random_value_hex(32) + justice_rawtx = get_random_value_hex(100) + + job_data = dict(dispute_txid=dispute_txid, justice_txid=justice_txid, justice_rawtx=justice_rawtx, + appointment_end=100) + + return Job.from_dict(job_data) + diff --git a/test/unit/test_api.py b/test/unit/test_api.py index fb88ce8..9bbeca8 100644 --- a/test/unit/test_api.py +++ b/test/unit/test_api.py @@ -22,7 +22,7 @@ appointments = [] locator_dispute_tx_map = {} -def generate_dummy_appointment(): +def generate_dummy_appointment_data(): current_height = bitcoin_cli().getblockcount() dispute_tx = TX.create_dummy_transaction() @@ -43,14 +43,15 @@ def generate_dummy_appointment(): appointment = {"locator": locator, "start_time": dummy_appointment_data.get("start_time"), "end_time": dummy_appointment_data.get("end_time"), "dispute_delta": dummy_appointment_data.get("dispute_delta"), - "encrypted_blob": encrypted_blob, "cipher": cipher, "hash_function": hash_function} + "encrypted_blob": encrypted_blob, "cipher": cipher, "hash_function": hash_function, + "triggered": False} return appointment, dispute_tx @pytest.fixture def new_appointment(): - appointment, dispute_tx = generate_dummy_appointment() + appointment, dispute_tx = generate_dummy_appointment_data() locator_dispute_tx_map[appointment["locator"]] = dispute_tx return appointment