Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test with 512 inputs #221

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ static size_t cx_hash_ripemd160(const uint8_t *in, size_t in_len, uint8_t *out,
if (out_len < CX_RIPEMD160_SIZE) {
return 0;
}
cx_ripemd160_init_no_throw((cx_ripemd160_t *) &G_cx);
cx_ripemd160_update((cx_ripemd160_t *) &G_cx, in, in_len);
cx_ripemd160_final((cx_ripemd160_t *) &G_cx, out);
LEDGER_ASSERT(cx_ripemd160_init_no_throw((cx_ripemd160_t *) &G_cx) == CX_OK, "It never fails");
LEDGER_ASSERT(cx_ripemd160_update((cx_ripemd160_t *) &G_cx, in, in_len) == CX_OK,
"It never fails");
LEDGER_ASSERT(cx_ripemd160_final((cx_ripemd160_t *) &G_cx, out) == CX_OK, "It never fails");
explicit_bzero((cx_ripemd160_t *) &G_cx, sizeof(cx_sha256_t));
return CX_RIPEMD160_SIZE;
}
Expand Down
16 changes: 8 additions & 8 deletions test_utils/txmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ def createPsbt(wallet: WalletPolicy, input_amounts: List[int], output_amounts: L
psbt.inputs[i].hd_keypaths[input_key] = KeyOriginInfo(
master_key_fpr, path)
elif is_taproot:
tweaked_key = get_taproot_output_key(input_key)
psbt.inputs[i].tap_bip32_paths[tweaked_key] = (
list(), KeyOriginInfo(master_key_fpr, path))
internal_key = input_key[1:]
psbt.inputs[i].tap_bip32_paths[internal_key] = (
{}, KeyOriginInfo(master_key_fpr, path))
else:
raise RuntimeError("Unexpected state: unknown transaction type")

Expand All @@ -224,12 +224,12 @@ def createPsbt(wallet: WalletPolicy, input_amounts: List[int], output_amounts: L
psbt.outputs[i].hd_keypaths[output_key] = KeyOriginInfo(
master_key_fpr, path)
elif is_taproot:
tweaked_key = get_taproot_output_key(output_key)
psbt.outputs[i].tap_bip32_paths[tweaked_key] = (
list(), KeyOriginInfo(master_key_fpr, path))
internal_key = output_key[1:]
psbt.outputs[i].tap_bip32_paths[internal_key] = (
{}, KeyOriginInfo(master_key_fpr, path))

psbt.outputs[i].tap_bip32_paths[tweaked_key] = (
list(), KeyOriginInfo(master_key_fpr, path))
psbt.outputs[i].tap_bip32_paths[internal_key] = (
{}, KeyOriginInfo(master_key_fpr, path))

psbt.tx = tx

Expand Down
20 changes: 12 additions & 8 deletions tests/test_sign_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,16 +709,13 @@ def test_sign_psbt_singlesig_large_amount(client: Client, comm: SpeculosClient,

@pytest.mark.timeout(0) # disable timeout
@has_automation("automations/sign_with_default_wallet_accept.json")
def test_sign_psbt_singlesig_wpkh_512to256(client: Client, enable_slow_tests: bool):
def test_sign_psbt_singlesig_tr_512to256(client: Client, enable_slow_tests: bool):
# PSBT for a transaction with 512 inputs and 256 outputs (maximum currently supported in the app)
# Very slow test (esp. with DEBUG enabled), so disabled unless the --enableslowtests option is used

if not enable_slow_tests:
pytest.skip()

n_inputs = 512
n_outputs = 256

wallet = WalletPolicy(
"",
"tr(@0/**)",
Expand All @@ -727,10 +724,17 @@ def test_sign_psbt_singlesig_wpkh_512to256(client: Client, enable_slow_tests: bo
],
)

n_inputs = 512
n_outputs = 256

input_amounts = [10000 + 10000 * i for i in range(n_inputs)]
total_amount = sum(input_amounts)
output_amounts = [(total_amount // n_outputs) - 10 for _ in range(n_outputs)]

psbt = txmaker.createPsbt(
wallet,
[10000 + 10000 * i for i in range(n_inputs)],
[999 + 99 * i for i in range(n_outputs)],
input_amounts,
output_amounts,
[i == 42 for i in range(n_outputs)]
)

Expand All @@ -739,7 +743,7 @@ def test_sign_psbt_singlesig_wpkh_512to256(client: Client, enable_slow_tests: bo
assert len(result) == n_inputs


def ux_thread_acept_prompt_stax(speculos_client: SpeculosClient, all_events: List[dict]):
def ux_thread_accept_prompt_stax(speculos_client: SpeculosClient, all_events: List[dict]):
"""Completes the signing flow always going right and accepting at the appropriate time, while collecting all the events in all_events."""

while True:
Expand Down Expand Up @@ -772,7 +776,7 @@ def test_sign_psbt_fail_11_changes(client: Client, comm: SpeculosClient, model:
all_events: List[dict] = []

if model == "stax":
x = threading.Thread(target=ux_thread_acept_prompt_stax, args=[comm, all_events])
x = threading.Thread(target=ux_thread_accept_prompt_stax, args=[comm, all_events])

x.start()
with pytest.raises(NotSupportedError):
Expand Down
33 changes: 0 additions & 33 deletions tests/test_sign_psbt_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,39 +481,6 @@ def test_sign_psbt_singlesig_large_amount_v1(client: Client, comm: SpeculosClien
assert parsed_events["amounts"][0] == format_amount(CURRENCY_TICKER, out_amt)


@pytest.mark.timeout(0) # disable timeout
@has_automation("automations/sign_with_default_wallet_accept.json")
def test_sign_psbt_singlesig_wpkh_512to256_v1(client: Client, enable_slow_tests: bool):
# PSBT for a transaction with 512 inputs and 256 outputs (maximum currently supported in the app)
# Very slow test (esp. with DEBUG enabled), so disabled unless the --enableslowtests option is used

if not enable_slow_tests:
pytest.skip()

n_inputs = 512
n_outputs = 256

wallet = WalletPolicy(
"",
"tr(@0)",
[
"[f5acc2fd/86'/1'/0']tpubDDKYE6BREvDsSWMazgHoyQWiJwYaDDYPbCFjYxN3HFXJP5fokeiK4hwK5tTLBNEDBwrDXn8cQ4v9b2xdW62Xr5yxoQdMu1v6c7UDXYVH27U/**"
],
version=WalletType.WALLET_POLICY_V1
)

psbt = txmaker.createPsbt(
wallet,
[10000 + 10000 * i for i in range(n_inputs)],
[999 + 99 * i for i in range(n_outputs)],
[i == 42 for i in range(n_outputs)]
)

result = client.sign_psbt(psbt, wallet, None)

assert len(result) == n_inputs


def ux_thread_accept_prompt_stax(speculos_client: SpeculosClient, all_events: List[dict]):
"""Completes the signing flow always going right and accepting at the appropriate time, while collecting all the events in all_events."""

Expand Down
Loading