Adapts the tests to work with data in db instead of memory

This commit is contained in:
Sergi Delgado Segura
2020-01-09 18:20:00 +01:00
parent 5196f5df29
commit db46444348
3 changed files with 67 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ from uuid import uuid4
from pisa.responder import TransactionTracker
from pisa.cleaner import Cleaner
from common.appointment import Appointment
from pisa.db_manager import WATCHER_PREFIX
from pisa.db_manager import WATCHER_PREFIX, TRIGGERED_APPOINTMENTS_PREFIX
from test.pisa.unit.conftest import get_random_value_hex
@@ -26,7 +26,7 @@ def set_up_appointments(db_manager, total_appointments):
locator = get_random_value_hex(LOCATOR_LEN_BYTES)
appointment = Appointment(locator, None, None, None, None)
appointments[uuid] = appointment
appointments[uuid] = {"locator": appointment.locator}
locator_uuid_map[locator] = [uuid]
db_manager.store_watcher_appointment(uuid, appointment.to_json())
@@ -36,7 +36,7 @@ def set_up_appointments(db_manager, total_appointments):
if i % 2:
uuid = uuid4().hex
appointments[uuid] = appointment
appointments[uuid] = {"locator": appointment.locator}
locator_uuid_map[locator].append(uuid)
db_manager.store_watcher_appointment(uuid, appointment.to_json())
@@ -59,7 +59,7 @@ def set_up_trackers(db_manager, total_trackers):
# Assign both penalty_txid and dispute_txid the same id (it shouldn't matter)
tracker = TransactionTracker(locator, dispute_txid, penalty_txid, None, None)
trackers[uuid] = tracker
trackers[uuid] = {"locator": tracker.locator, "penalty_txid": tracker.penalty_txid}
tx_tracker_map[penalty_txid] = [uuid]
db_manager.store_responder_tracker(uuid, tracker.to_json())
@@ -69,7 +69,7 @@ def set_up_trackers(db_manager, total_trackers):
if i % 2:
uuid = uuid4().hex
trackers[uuid] = tracker
trackers[uuid] = {"locator": tracker.locator, "penalty_txid": tracker.penalty_txid}
tx_tracker_map[penalty_txid].append(uuid)
db_manager.store_responder_tracker(uuid, tracker.to_json())
@@ -99,9 +99,8 @@ def test_delete_completed_appointments(db_manager):
assert len(appointments) == 0
# Make sure that all appointments are flagged as triggered in the db
db_appointments = db_manager.load_appointments_db(prefix=WATCHER_PREFIX)
for uuid in uuids:
assert db_appointments[uuid]["triggered"] is True
assert db_manager.db.get((TRIGGERED_APPOINTMENTS_PREFIX + uuid).encode("utf-8")) is not None
def test_delete_completed_trackers_db_match(db_manager):
@@ -128,12 +127,12 @@ def test_delete_completed_trackers_no_db_match(db_manager):
# Let's change some uuid's by creating new trackers that are not included in the db and share a penalty_txid
# with another tracker that is stored in the db.
for uuid in selected_trackers[: ITEMS // 2]:
penalty_txid = trackers[uuid].penalty_txid
penalty_txid = trackers[uuid].get("penalty_txid")
dispute_txid = get_random_value_hex(32)
locator = dispute_txid[:LOCATOR_LEN_HEX]
new_uuid = uuid4().hex
trackers[new_uuid] = TransactionTracker(locator, dispute_txid, penalty_txid, None, None)
trackers[new_uuid] = {"locator": locator, "penalty_txid": penalty_txid}
tx_tracker_map[penalty_txid].append(new_uuid)
selected_trackers.append(new_uuid)
@@ -144,7 +143,7 @@ def test_delete_completed_trackers_no_db_match(db_manager):
dispute_txid = get_random_value_hex(32)
locator = dispute_txid[:LOCATOR_LEN_HEX]
trackers[uuid] = TransactionTracker(locator, dispute_txid, penalty_txid, None, None)
trackers[uuid] = {"locator": locator, "penalty_txid": penalty_txid}
tx_tracker_map[penalty_txid] = [uuid]
selected_trackers.append(uuid)