mirror of
https://github.com/aljazceru/python-teos.git
synced 2026-02-04 06:04:26 +01:00
Sets add_appointment_endpoint from / to /add_appointment for consistency
Also passes the base_url to add_appointment and get_appointment and builds the full endpoint inside (also for consistency)
This commit is contained in:
@@ -24,14 +24,9 @@ from test.teos.e2e.conftest import (
|
||||
cli_config = get_config(DATA_DIR, CONF_FILE_NAME, DEFAULT_CONF)
|
||||
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
|
||||
# # appointment
|
||||
# teos_cli.teos_api_server = "http://{}".format(HOST)
|
||||
# teos_cli.teos_api_port = PORT
|
||||
|
||||
teos_base_endpoint = "http://{}:{}".format(cli_config.get("TEOS_SERVER"), cli_config.get("TEOS_PORT"))
|
||||
teos_add_appointment_endpoint = teos_base_endpoint
|
||||
teos_get_appointment_endpoint = teos_base_endpoint + "/get_appointment"
|
||||
teos_add_appointment_endpoint = "{}/add_appointment".format(teos_base_endpoint)
|
||||
teos_get_appointment_endpoint = "{}/get_appointment".format(teos_base_endpoint)
|
||||
|
||||
# Run teosd
|
||||
teosd_process = run_teosd()
|
||||
@@ -46,7 +41,7 @@ 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 teos_cli.get_appointment(locator, teos_get_appointment_endpoint)
|
||||
return teos_cli.get_appointment(locator, teos_base_endpoint)
|
||||
|
||||
|
||||
def test_appointment_life_cycle(bitcoin_cli, create_txs):
|
||||
@@ -55,7 +50,7 @@ def test_appointment_life_cycle(bitcoin_cli, create_txs):
|
||||
appointment_data = build_appointment_data(bitcoin_cli, commitment_tx_id, penalty_tx)
|
||||
locator = compute_locator(commitment_tx_id)
|
||||
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_base_endpoint, cli_config) is True
|
||||
|
||||
appointment_info = get_appointment_info(locator)
|
||||
assert appointment_info is not None
|
||||
@@ -105,7 +100,7 @@ def test_appointment_malformed_penalty(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 teos_cli.add_appointment([json.dumps(appointment_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_base_endpoint, cli_config) is True
|
||||
|
||||
# Broadcast the commitment transaction and mine a block
|
||||
new_addr = bitcoin_cli.getnewaddress()
|
||||
@@ -143,7 +138,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")}
|
||||
|
||||
# Send appointment to the server.
|
||||
response = teos_cli.post_appointment(data, teos_add_appointment_endpoint)
|
||||
response = teos_cli.post_appointment(data, teos_base_endpoint)
|
||||
response_json = teos_cli.process_post_appointment_response(response)
|
||||
|
||||
# Check that the server has accepted the appointment
|
||||
@@ -179,8 +174,8 @@ def test_two_identical_appointments(bitcoin_cli, create_txs):
|
||||
locator = compute_locator(commitment_tx_id)
|
||||
|
||||
# Send the appointment twice
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_base_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_base_endpoint, cli_config) is True
|
||||
|
||||
# Broadcast the commitment transaction and mine a block
|
||||
new_addr = bitcoin_cli.getnewaddress()
|
||||
@@ -213,8 +208,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)
|
||||
locator = compute_locator(commitment_tx_id)
|
||||
|
||||
assert teos_cli.add_appointment([json.dumps(appointment1_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment2_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment1_data)], teos_base_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment2_data)], teos_base_endpoint, cli_config) is True
|
||||
|
||||
# Broadcast the commitment transaction and mine a block
|
||||
new_addr = bitcoin_cli.getnewaddress()
|
||||
@@ -241,7 +236,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)
|
||||
locator = compute_locator(commitment_tx_id)
|
||||
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_base_endpoint, cli_config) is True
|
||||
|
||||
# Restart teos
|
||||
teosd_process.terminate()
|
||||
@@ -279,7 +274,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)
|
||||
locator = compute_locator(commitment_tx_id)
|
||||
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_add_appointment_endpoint, cli_config) is True
|
||||
assert teos_cli.add_appointment([json.dumps(appointment_data)], teos_base_endpoint, cli_config) is True
|
||||
|
||||
# Check that the appointment is still in the Watcher
|
||||
appointment_info = get_appointment_info(locator)
|
||||
|
||||
@@ -28,6 +28,10 @@ from common.constants import LOCATOR_LEN_BYTES
|
||||
|
||||
|
||||
TEOS_API = "http://{}:{}".format(HOST, PORT)
|
||||
add_appointment_endpoint = "{}/add_appointment".format(TEOS_API)
|
||||
get_appointment_endpoint = "{}/get_appointment".format(TEOS_API)
|
||||
get_all_appointment_endpoint = "{}/get_all_appointments".format(TEOS_API)
|
||||
|
||||
MULTIPLE_APPOINTMENTS = 10
|
||||
|
||||
appointments = []
|
||||
@@ -68,7 +72,7 @@ def new_appt_data():
|
||||
|
||||
|
||||
def add_appointment(new_appt_data):
|
||||
r = requests.post(url=TEOS_API, json=json.dumps(new_appt_data), timeout=5)
|
||||
r = requests.post(url=add_appointment_endpoint, json=json.dumps(new_appt_data), timeout=5)
|
||||
|
||||
if r.status_code == 200:
|
||||
appointments.append(new_appt_data["appointment"])
|
||||
@@ -88,7 +92,7 @@ def test_add_appointment(run_api, run_bitcoind, new_appt_data):
|
||||
|
||||
|
||||
def test_request_random_appointment():
|
||||
r = requests.get(url=TEOS_API + "/get_appointment?locator=" + get_random_value_hex(LOCATOR_LEN_BYTES))
|
||||
r = requests.get(url="{}?locator={}".format(get_appointment_endpoint, get_random_value_hex(LOCATOR_LEN_BYTES)))
|
||||
assert r.status_code == 200
|
||||
|
||||
received_appointments = json.loads(r.content)
|
||||
@@ -123,7 +127,7 @@ def test_add_too_many_appointment(new_appt_data):
|
||||
|
||||
|
||||
def test_get_all_appointments_watcher():
|
||||
r = requests.get(url=TEOS_API + "/get_all_appointments")
|
||||
r = requests.get(url=get_all_appointment_endpoint)
|
||||
assert r.status_code == 200 and r.reason == "OK"
|
||||
|
||||
received_appointments = json.loads(r.content)
|
||||
@@ -147,7 +151,7 @@ def test_get_all_appointments_responder():
|
||||
generate_blocks(6)
|
||||
|
||||
# Get all appointments
|
||||
r = requests.get(url=TEOS_API + "/get_all_appointments")
|
||||
r = requests.get(url=get_all_appointment_endpoint)
|
||||
received_appointments = json.loads(r.content)
|
||||
|
||||
# Make sure there is not pending locator in the watcher
|
||||
@@ -164,7 +168,7 @@ def test_request_appointment_watcher(new_appt_data):
|
||||
assert r.status_code == 200
|
||||
|
||||
# Next we can request it
|
||||
r = requests.get(url=TEOS_API + "/get_appointment?locator=" + new_appt_data["appointment"]["locator"])
|
||||
r = requests.get(url="{}?locator={}".format(get_appointment_endpoint, new_appt_data["appointment"]["locator"]))
|
||||
assert r.status_code == 200
|
||||
|
||||
# Each locator may point to multiple appointments, check them all
|
||||
@@ -173,7 +177,7 @@ def test_request_appointment_watcher(new_appt_data):
|
||||
# Take the status out and leave the received appointments ready to compare
|
||||
appointment_status = [appointment.pop("status") for appointment in received_appointments]
|
||||
|
||||
# Check that the appointment is within the received appoints
|
||||
# Check that the appointment is within the received appointments
|
||||
assert new_appt_data["appointment"] in received_appointments
|
||||
|
||||
# Check that all the appointments are being watched
|
||||
@@ -191,7 +195,7 @@ def test_request_appointment_responder(new_appt_data):
|
||||
# Generate a block to trigger the watcher
|
||||
generate_block()
|
||||
|
||||
r = requests.get(url=TEOS_API + "/get_appointment?locator=" + new_appt_data["appointment"]["locator"])
|
||||
r = requests.get(url="{}?locator={}".format(get_appointment_endpoint, new_appt_data["appointment"]["locator"]))
|
||||
assert r.status_code == 200
|
||||
|
||||
received_appointments = json.loads(r.content)
|
||||
|
||||
Reference in New Issue
Block a user