Changes sk_path to sk_der in Watcher

The Watcher used to receive a secret key file path ion the __init__ to load a secret key for signing. That made testing the Watcher hard, since the file needed to be present. Changing it so the main (pisad) loads the file from disk and passes the data the Watcher on init.
This commit is contained in:
Sergi Delgado Segura
2019-12-16 10:54:13 +01:00
parent e6fd9f77cf
commit 2f67ecfa6e
4 changed files with 41 additions and 30 deletions

View File

@@ -3,6 +3,7 @@ import pytest
import requests
from time import sleep
from threading import Thread
from cryptography.hazmat.primitives import serialization
from pisa.api import start_api
from pisa.watcher import Watcher
@@ -10,7 +11,13 @@ from pisa.tools import bitcoin_cli
from pisa import HOST, PORT, c_logger
from pisa.conf import MAX_APPOINTMENTS
from test.unit.conftest import generate_block, generate_blocks, get_random_value_hex, generate_dummy_appointment_data
from test.unit.conftest import (
generate_block,
generate_blocks,
get_random_value_hex,
generate_dummy_appointment_data,
generate_keypair,
)
from common.constants import LOCATOR_LEN_BYTES
@@ -25,7 +32,13 @@ locator_dispute_tx_map = {}
@pytest.fixture(scope="module")
def run_api(db_manager):
watcher = Watcher(db_manager)
sk, pk = generate_keypair()
sk_der = sk.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption(),
)
watcher = Watcher(db_manager, sk_der)
api_thread = Thread(target=start_api, args=[watcher])
api_thread.daemon = True