mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 14:44:21 +01:00
Update unit tests to use serialize
This commit is contained in:
@@ -15,7 +15,7 @@ from pisa.responder import TransactionTracker
|
||||
from pisa.watcher import Watcher
|
||||
from pisa.tools import bitcoin_cli
|
||||
from pisa.db_manager import DBManager
|
||||
from pisa.appointment import Appointment
|
||||
from common.appointment import Appointment
|
||||
|
||||
from test.simulator.utils import sha256d
|
||||
from test.simulator.transaction import TX
|
||||
@@ -110,7 +110,7 @@ def generate_dummy_appointment_data(real_height=True, start_time_offset=5, end_t
|
||||
"encrypted_blob": encrypted_blob,
|
||||
}
|
||||
|
||||
signature = Cryptographer.sign(Cryptographer.signature_format(appointment_data), client_sk)
|
||||
signature = Cryptographer.sign(Appointment.from_dict(appointment_data).serialize(), client_sk)
|
||||
pk_hex = hexlify(client_pk_der).decode("utf-8")
|
||||
|
||||
data = {"appointment": appointment_data, "signature": signature, "public_key": pk_hex}
|
||||
|
||||
@@ -4,7 +4,7 @@ from uuid import uuid4
|
||||
from pisa import c_logger
|
||||
from pisa.responder import TransactionTracker
|
||||
from pisa.cleaner import Cleaner
|
||||
from pisa.appointment import Appointment
|
||||
from common.appointment import Appointment
|
||||
from pisa.db_manager import WATCHER_PREFIX
|
||||
|
||||
from test.pisa.unit.conftest import get_random_value_hex
|
||||
|
||||
@@ -7,7 +7,7 @@ from cryptography.hazmat.primitives import serialization
|
||||
from pisa import c_logger
|
||||
from pisa.errors import *
|
||||
from pisa.inspector import Inspector
|
||||
from pisa.appointment import Appointment
|
||||
from common.appointment import Appointment
|
||||
from pisa.block_processor import BlockProcessor
|
||||
from pisa.conf import MIN_TO_SELF_DELAY
|
||||
|
||||
@@ -185,7 +185,9 @@ def test_check_appointment_signature():
|
||||
fake_sk = ec.generate_private_key(ec.SECP256K1, default_backend())
|
||||
|
||||
# Create a bad signature to make sure inspector rejects it
|
||||
bad_signature = Cryptographer.sign(Cryptographer.signature_format(dummy_appointment_data["appointment"]), fake_sk)
|
||||
bad_signature = Cryptographer.sign(
|
||||
Appointment.from_dict(dummy_appointment_data["appointment"]).serialize(), fake_sk
|
||||
)
|
||||
assert (
|
||||
Inspector.check_appointment_signature(dummy_appointment_data["appointment"], bad_signature, client_pk_hex)[0]
|
||||
== APPOINTMENT_INVALID_SIGNATURE
|
||||
@@ -202,12 +204,6 @@ def test_inspect(run_bitcoind):
|
||||
)
|
||||
client_pk_hex = hexlify(client_pk_der).decode("utf-8")
|
||||
|
||||
# Invalid appointment, every field is empty
|
||||
appointment_data = dict()
|
||||
signature = Cryptographer.sign(Cryptographer.signature_format(appointment_data), client_sk)
|
||||
appointment = inspector.inspect(appointment_data, signature, client_pk)
|
||||
assert type(appointment) == tuple and appointment[0] != 0
|
||||
|
||||
# Valid appointment
|
||||
locator = get_random_value_hex(LOCATOR_LEN_BYTES)
|
||||
start_time = BlockProcessor.get_block_count() + 5
|
||||
@@ -223,7 +219,7 @@ def test_inspect(run_bitcoind):
|
||||
"encrypted_blob": encrypted_blob,
|
||||
}
|
||||
|
||||
signature = Cryptographer.sign(Cryptographer.signature_format(appointment_data), client_sk)
|
||||
signature = Cryptographer.sign(Appointment.from_dict(appointment_data).serialize(), client_sk)
|
||||
|
||||
appointment = inspector.inspect(appointment_data, signature, client_pk_hex)
|
||||
|
||||
|
||||
@@ -92,13 +92,13 @@ def test_add_appointment(run_bitcoind, watcher):
|
||||
added_appointment, sig = watcher.add_appointment(appointment)
|
||||
|
||||
assert added_appointment is True
|
||||
assert Cryptographer.verify(Cryptographer.signature_format(appointment.to_dict()), sig, public_key)
|
||||
assert Cryptographer.verify(appointment.serialize(), sig, public_key)
|
||||
|
||||
# Check that we can also add an already added appointment (same locator)
|
||||
added_appointment, sig = watcher.add_appointment(appointment)
|
||||
|
||||
assert added_appointment is True
|
||||
assert Cryptographer.verify(Cryptographer.signature_format(appointment.to_dict()), sig, public_key)
|
||||
assert Cryptographer.verify(appointment.serialize(), sig, public_key)
|
||||
|
||||
|
||||
def test_add_too_many_appointments(watcher):
|
||||
@@ -112,7 +112,7 @@ def test_add_too_many_appointments(watcher):
|
||||
added_appointment, sig = watcher.add_appointment(appointment)
|
||||
|
||||
assert added_appointment is True
|
||||
assert Cryptographer.verify(Cryptographer.signature_format(appointment.to_dict()), sig, public_key)
|
||||
assert Cryptographer.verify(appointment.serialize(), sig, public_key)
|
||||
|
||||
appointment, dispute_tx = generate_dummy_appointment(
|
||||
start_time_offset=START_TIME_OFFSET, end_time_offset=END_TIME_OFFSET
|
||||
|
||||
Reference in New Issue
Block a user