Skip to content

Commit

Permalink
Restructure markdown test report with named sections
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Dec 13, 2023
1 parent a5b34cb commit ef530e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
25 changes: 22 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,26 @@ def manager(rpc):
return ContractManager([], rpc, mine_automatically=True, poll_interval=0.01)


class TestReport:
def __init__(self):
self.sections = {}

def write(self, section_name, content):
if section_name not in self.sections:
self.sections[section_name] = []
self.sections[section_name].append(content)

def finalize_report(self, filename):
with open(filename, "w") as file:
for section, contents in self.sections.items():
file.write(f"## {section}\n")
for content in contents:
file.write(content + "\n")
file.write("\n")


@pytest.fixture(scope="session")
def report_file():
with open("report.md", "w") as file:
yield file
def report():
report_obj = TestReport()
yield report_obj
report_obj.finalize_report("report.md")
24 changes: 10 additions & 14 deletions tests/test_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@


@pytest.mark.parametrize("vault_specs", [V_full, V_no_partial_revault])
def test_vault_recover(vault_specs: VaultSpecs, manager: ContractManager, report_file: TextIOWrapper):
def test_vault_recover(vault_specs: VaultSpecs, manager: ContractManager, report):
vault_description, vault_contract = vault_specs

amount = 20_000
Expand All @@ -61,14 +61,14 @@ def test_vault_recover(vault_specs: VaultSpecs, manager: ContractManager, report
assert out.nValue == amount
assert out.scriptPubKey == OpaqueP2TR(recover_priv_key.pubkey[1:]).get_tr_info().scriptPubKey

report_file.write(format_tx_markdown(V_inst.spending_tx,
f"{vault_description}: Recovery from vault, 1 input [NoRecoveryAuth]"))
report.write(vault_description,
format_tx_markdown(V_inst.spending_tx, "Recovery from vault, 1 input [NoRecoveryAuth]"))

assert len(out_instances) == 0


@pytest.mark.parametrize("vault_specs", [V_full, V_no_partial_revault, V_no_early_recover, V_light])
def test_vault_trigger_and_recover(vault_specs: VaultSpecs, manager: ContractManager, report_file: TextIOWrapper):
def test_vault_trigger_and_recover(vault_specs: VaultSpecs, manager: ContractManager, report):
vault_description, vault_contract = vault_specs

signer = SchnorrSigner(unvault_priv_key)
Expand All @@ -86,17 +86,17 @@ def test_vault_trigger_and_recover(vault_specs: VaultSpecs, manager: ContractMan
[U_inst] = V_inst("trigger", signer=signer,
out_i=0, ctv_hash=ctv_tmpl.get_standard_template_hash(0))

report_file.write(format_tx_markdown(V_inst.spending_tx, f"{vault_description}: Trigger"))
report.write(vault_description, format_tx_markdown(V_inst.spending_tx, "Trigger"))

out_instances = U_inst("recover", out_i=0)

assert len(out_instances) == 0

report_file.write(format_tx_markdown(U_inst.spending_tx, f"{vault_description}: Recovery from trigger"))
report.write(vault_description, format_tx_markdown(U_inst.spending_tx, "Recovery from trigger"))


@pytest.mark.parametrize("vault_specs", [V_full, V_no_partial_revault, V_no_early_recover, V_light])
def test_vault_trigger_and_withdraw(vault_specs: VaultSpecs, rpc: AuthServiceProxy, manager: ContractManager, report_file: TextIOWrapper):
def test_vault_trigger_and_withdraw(vault_specs: VaultSpecs, rpc: AuthServiceProxy, manager: ContractManager, report):
vault_description, vault_contract = vault_specs

signer = SchnorrSigner(unvault_priv_key)
Expand All @@ -114,8 +114,6 @@ def test_vault_trigger_and_withdraw(vault_specs: VaultSpecs, rpc: AuthServicePro
[U_inst] = V_inst("trigger", signer=signer,
out_i=0, ctv_hash=ctv_tmpl.get_standard_template_hash(0))

report_file.write(format_tx_markdown(V_inst.spending_tx, f"{vault_description}: Trigger"))

spend_tx, _ = manager.get_spend_tx(
(U_inst, "withdraw", {"ctv_hash": ctv_tmpl.get_standard_template_hash(0)})
)
Expand All @@ -141,11 +139,11 @@ def test_vault_trigger_and_withdraw(vault_specs: VaultSpecs, rpc: AuthServicePro

manager.spend_and_wait(U_inst, spend_tx)

report_file.write(format_tx_markdown(U_inst.spending_tx, f"{vault_description}: Withdraw [3 outputs]"))
report.write(vault_description, format_tx_markdown(U_inst.spending_tx, "Withdraw [3 outputs]"))


@pytest.mark.parametrize("vault_specs", [V_full, V_no_early_recover])
def test_vault_trigger_with_revault_and_withdraw(vault_specs: VaultSpecs, rpc: AuthServiceProxy, manager: ContractManager, report_file: TextIOWrapper):
def test_vault_trigger_with_revault_and_withdraw(vault_specs: VaultSpecs, rpc: AuthServiceProxy, manager: ContractManager, report):
# get coins on 3 different Vaults, then trigger with partial withdrawal
# one of the vault uses "trigger_with_revault", the others us normal "trigger"

Expand Down Expand Up @@ -187,7 +185,7 @@ def test_vault_trigger_with_revault_and_withdraw(vault_specs: VaultSpecs, rpc: A

[U_inst] = manager.spend_and_wait([V_inst_1, V_inst_2, V_inst_3], spend_tx)

report_file.write(format_tx_markdown(spend_tx, f"{vault_description}: Trigger (with revault) [3 vault inputs]"))
report.write(vault_description, format_tx_markdown(spend_tx, "Trigger (with revault) [3 vault inputs]"))

spend_tx, _ = manager.get_spend_tx(
(U_inst, "withdraw", {"ctv_hash": ctv_tmpl.get_standard_template_hash(0)})
Expand All @@ -210,5 +208,3 @@ def test_vault_trigger_with_revault_and_withdraw(vault_specs: VaultSpecs, rpc: A
mine_blocks(rpc, locktime - 1)

manager.spend_and_wait(U_inst, spend_tx)

report_file.write(format_tx_markdown(U_inst.spending_tx, f"{vault_description}: Withdraw (3 outputs)"))

0 comments on commit ef530e2

Please sign in to comment.