pisa -> teos

This commit is contained in:
Sergi Delgado Segura
2020-03-17 13:05:55 +01:00
parent 15126618d5
commit 7c7ff909d7
56 changed files with 373 additions and 372 deletions

View File

@@ -11,10 +11,10 @@ from common.appointment import Appointment
from common.cryptographer import Cryptographer
from common.blob import Blob
import apps.cli.wt_cli as wt_cli
import apps.cli.teos_cli as teos_cli
from test.apps.cli.unit.conftest import get_random_value_hex
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=wt_cli.LOG_PREFIX)
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=teos_cli.LOG_PREFIX)
# dummy keys for the tests
dummy_sk = PrivateKey()
@@ -23,11 +23,11 @@ another_sk = PrivateKey()
# Replace the key in the module with a key we control for the tests
wt_cli.pisa_public_key = dummy_pk
teos_cli.teos_public_key = dummy_pk
# Replace endpoint with dummy one
wt_cli.pisa_api_server = "https://dummy.com"
wt_cli.pisa_api_port = 12345
pisa_endpoint = "{}:{}/".format(wt_cli.pisa_api_server, wt_cli.pisa_api_port)
teos_cli.teos_api_server = "https://dummy.com"
teos_cli.teos_api_port = 12345
teos_endpoint = "{}:{}/".format(teos_cli.teos_api_server, teos_cli.teos_api_port)
dummy_appointment_request = {
"tx": get_random_value_hex(192),
@@ -74,17 +74,17 @@ def get_bad_signature(*args):
# f.write(dummy_pk_der)
#
# # Now we can test the function passing the using this files (we'll use the same pk for both)
# r = wt_cli.load_keys(public_key_file_path, private_key_file_path, public_key_file_path)
# r = teos_cli.load_keys(public_key_file_path, private_key_file_path, public_key_file_path)
# assert isinstance(r, tuple)
# assert len(r) == 3
#
# # If any param does not match we should get None as result
# assert wt_cli.load_keys(None, private_key_file_path, public_key_file_path) is None
# assert wt_cli.load_keys(public_key_file_path, None, public_key_file_path) is None
# assert wt_cli.load_keys(public_key_file_path, private_key_file_path, None) is None
# assert teos_cli.load_keys(None, private_key_file_path, public_key_file_path) is None
# assert teos_cli.load_keys(public_key_file_path, None, public_key_file_path) is None
# assert teos_cli.load_keys(public_key_file_path, private_key_file_path, None) is None
#
# # The same should happen if we pass a public key where a private should be, for instance
# assert wt_cli.load_keys(private_key_file_path, public_key_file_path, private_key_file_path) is None
# assert teos_cli.load_keys(private_key_file_path, public_key_file_path, private_key_file_path) is None
#
# os.remove(private_key_file_path)
# os.remove(public_key_file_path)
@@ -95,14 +95,14 @@ def get_bad_signature(*args):
def test_add_appointment(monkeypatch):
# Simulate a request to add_appointment for dummy_appointment, make sure that the right endpoint is requested
# and the return value is True
monkeypatch.setattr(wt_cli, "load_keys", load_dummy_keys)
monkeypatch.setattr(teos_cli, "load_keys", load_dummy_keys)
response = {"locator": dummy_appointment.locator, "signature": get_dummy_signature()}
responses.add(responses.POST, pisa_endpoint, json=response, status=200)
result = wt_cli.add_appointment([json.dumps(dummy_appointment_request)])
responses.add(responses.POST, teos_endpoint, json=response, status=200)
result = teos_cli.add_appointment([json.dumps(dummy_appointment_request)])
assert len(responses.calls) == 1
assert responses.calls[0].request.url == pisa_endpoint
assert responses.calls[0].request.url == teos_endpoint
assert result
@@ -112,39 +112,39 @@ def test_add_appointment_with_invalid_signature(monkeypatch):
# make sure that the right endpoint is requested, but the return value is False
# Make sure the test uses the bad dummy signature
monkeypatch.setattr(wt_cli, "load_keys", load_dummy_keys)
monkeypatch.setattr(teos_cli, "load_keys", load_dummy_keys)
response = {
"locator": dummy_appointment.to_dict()["locator"],
"signature": get_bad_signature(), # Sign with a bad key
}
responses.add(responses.POST, pisa_endpoint, json=response, status=200)
result = wt_cli.add_appointment([json.dumps(dummy_appointment_request)])
responses.add(responses.POST, teos_endpoint, json=response, status=200)
result = teos_cli.add_appointment([json.dumps(dummy_appointment_request)])
assert result is False
def test_parse_add_appointment_args():
# If no args are passed, function should fail.
appt_data = wt_cli.parse_add_appointment_args(None)
appt_data = teos_cli.parse_add_appointment_args(None)
assert not appt_data
# If file doesn't exist, function should fail.
appt_data = wt_cli.parse_add_appointment_args(["-f", "nonexistent_file"])
appt_data = teos_cli.parse_add_appointment_args(["-f", "nonexistent_file"])
assert not appt_data
# If file exists and has data in it, function should work.
with open("appt_test_file", "w") as f:
json.dump(dummy_appointment_request, f)
appt_data = wt_cli.parse_add_appointment_args(["-f", "appt_test_file"])
appt_data = teos_cli.parse_add_appointment_args(["-f", "appt_test_file"])
assert appt_data
os.remove("appt_test_file")
# If appointment json is passed in, function should work.
appt_data = wt_cli.parse_add_appointment_args([json.dumps(dummy_appointment_request)])
appt_data = teos_cli.parse_add_appointment_args([json.dumps(dummy_appointment_request)])
assert appt_data
@@ -155,11 +155,11 @@ def test_post_appointment():
"signature": Cryptographer.sign(dummy_appointment.serialize(), dummy_pk),
}
responses.add(responses.POST, pisa_endpoint, json=response, status=200)
response = wt_cli.post_appointment(json.dumps(dummy_appointment_request))
responses.add(responses.POST, teos_endpoint, json=response, status=200)
response = teos_cli.post_appointment(json.dumps(dummy_appointment_request))
assert len(responses.calls) == 1
assert responses.calls[0].request.url == pisa_endpoint
assert responses.calls[0].request.url == teos_endpoint
assert response
@@ -172,28 +172,28 @@ def test_process_post_appointment_response():
}
# A 200 OK with a correct json response should return the json of the response
responses.add(responses.POST, pisa_endpoint, json=response, status=200)
r = wt_cli.post_appointment(json.dumps(dummy_appointment_request))
assert wt_cli.process_post_appointment_response(r) == r.json()
responses.add(responses.POST, teos_endpoint, json=response, status=200)
r = teos_cli.post_appointment(json.dumps(dummy_appointment_request))
assert teos_cli.process_post_appointment_response(r) == r.json()
# If we modify the response code tor a rejection (lets say 404) we should get None
responses.replace(responses.POST, pisa_endpoint, json=response, status=404)
r = wt_cli.post_appointment(json.dumps(dummy_appointment_request))
assert wt_cli.process_post_appointment_response(r) is None
responses.replace(responses.POST, teos_endpoint, json=response, status=404)
r = teos_cli.post_appointment(json.dumps(dummy_appointment_request))
assert teos_cli.process_post_appointment_response(r) is None
# The same should happen if the response is not in json
responses.replace(responses.POST, pisa_endpoint, status=404)
r = wt_cli.post_appointment(json.dumps(dummy_appointment_request))
assert wt_cli.process_post_appointment_response(r) is None
responses.replace(responses.POST, teos_endpoint, status=404)
r = teos_cli.post_appointment(json.dumps(dummy_appointment_request))
assert teos_cli.process_post_appointment_response(r) is None
def test_save_appointment_receipt(monkeypatch):
appointments_folder = "test_appointments_receipts"
wt_cli.config["APPOINTMENTS_FOLDER_NAME"] = appointments_folder
teos_cli.config["APPOINTMENTS_FOLDER_NAME"] = appointments_folder
# The functions creates a new directory if it does not exist
assert not os.path.exists(appointments_folder)
wt_cli.save_appointment_receipt(dummy_appointment.to_dict(), get_dummy_signature())
teos_cli.save_appointment_receipt(dummy_appointment.to_dict(), get_dummy_signature())
assert os.path.exists(appointments_folder)
# Check that the receipt has been saved by checking the file names
@@ -209,9 +209,9 @@ def test_get_appointment():
dummy_appointment_full["status"] = "being_watched"
response = dummy_appointment_full
request_url = "{}get_appointment?locator={}".format(pisa_endpoint, response.get("locator"))
request_url = "{}get_appointment?locator={}".format(teos_endpoint, response.get("locator"))
responses.add(responses.GET, request_url, json=response, status=200)
result = wt_cli.get_appointment(response.get("locator"))
result = teos_cli.get_appointment(response.get("locator"))
assert len(responses.calls) == 1
assert responses.calls[0].request.url == request_url
@@ -223,7 +223,7 @@ def test_get_appointment_err():
locator = get_random_value_hex(16)
# Test that get_appointment handles a connection error appropriately.
request_url = "{}get_appointment?locator=".format(pisa_endpoint, locator)
request_url = "{}get_appointment?locator=".format(teos_endpoint, locator)
responses.add(responses.GET, request_url, body=ConnectionError())
assert not wt_cli.get_appointment(locator)
assert not teos_cli.get_appointment(locator)

View File

@@ -3,8 +3,8 @@ import pytest
import logging
from copy import deepcopy
# FIXME: Import from pisa. Common should not import anything from cli nor pisa.
from pisa import conf_fields
# FIXME: Import from teos. Common should not import anything from cli nor teos.
from teos import conf_fields
from common.constants import LOCATOR_LEN_BYTES
from common.tools import (

View File

@@ -3,9 +3,9 @@ import random
from multiprocessing import Process
from decimal import Decimal, getcontext
import pisa.conf as conf
from pisa.pisad import main
from pisa.utils.auth_proxy import AuthServiceProxy
import teos.conf as conf
from teos.teosd import main
from teos.utils.auth_proxy import AuthServiceProxy
getcontext().prec = 10
END_TIME_DELTA = 10
@@ -50,11 +50,11 @@ def create_txs(bitcoin_cli):
return signed_commitment_tx, signed_penalty_tx
def run_pisad():
pisad_process = Process(target=main, daemon=True)
pisad_process.start()
def run_teosd():
teosd_process = Process(target=main, daemon=True)
teosd_process.start()
return pisad_process
return teosd_process
def get_random_value_hex(nbytes):

View File

@@ -10,13 +10,13 @@ FEED_PROTOCOL = "tcp"
FEED_ADDR = "127.0.0.1"
FEED_PORT = 28335
# PISA
DATA_FOLDER = "~/.pisa_btc/"
# TEOS
DATA_FOLDER = "~/.teos/"
MAX_APPOINTMENTS = 100
EXPIRY_DELTA = 6
MIN_TO_SELF_DELAY = 20
SERVER_LOG_FILE = "pisa.log"
PISA_SECRET_KEY = "pisa_sk.der"
SERVER_LOG_FILE = "teos.log"
TEOS_SECRET_KEY = "teos_sk.der"
# CHAIN MONITOR
POLLING_DELTA = 60

View File

@@ -2,9 +2,9 @@ import json
from time import sleep
from riemann.tx import Tx
from pisa import config
from pisa import HOST, PORT
from apps.cli import wt_cli
from teos import config
from teos import HOST, PORT
from apps.cli import teos_cli
from common.blob import Blob
import common.cryptographer
@@ -12,31 +12,31 @@ from common.logger import Logger
from common.tools import compute_locator
from common.appointment import Appointment
from common.cryptographer import Cryptographer
from pisa.utils.auth_proxy import JSONRPCException
from test.pisa.e2e.conftest import (
from teos.utils.auth_proxy import JSONRPCException
from test.teos.e2e.conftest import (
END_TIME_DELTA,
build_appointment_data,
get_random_value_hex,
create_penalty_tx,
run_pisad,
run_teosd,
)
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
# We'll use wt_cli to add appointments. The expected input format is a list of arguments with a json-encoded
# We'll use teos_cli to add appointments. The expected input format is a list of arguments with a json-encoded
# appointment
wt_cli.pisa_api_server = "http://{}".format(HOST)
wt_cli.pisa_api_port = PORT
teos_cli.teos_api_server = "http://{}".format(HOST)
teos_cli.teos_api_port = PORT
# Run pisad
pisad_process = run_pisad()
# Run teosd
teosd_process = run_teosd()
def get_pisa_pk():
pisa_sk = Cryptographer.load_private_key_der(Cryptographer.load_key_file(config.get("PISA_SECRET_KEY")))
pisa_pk = pisa_sk.public_key
def get_teos_pk():
teos_sk = Cryptographer.load_private_key_der(Cryptographer.load_key_file(config.get("TEOS_SECRET_KEY")))
teos_pk = teos_sk.public_key
return pisa_pk
return teos_pk
def broadcast_transaction_and_mine_block(bitcoin_cli, commitment_tx, addr):
@@ -48,18 +48,18 @@ def broadcast_transaction_and_mine_block(bitcoin_cli, commitment_tx, addr):
def get_appointment_info(locator):
# Check that the justice has been triggered (the appointment has moved from Watcher to Responder)
sleep(1) # Let's add a bit of delay so the state can be updated
return wt_cli.get_appointment(locator)
return teos_cli.get_appointment(locator)
def test_appointment_life_cycle(monkeypatch, bitcoin_cli, create_txs):
monkeypatch.setattr(wt_cli, "load_keys", get_pisa_pk)
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
commitment_tx, penalty_tx = create_txs
commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid")
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
locator = compute_locator(commitment_tx_id)
assert wt_cli.add_appointment([json.dumps(appointment_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
appointment_info = get_appointment_info(locator)
assert appointment_info is not None
@@ -97,7 +97,7 @@ def test_appointment_life_cycle(monkeypatch, bitcoin_cli, create_txs):
def test_appointment_malformed_penalty(monkeypatch, bitcoin_cli, create_txs):
monkeypatch.setattr(wt_cli, "load_keys", get_pisa_pk)
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
# Lets start by creating two valid transaction
commitment_tx, penalty_tx = create_txs
@@ -111,7 +111,7 @@ def test_appointment_malformed_penalty(monkeypatch, bitcoin_cli, create_txs):
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, mod_penalty_tx.hex())
locator = compute_locator(commitment_tx_id)
assert wt_cli.add_appointment([json.dumps(appointment_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
# Broadcast the commitment transaction and mine a block
new_addr = bitcoin_cli.getnewaddress()
@@ -134,14 +134,14 @@ def test_appointment_wrong_key(bitcoin_cli, create_txs):
# The appointment data is built using a random 32-byte value.
appointment_data = build_appointment_data(bitcoin_cli, get_random_value_hex(32), penalty_tx)
# We can't use wt_cli.add_appointment here since it computes the locator internally, so let's do it manually.
# We can't use teos_cli.add_appointment here since it computes the locator internally, so let's do it manually.
# We will encrypt the blob using the random value and derive the locator from the commitment tx.
appointment_data["locator"] = compute_locator(bitcoin_cli.decoderawtransaction(commitment_tx).get("txid"))
appointment_data["encrypted_blob"] = Cryptographer.encrypt(Blob(penalty_tx), get_random_value_hex(32))
appointment = Appointment.from_dict(appointment_data)
# pisa_pk, cli_sk, cli_pk_der = wt_cli.load_keys(
# cli_conf.get("PISA_PUBLIC_KEY"), cli_conf.get("CLI_PRIVATE_KEY"), cli_conf.get("CLI_PUBLIC_KEY")
# teos_pk, cli_sk, cli_pk_der = teos_cli.load_keys(
# cli_conf.get("TEOS_PUBLIC_KEY"), cli_conf.get("CLI_PRIVATE_KEY"), cli_conf.get("CLI_PUBLIC_KEY")
# )
# hex_pk_der = binascii.hexlify(cli_pk_der)
#
@@ -149,18 +149,18 @@ def test_appointment_wrong_key(bitcoin_cli, create_txs):
# data = {"appointment": appointment.to_dict(), "signature": signature, "public_key": hex_pk_der.decode("utf-8")}
# FIXME: Since the pk is now hardcoded for the alpha in the cli we cannot use load_keys here. We need to derive
# the pk from the sk on disk.
pisa_pk = get_pisa_pk()
teos_pk = get_teos_pk()
data = {"appointment": appointment.to_dict()}
# Send appointment to the server.
response = wt_cli.post_appointment(data)
response_json = wt_cli.process_post_appointment_response(response)
response = teos_cli.post_appointment(data)
response_json = teos_cli.process_post_appointment_response(response)
# Check that the server has accepted the appointment
signature = response_json.get("signature")
assert signature is not None
rpk = Cryptographer.recover_pk(appointment.serialize(), signature)
assert Cryptographer.verify_rpk(pisa_pk, rpk) is True
assert Cryptographer.verify_rpk(teos_pk, rpk) is True
assert response_json.get("locator") == appointment.locator
# Trigger the appointment
@@ -177,7 +177,7 @@ def test_appointment_wrong_key(bitcoin_cli, create_txs):
def test_two_identical_appointments(monkeypatch, bitcoin_cli, create_txs):
monkeypatch.setattr(wt_cli, "load_keys", get_pisa_pk)
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
# Tests sending two identical appointments to the tower.
# At the moment there are no checks for identical appointments, so both will be accepted, decrypted and kept until
@@ -191,8 +191,8 @@ def test_two_identical_appointments(monkeypatch, bitcoin_cli, create_txs):
locator = compute_locator(commitment_tx_id)
# Send the appointment twice
assert wt_cli.add_appointment([json.dumps(appointment_data)]) is True
assert wt_cli.add_appointment([json.dumps(appointment_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
# Broadcast the commitment transaction and mine a block
new_addr = bitcoin_cli.getnewaddress()
@@ -212,7 +212,7 @@ def test_two_identical_appointments(monkeypatch, bitcoin_cli, create_txs):
def test_two_appointment_same_locator_different_penalty(monkeypatch, bitcoin_cli, create_txs):
monkeypatch.setattr(wt_cli, "load_keys", get_pisa_pk)
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
# This tests sending an appointment with two valid transaction with the same locator.
commitment_tx, penalty_tx1 = create_txs
@@ -227,8 +227,8 @@ def test_two_appointment_same_locator_different_penalty(monkeypatch, bitcoin_cli
appointment2_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx2)
locator = compute_locator(commitment_tx_id)
assert wt_cli.add_appointment([json.dumps(appointment1_data)]) is True
assert wt_cli.add_appointment([json.dumps(appointment2_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment1_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment2_data)]) is True
# Broadcast the commitment transaction and mine a block
new_addr = bitcoin_cli.getnewaddress()
@@ -245,25 +245,25 @@ def test_two_appointment_same_locator_different_penalty(monkeypatch, bitcoin_cli
assert appointment_info[0].get("penalty_rawtx") == penalty_tx1
def test_appointment_shutdown_pisa_trigger_back_online(monkeypatch, create_txs, bitcoin_cli):
global pisad_process
def test_appointment_shutdown_teos_trigger_back_online(monkeypatch, create_txs, bitcoin_cli):
global teosd_process
monkeypatch.setattr(wt_cli, "load_keys", get_pisa_pk)
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
pisa_pid = pisad_process.pid
teos_pid = teosd_process.pid
commitment_tx, penalty_tx = create_txs
commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid")
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
locator = compute_locator(commitment_tx_id)
assert wt_cli.add_appointment([json.dumps(appointment_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
# Restart pisa
pisad_process.terminate()
pisad_process = run_pisad()
# Restart teos
teosd_process.terminate()
teosd_process = run_teosd()
assert pisa_pid != pisad_process.pid
assert teos_pid != teosd_process.pid
# Check that the appointment is still in the Watcher
appointment_info = get_appointment_info(locator)
@@ -285,19 +285,19 @@ def test_appointment_shutdown_pisa_trigger_back_online(monkeypatch, create_txs,
assert appointment_info[0].get("status") == "dispute_responded"
def test_appointment_shutdown_pisa_trigger_while_offline(monkeypatch, create_txs, bitcoin_cli):
global pisad_process
def test_appointment_shutdown_teos_trigger_while_offline(monkeypatch, create_txs, bitcoin_cli):
global teosd_process
monkeypatch.setattr(wt_cli, "load_keys", get_pisa_pk)
monkeypatch.setattr(teos_cli, "load_keys", get_teos_pk)
pisa_pid = pisad_process.pid
teos_pid = teosd_process.pid
commitment_tx, penalty_tx = create_txs
commitment_tx_id = bitcoin_cli.decoderawtransaction(commitment_tx).get("txid")
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
locator = compute_locator(commitment_tx_id)
assert wt_cli.add_appointment([json.dumps(appointment_data)]) is True
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
# Check that the appointment is still in the Watcher
appointment_info = get_appointment_info(locator)
@@ -306,13 +306,13 @@ def test_appointment_shutdown_pisa_trigger_while_offline(monkeypatch, create_txs
assert appointment_info[0].get("status") == "being_watched"
# Shutdown and trigger
pisad_process.terminate()
teosd_process.terminate()
new_addr = bitcoin_cli.getnewaddress()
broadcast_transaction_and_mine_block(bitcoin_cli, commitment_tx, new_addr)
# Restart
pisad_process = run_pisad()
assert pisa_pid != pisad_process.pid
teosd_process = run_teosd()
assert teos_pid != teosd_process.pid
# The appointment should have been moved to the Responder
sleep(1)
@@ -322,4 +322,4 @@ def test_appointment_shutdown_pisa_trigger_while_offline(monkeypatch, create_txs
assert len(appointment_info) == 1
assert appointment_info[0].get("status") == "dispute_responded"
pisad_process.terminate()
teosd_process.terminate()

View File

@@ -9,9 +9,9 @@ from threading import Thread
from coincurve import PrivateKey
from common.blob import Blob
from pisa.responder import TransactionTracker
from pisa.tools import bitcoin_cli
from pisa.db_manager import DBManager
from teos.responder import TransactionTracker
from teos.tools import bitcoin_cli
from teos.db_manager import DBManager
from common.appointment import Appointment
from common.tools import compute_locator
@@ -19,7 +19,7 @@ from bitcoind_mock.transaction import create_dummy_transaction
from bitcoind_mock.bitcoind import BitcoindMock
from bitcoind_mock.conf import BTC_RPC_HOST, BTC_RPC_PORT
from pisa import LOG_PREFIX
from teos import LOG_PREFIX
import common.cryptographer
from common.logger import Logger
from common.constants import LOCATOR_LEN_HEX
@@ -151,7 +151,7 @@ def generate_dummy_tracker():
def get_config():
data_folder = os.path.expanduser("~/.pisa_btc")
data_folder = os.path.expanduser("~/.teos")
config = {
"BTC_RPC_USER": "username",
"BTC_RPC_PASSWD": "password",
@@ -165,8 +165,8 @@ def get_config():
"MAX_APPOINTMENTS": 100,
"EXPIRY_DELTA": 6,
"MIN_TO_SELF_DELAY": 20,
"SERVER_LOG_FILE": data_folder + "pisa.log",
"PISA_SECRET_KEY": data_folder + "pisa_sk.der",
"SERVER_LOG_FILE": data_folder + "teos.log",
"TEOS_SECRET_KEY": data_folder + "teos_sk.der",
"DB_PATH": "appointments",
}

View File

@@ -4,14 +4,14 @@ import requests
from time import sleep
from threading import Thread
from pisa.api import API
from pisa.watcher import Watcher
from pisa.responder import Responder
from pisa.tools import bitcoin_cli
from pisa import HOST, PORT
from pisa.chain_monitor import ChainMonitor
from teos.api import API
from teos.watcher import Watcher
from teos.responder import Responder
from teos.tools import bitcoin_cli
from teos import HOST, PORT
from teos.chain_monitor import ChainMonitor
from test.pisa.unit.conftest import (
from test.teos.unit.conftest import (
generate_block,
generate_blocks,
get_random_value_hex,
@@ -23,7 +23,7 @@ from test.pisa.unit.conftest import (
from common.constants import LOCATOR_LEN_BYTES
PISA_API = "http://{}:{}".format(HOST, PORT)
TEOS_API = "http://{}:{}".format(HOST, PORT)
MULTIPLE_APPOINTMENTS = 10
appointments = []
@@ -58,7 +58,7 @@ def new_appt_data():
def add_appointment(new_appt_data):
r = requests.post(url=PISA_API, json=json.dumps(new_appt_data), timeout=5)
r = requests.post(url=TEOS_API, json=json.dumps(new_appt_data), timeout=5)
if r.status_code == 200:
appointments.append(new_appt_data["appointment"])
@@ -78,7 +78,7 @@ def test_add_appointment(run_api, run_bitcoind, new_appt_data):
def test_request_random_appointment():
r = requests.get(url=PISA_API + "/get_appointment?locator=" + get_random_value_hex(LOCATOR_LEN_BYTES))
r = requests.get(url=TEOS_API + "/get_appointment?locator=" + get_random_value_hex(LOCATOR_LEN_BYTES))
assert r.status_code == 200
received_appointments = json.loads(r.content)
@@ -113,7 +113,7 @@ def test_add_too_many_appointment(new_appt_data):
def test_get_all_appointments_watcher():
r = requests.get(url=PISA_API + "/get_all_appointments")
r = requests.get(url=TEOS_API + "/get_all_appointments")
assert r.status_code == 200 and r.reason == "OK"
received_appointments = json.loads(r.content)
@@ -137,7 +137,7 @@ def test_get_all_appointments_responder():
generate_blocks(6)
# Get all appointments
r = requests.get(url=PISA_API + "/get_all_appointments")
r = requests.get(url=TEOS_API + "/get_all_appointments")
received_appointments = json.loads(r.content)
# Make sure there is not pending locator in the watcher
@@ -154,7 +154,7 @@ def test_request_appointment_watcher(new_appt_data):
assert r.status_code == 200
# Next we can request it
r = requests.get(url=PISA_API + "/get_appointment?locator=" + new_appt_data["appointment"]["locator"])
r = requests.get(url=TEOS_API + "/get_appointment?locator=" + new_appt_data["appointment"]["locator"])
assert r.status_code == 200
# Each locator may point to multiple appointments, check them all
@@ -181,7 +181,7 @@ def test_request_appointment_responder(new_appt_data):
# Generate a block to trigger the watcher
generate_block()
r = requests.get(url=PISA_API + "/get_appointment?locator=" + new_appt_data["appointment"]["locator"])
r = requests.get(url=TEOS_API + "/get_appointment?locator=" + new_appt_data["appointment"]["locator"])
assert r.status_code == 200
received_appointments = json.loads(r.content)

View File

@@ -1,7 +1,7 @@
import pytest
from pisa.block_processor import BlockProcessor
from test.pisa.unit.conftest import get_random_value_hex, generate_block, generate_blocks, fork
from teos.block_processor import BlockProcessor
from test.teos.unit.conftest import get_random_value_hex, generate_block, generate_blocks, fork
hex_tx = (

View File

@@ -2,10 +2,10 @@ import pytest
from uuid import uuid4
from queue import Queue
from pisa.builder import Builder
from pisa.watcher import Watcher
from pisa.responder import Responder
from test.pisa.unit.conftest import (
from teos.builder import Builder
from teos.watcher import Watcher
from teos.responder import Responder
from test.teos.unit.conftest import (
get_random_value_hex,
generate_dummy_appointment,
generate_dummy_tracker,

View File

@@ -1,9 +1,9 @@
import pytest
from pisa.carrier import Carrier
from teos.carrier import Carrier
from bitcoind_mock.transaction import create_dummy_transaction
from test.pisa.unit.conftest import generate_blocks, get_random_value_hex
from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
from test.teos.unit.conftest import generate_blocks, get_random_value_hex
from teos.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
# FIXME: This test do not fully cover the carrier since the simulator does not support every single error bitcoind may

View File

@@ -3,10 +3,10 @@ import time
from queue import Queue
from threading import Thread, Event, Condition
from pisa.block_processor import BlockProcessor
from pisa.chain_monitor import ChainMonitor
from teos.block_processor import BlockProcessor
from teos.chain_monitor import ChainMonitor
from test.pisa.unit.conftest import get_random_value_hex, generate_block
from test.teos.unit.conftest import get_random_value_hex, generate_block
def test_init(run_bitcoind):

View File

@@ -1,11 +1,11 @@
import random
from uuid import uuid4
from pisa.responder import TransactionTracker
from pisa.cleaner import Cleaner
from teos.responder import TransactionTracker
from teos.cleaner import Cleaner
from common.appointment import Appointment
from test.pisa.unit.conftest import get_random_value_hex
from test.teos.unit.conftest import get_random_value_hex
from common.constants import LOCATOR_LEN_BYTES, LOCATOR_LEN_HEX

View File

@@ -4,8 +4,8 @@ import pytest
import shutil
from uuid import uuid4
from pisa.db_manager import DBManager
from pisa.db_manager import (
from teos.db_manager import DBManager
from teos.db_manager import (
WATCHER_LAST_BLOCK_KEY,
RESPONDER_LAST_BLOCK_KEY,
LOCATOR_MAP_PREFIX,
@@ -14,7 +14,7 @@ from pisa.db_manager import (
from common.constants import LOCATOR_LEN_BYTES
from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appointment
from test.teos.unit.conftest import get_random_value_hex, generate_dummy_appointment
@pytest.fixture(scope="module")

View File

@@ -1,18 +1,18 @@
from binascii import unhexlify
from pisa.errors import *
from pisa.inspector import Inspector
from teos.errors import *
from teos.inspector import Inspector
from common.appointment import Appointment
from pisa.block_processor import BlockProcessor
from pisa.conf import MIN_TO_SELF_DELAY
from teos.block_processor import BlockProcessor
from teos.conf import MIN_TO_SELF_DELAY
from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appointment_data, generate_keypair, get_config
from test.teos.unit.conftest import get_random_value_hex, generate_dummy_appointment_data, generate_keypair, get_config
from common.constants import LOCATOR_LEN_BYTES, LOCATOR_LEN_HEX
from common.cryptographer import Cryptographer
from common.logger import Logger
from pisa import LOG_PREFIX
from teos import LOG_PREFIX
import common.cryptographer
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=LOG_PREFIX)

View File

@@ -7,15 +7,15 @@ from shutil import rmtree
from copy import deepcopy
from threading import Thread
from pisa.db_manager import DBManager
from pisa.responder import Responder, TransactionTracker
from pisa.block_processor import BlockProcessor
from pisa.chain_monitor import ChainMonitor
from pisa.tools import bitcoin_cli
from teos.db_manager import DBManager
from teos.responder import Responder, TransactionTracker
from teos.block_processor import BlockProcessor
from teos.chain_monitor import ChainMonitor
from teos.tools import bitcoin_cli
from common.constants import LOCATOR_LEN_HEX
from bitcoind_mock.transaction import create_dummy_transaction, create_tx_from_hex
from test.pisa.unit.conftest import generate_block, generate_blocks, get_random_value_hex
from test.teos.unit.conftest import generate_block, generate_blocks, get_random_value_hex
@pytest.fixture(scope="module")

View File

@@ -1,4 +1,4 @@
from pisa.tools import can_connect_to_bitcoind, in_correct_network, bitcoin_cli
from teos.tools import can_connect_to_bitcoind, in_correct_network, bitcoin_cli
from common.tools import check_sha256_hex_format

View File

@@ -4,23 +4,23 @@ from shutil import rmtree
from threading import Thread
from coincurve import PrivateKey
from pisa.watcher import Watcher
from pisa.responder import Responder
from pisa.tools import bitcoin_cli
from pisa.chain_monitor import ChainMonitor
from pisa.db_manager import DBManager
from teos.watcher import Watcher
from teos.responder import Responder
from teos.tools import bitcoin_cli
from teos.chain_monitor import ChainMonitor
from teos.db_manager import DBManager
from test.pisa.unit.conftest import (
from test.teos.unit.conftest import (
generate_blocks,
generate_dummy_appointment,
get_random_value_hex,
generate_keypair,
get_config,
)
from pisa.conf import EXPIRY_DELTA, MAX_APPOINTMENTS
from teos.conf import EXPIRY_DELTA, MAX_APPOINTMENTS
import common.cryptographer
from pisa import LOG_PREFIX
from teos import LOG_PREFIX
from common.logger import Logger
from common.tools import compute_locator
from common.cryptographer import Cryptographer