mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 06:34:19 +01:00
Refactors e2e tests to match the new config approach
This commit is contained in:
@@ -3,19 +3,29 @@ import random
|
|||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from decimal import Decimal, getcontext
|
from decimal import Decimal, getcontext
|
||||||
|
|
||||||
import teos.conf as conf
|
|
||||||
from teos.teosd import main
|
from teos.teosd import main
|
||||||
|
from teos import DEFAULT_CONF
|
||||||
from teos.utils.auth_proxy import AuthServiceProxy
|
from teos.utils.auth_proxy import AuthServiceProxy
|
||||||
|
|
||||||
|
from common.config_loader import ConfigLoader
|
||||||
|
|
||||||
|
|
||||||
getcontext().prec = 10
|
getcontext().prec = 10
|
||||||
END_TIME_DELTA = 10
|
END_TIME_DELTA = 10
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def bitcoin_cli():
|
def bitcoin_cli():
|
||||||
# return AuthServiceProxy("http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST, 18444))
|
btc_connect_params = {k: v["value"] for k, v in DEFAULT_CONF.items() if k.startswith("BTC")}
|
||||||
|
|
||||||
return AuthServiceProxy(
|
return AuthServiceProxy(
|
||||||
"http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST, conf.BTC_RPC_PORT)
|
"http://%s:%s@%s:%d"
|
||||||
|
% (
|
||||||
|
btc_connect_params.get("BTC_RPC_USER"),
|
||||||
|
btc_connect_params.get("BTC_RPC_PASSWD"),
|
||||||
|
btc_connect_params.get("BTC_RPC_CONNECT"),
|
||||||
|
18443,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +61,7 @@ def create_txs(bitcoin_cli):
|
|||||||
|
|
||||||
|
|
||||||
def run_teosd():
|
def run_teosd():
|
||||||
teosd_process = Process(target=main, daemon=True)
|
teosd_process = Process(target=main, kwargs={"command_line_conf": {}}, daemon=True)
|
||||||
teosd_process.start()
|
teosd_process.start()
|
||||||
|
|
||||||
return teosd_process
|
return teosd_process
|
||||||
@@ -116,3 +126,10 @@ def build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return appointment_data
|
return appointment_data
|
||||||
|
|
||||||
|
|
||||||
|
def get_config(data_folder, conf_file_name, default_conf):
|
||||||
|
config_loader = ConfigLoader(data_folder, conf_file_name, default_conf, {})
|
||||||
|
config = config_loader.build_config()
|
||||||
|
|
||||||
|
return config
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import binascii
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
from riemann.tx import Tx
|
from riemann.tx import Tx
|
||||||
|
|
||||||
|
|
||||||
from teos import HOST, PORT
|
from teos import HOST, PORT
|
||||||
from cli import teos_cli
|
|
||||||
from common.blob import Blob
|
from cli import teos_cli, DATA_DIR, DEFAULT_CONF, CONF_FILE_NAME
|
||||||
|
|
||||||
import common.cryptographer
|
import common.cryptographer
|
||||||
|
from common.blob import Blob
|
||||||
from common.logger import Logger
|
from common.logger import Logger
|
||||||
from common.tools import compute_locator
|
from common.tools import compute_locator
|
||||||
from common.appointment import Appointment
|
from common.appointment import Appointment
|
||||||
@@ -20,9 +20,10 @@ from test.teos.e2e.conftest import (
|
|||||||
get_random_value_hex,
|
get_random_value_hex,
|
||||||
create_penalty_tx,
|
create_penalty_tx,
|
||||||
run_teosd,
|
run_teosd,
|
||||||
|
get_config,
|
||||||
)
|
)
|
||||||
from cli import config as cli_conf
|
|
||||||
|
|
||||||
|
cli_config = get_config(DATA_DIR, CONF_FILE_NAME, DEFAULT_CONF)
|
||||||
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
|
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
|
||||||
|
|
||||||
# We'll use teos_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
|
||||||
@@ -43,7 +44,7 @@ def broadcast_transaction_and_mine_block(bitcoin_cli, commitment_tx, addr):
|
|||||||
def get_appointment_info(locator):
|
def get_appointment_info(locator):
|
||||||
# Check that the justice has been triggered (the appointment has moved from Watcher to Responder)
|
# 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
|
sleep(1) # Let's add a bit of delay so the state can be updated
|
||||||
return teos_cli.get_appointment(locator)
|
return teos_cli.get_appointment(locator, cli_config)
|
||||||
|
|
||||||
|
|
||||||
def test_appointment_life_cycle(bitcoin_cli, create_txs):
|
def test_appointment_life_cycle(bitcoin_cli, create_txs):
|
||||||
@@ -52,7 +53,7 @@ def test_appointment_life_cycle(bitcoin_cli, create_txs):
|
|||||||
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
|
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
|
||||||
locator = compute_locator(commitment_tx_id)
|
locator = compute_locator(commitment_tx_id)
|
||||||
|
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment_data)], cli_config) is True
|
||||||
|
|
||||||
appointment_info = get_appointment_info(locator)
|
appointment_info = get_appointment_info(locator)
|
||||||
assert appointment_info is not None
|
assert appointment_info is not None
|
||||||
@@ -102,7 +103,7 @@ def test_appointment_malformed_penalty(bitcoin_cli, create_txs):
|
|||||||
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, mod_penalty_tx.hex())
|
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, mod_penalty_tx.hex())
|
||||||
locator = compute_locator(commitment_tx_id)
|
locator = compute_locator(commitment_tx_id)
|
||||||
|
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment_data)], cli_config) is True
|
||||||
|
|
||||||
# Broadcast the commitment transaction and mine a block
|
# Broadcast the commitment transaction and mine a block
|
||||||
new_addr = bitcoin_cli.getnewaddress()
|
new_addr = bitcoin_cli.getnewaddress()
|
||||||
@@ -132,7 +133,7 @@ def test_appointment_wrong_key(bitcoin_cli, create_txs):
|
|||||||
appointment = Appointment.from_dict(appointment_data)
|
appointment = Appointment.from_dict(appointment_data)
|
||||||
|
|
||||||
teos_pk, cli_sk, cli_pk_der = teos_cli.load_keys(
|
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")
|
cli_config.get("TEOS_PUBLIC_KEY"), cli_config.get("CLI_PRIVATE_KEY"), cli_config.get("CLI_PUBLIC_KEY")
|
||||||
)
|
)
|
||||||
hex_pk_der = binascii.hexlify(cli_pk_der)
|
hex_pk_der = binascii.hexlify(cli_pk_der)
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ def test_appointment_wrong_key(bitcoin_cli, create_txs):
|
|||||||
data = {"appointment": appointment.to_dict(), "signature": signature, "public_key": hex_pk_der.decode("utf-8")}
|
data = {"appointment": appointment.to_dict(), "signature": signature, "public_key": hex_pk_der.decode("utf-8")}
|
||||||
|
|
||||||
# Send appointment to the server.
|
# Send appointment to the server.
|
||||||
response = teos_cli.post_appointment(data)
|
response = teos_cli.post_appointment(data, cli_config)
|
||||||
response_json = teos_cli.process_post_appointment_response(response)
|
response_json = teos_cli.process_post_appointment_response(response)
|
||||||
|
|
||||||
# Check that the server has accepted the appointment
|
# Check that the server has accepted the appointment
|
||||||
@@ -176,8 +177,8 @@ def test_two_identical_appointments(bitcoin_cli, create_txs):
|
|||||||
locator = compute_locator(commitment_tx_id)
|
locator = compute_locator(commitment_tx_id)
|
||||||
|
|
||||||
# Send the appointment twice
|
# Send the appointment twice
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment_data)], cli_config) is True
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment_data)], cli_config) is True
|
||||||
|
|
||||||
# Broadcast the commitment transaction and mine a block
|
# Broadcast the commitment transaction and mine a block
|
||||||
new_addr = bitcoin_cli.getnewaddress()
|
new_addr = bitcoin_cli.getnewaddress()
|
||||||
@@ -210,8 +211,8 @@ def test_two_appointment_same_locator_different_penalty(bitcoin_cli, create_txs)
|
|||||||
appointment2_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx2)
|
appointment2_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx2)
|
||||||
locator = compute_locator(commitment_tx_id)
|
locator = compute_locator(commitment_tx_id)
|
||||||
|
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment1_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment1_data)], cli_config) is True
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment2_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment2_data)], cli_config) is True
|
||||||
|
|
||||||
# Broadcast the commitment transaction and mine a block
|
# Broadcast the commitment transaction and mine a block
|
||||||
new_addr = bitcoin_cli.getnewaddress()
|
new_addr = bitcoin_cli.getnewaddress()
|
||||||
@@ -238,7 +239,7 @@ def test_appointment_shutdown_teos_trigger_back_online(create_txs, bitcoin_cli):
|
|||||||
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
|
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
|
||||||
locator = compute_locator(commitment_tx_id)
|
locator = compute_locator(commitment_tx_id)
|
||||||
|
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment_data)], cli_config) is True
|
||||||
|
|
||||||
# Restart teos
|
# Restart teos
|
||||||
teosd_process.terminate()
|
teosd_process.terminate()
|
||||||
@@ -276,7 +277,7 @@ def test_appointment_shutdown_teos_trigger_while_offline(create_txs, bitcoin_cli
|
|||||||
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
|
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
|
||||||
locator = compute_locator(commitment_tx_id)
|
locator = compute_locator(commitment_tx_id)
|
||||||
|
|
||||||
assert teos_cli.add_appointment([json.dumps(appointment_data)]) is True
|
assert teos_cli.add_appointment([json.dumps(appointment_data)], cli_config) is True
|
||||||
|
|
||||||
# Check that the appointment is still in the Watcher
|
# Check that the appointment is still in the Watcher
|
||||||
appointment_info = get_appointment_info(locator)
|
appointment_info = get_appointment_info(locator)
|
||||||
|
|||||||
Reference in New Issue
Block a user