mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Separated signing logic of the Watcher in sign_appointment function; added unit test
This commit is contained in:
@@ -82,6 +82,15 @@ def create_appointments(n):
|
||||
return appointments, locator_uuid_map, dispute_txs
|
||||
|
||||
|
||||
def verify_signature(appointment, signature, pk):
|
||||
# verify the signature
|
||||
try:
|
||||
data = appointment.to_json().encode('utf-8')
|
||||
pk.verify(signature, data, ec.ECDSA(hashes.SHA256()))
|
||||
except InvalidSignature:
|
||||
assert False, "The appointment's signature is not correct"
|
||||
|
||||
|
||||
def test_init(watcher):
|
||||
assert type(watcher.appointments) is dict and len(watcher.appointments) == 0
|
||||
assert type(watcher.locator_uuid_map) is dict and len(watcher.locator_uuid_map) == 0
|
||||
@@ -92,6 +101,12 @@ def test_init(watcher):
|
||||
assert type(watcher.responder) is Responder
|
||||
|
||||
|
||||
def test_sign_appointment(watcher):
|
||||
appointment, _ = generate_dummy_appointment()
|
||||
signature = watcher.sign_appointment(appointment)
|
||||
verify_signature(appointment, signature, public_key)
|
||||
|
||||
|
||||
def test_add_appointment(run_bitcoind, watcher):
|
||||
# The watcher automatically fires do_watch and do_subscribe on adding an appointment if it is asleep (initial state)
|
||||
# Avoid this by setting the state to awake.
|
||||
@@ -104,12 +119,7 @@ def test_add_appointment(run_bitcoind, watcher):
|
||||
|
||||
assert added_appointment is True
|
||||
|
||||
# verify the signature
|
||||
try:
|
||||
data = appointment.to_json().encode('utf-8')
|
||||
public_key.verify(sig, data, ec.ECDSA(hashes.SHA256()))
|
||||
except InvalidSignature:
|
||||
assert False, "The appointment's signature is not correct"
|
||||
verify_signature(appointment, sig, public_key)
|
||||
|
||||
|
||||
def test_add_too_many_appointments(watcher):
|
||||
@@ -121,6 +131,7 @@ def test_add_too_many_appointments(watcher):
|
||||
added_appointment, sig = watcher.add_appointment(appointment)
|
||||
|
||||
assert added_appointment is True
|
||||
verify_signature(appointment, sig, public_key)
|
||||
|
||||
appointment, dispute_tx = generate_dummy_appointment()
|
||||
added_appointment, sig = watcher.add_appointment(appointment)
|
||||
|
||||
Reference in New Issue
Block a user