From 084295b889aaa3adda6aa108c02faf2f2d3cc2ae Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Fri, 24 Jan 2020 14:33:04 +0100 Subject: [PATCH] Adds test for triggering appointment with pissad offline --- test/pisa/e2e/test_basic_e2e.py | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/test/pisa/e2e/test_basic_e2e.py b/test/pisa/e2e/test_basic_e2e.py index b7e231e..dee74b2 100644 --- a/test/pisa/e2e/test_basic_e2e.py +++ b/test/pisa/e2e/test_basic_e2e.py @@ -211,7 +211,7 @@ def test_two_appointment_same_locator_different_penalty(bitcoin_cli, create_txs) assert appointment_info[0].get("penalty_rawtx") == penalty_tx1 -def test_appointment_shutdown_pisa(create_txs, bitcoin_cli): +def test_appointment_shutdown_pisa_trigger_back_online(create_txs, bitcoin_cli): global pisad_process pisa_pid = pisad_process.pid @@ -222,7 +222,6 @@ def test_appointment_shutdown_pisa(create_txs, bitcoin_cli): locator = compute_locator(commitment_tx_id) assert pisa_cli.add_appointment([json.dumps(appointment_data)]) is True - sleep(2) # Restart pisa pisad_process.terminate() @@ -241,7 +240,43 @@ def test_appointment_shutdown_pisa(create_txs, bitcoin_cli): new_addr = bitcoin_cli.getnewaddress() broadcast_transaction_and_mine_block(bitcoin_cli, commitment_tx, new_addr) - # The appointment should have been removed since the penalty_tx was malformed. + # The appointment should have been moved to the Responder + sleep(1) + appointment_info = get_appointment_info(locator) + + assert appointment_info is not None + assert len(appointment_info) == 1 + assert appointment_info[0].get("status") == "dispute_responded" + + +def test_appointment_shutdown_pisa_trigger_while_offline(create_txs, bitcoin_cli): + global pisad_process + + pisa_pid = pisad_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 pisa_cli.add_appointment([json.dumps(appointment_data)]) is True + + # Check that the appointment is still in the Watcher + appointment_info = get_appointment_info(locator) + assert appointment_info is not None + assert len(appointment_info) == 1 + assert appointment_info[0].get("status") == "being_watched" + + # Shutdown and trigger + pisad_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 + + # The appointment should have been moved to the Responder sleep(1) appointment_info = get_appointment_info(locator)