Adds dummy appointment and job methods to conftest and includes triggered param to test_api

This commit is contained in:
Sergi Delgado Segura
2019-11-05 19:11:58 +00:00
parent 6644ad5bd1
commit a6b1f96aaf
2 changed files with 31 additions and 3 deletions

View File

@@ -7,8 +7,10 @@ from threading import Thread
from pisa.conf import DB_PATH from pisa.conf import DB_PATH
from pisa.api import start_api from pisa.api import start_api
from pisa.responder import Job
from pisa.watcher import Watcher from pisa.watcher import Watcher
from pisa.db_manager import DBManager from pisa.db_manager import DBManager
from pisa.appointment import Appointment
from test.simulator.bitcoind_sim import run_simulator, HOST, PORT from test.simulator.bitcoind_sim import run_simulator, HOST, PORT
@@ -65,3 +67,28 @@ def generate_blocks(n):
generate_block() 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)

View File

@@ -22,7 +22,7 @@ appointments = []
locator_dispute_tx_map = {} locator_dispute_tx_map = {}
def generate_dummy_appointment(): def generate_dummy_appointment_data():
current_height = bitcoin_cli().getblockcount() current_height = bitcoin_cli().getblockcount()
dispute_tx = TX.create_dummy_transaction() 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"), appointment = {"locator": locator, "start_time": dummy_appointment_data.get("start_time"),
"end_time": dummy_appointment_data.get("end_time"), "end_time": dummy_appointment_data.get("end_time"),
"dispute_delta": dummy_appointment_data.get("dispute_delta"), "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 return appointment, dispute_tx
@pytest.fixture @pytest.fixture
def new_appointment(): def new_appointment():
appointment, dispute_tx = generate_dummy_appointment() appointment, dispute_tx = generate_dummy_appointment_data()
locator_dispute_tx_map[appointment["locator"]] = dispute_tx locator_dispute_tx_map[appointment["locator"]] = dispute_tx
return appointment return appointment