mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Generalizes get_dummy_appointment (there were multiple instances of it in different tests)
Also refactors some unused imports and modifies the watcher tests to use .serialize instead of to_json
This commit is contained in:
@@ -4,13 +4,19 @@ import requests
|
||||
from time import sleep
|
||||
from shutil import rmtree
|
||||
from threading import Thread
|
||||
from hashlib import sha256
|
||||
from binascii import unhexlify
|
||||
|
||||
from pisa.conf import DB_PATH
|
||||
from apps.cli.blob import Blob
|
||||
from pisa.api import start_api
|
||||
from pisa.responder import Job
|
||||
from pisa.watcher import Watcher
|
||||
from pisa.tools import bitcoin_cli
|
||||
from pisa.db_manager import DBManager
|
||||
from pisa.appointment import Appointment
|
||||
from test.simulator.utils import sha256d
|
||||
from test.simulator.transaction import TX
|
||||
from test.simulator.bitcoind_sim import run_simulator, HOST, PORT
|
||||
|
||||
|
||||
@@ -52,9 +58,9 @@ def db_manager():
|
||||
|
||||
|
||||
def get_random_value_hex(nbytes):
|
||||
pseudo_random_value = random.getrandbits(8*nbytes)
|
||||
pseudo_random_value = random.getrandbits(8 * nbytes)
|
||||
prv_hex = '{:x}'.format(pseudo_random_value)
|
||||
return prv_hex.zfill(2*nbytes)
|
||||
return prv_hex.zfill(2 * nbytes)
|
||||
|
||||
|
||||
def generate_block():
|
||||
@@ -67,19 +73,38 @@ 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
|
||||
def generate_dummy_appointment_data(start_time_offset=5, end_time_offset=30):
|
||||
current_height = bitcoin_cli().getblockcount()
|
||||
|
||||
dispute_tx = TX.create_dummy_transaction()
|
||||
dispute_txid = sha256d(dispute_tx)
|
||||
justice_tx = TX.create_dummy_transaction(dispute_txid)
|
||||
|
||||
dummy_appointment_data = {"tx": justice_tx, "tx_id": dispute_txid, "start_time": current_height + start_time_offset,
|
||||
"end_time": current_height + end_time_offset, "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)
|
||||
locator = sha256(unhexlify(dispute_txid)).hexdigest()
|
||||
blob = Blob(dummy_appointment_data.get("tx"), cipher, hash_function)
|
||||
|
||||
return Appointment.from_dict(appointment_data)
|
||||
encrypted_blob = blob.encrypt((dummy_appointment_data.get("tx_id")))
|
||||
|
||||
appointment_data = {"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,
|
||||
"triggered": False}
|
||||
|
||||
return appointment_data, dispute_tx
|
||||
|
||||
|
||||
def generate_dummy_appointment(start_time_offset=5, end_time_offset=30):
|
||||
appointment_data, dispute_tx = generate_dummy_appointment_data(start_time_offset=start_time_offset,
|
||||
end_time_offset=end_time_offset)
|
||||
|
||||
return Appointment.from_dict(appointment_data), dispute_tx
|
||||
|
||||
|
||||
def generate_dummy_job():
|
||||
@@ -91,4 +116,3 @@ def generate_dummy_job():
|
||||
appointment_end=100)
|
||||
|
||||
return Job.from_dict(job_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user