remove msas (always allowed) remove unsort_ms (always allowed) rework fake_txn # Conflicts: # cli/signit.py # releases/ChangeLog.md # releases/History-Mk4.md # releases/Next-ChangeLog.md # releases/signatures.txt # shared/actions.py # shared/address_explorer.py # shared/auth.py # shared/backups.py # shared/chains.py # shared/decoders.py # shared/descriptor.py # shared/display.py # shared/export.py # shared/flow.py # shared/lcd_display.py # shared/multisig.py # shared/nfc.py # shared/notes.py # shared/nvstore.py # shared/ownership.py # shared/paper.py # shared/psbt.py # shared/qrs.py # shared/seed.py # shared/serializations.py # shared/utils.py # shared/ux.py # shared/ux_mk4.py # shared/ux_q1.py # shared/version.py # shared/wallet.py # shared/xor_seed.py # stm32/COLDCARD_MK4/file_time.c # stm32/COLDCARD_Q1/file_time.c # stm32/MK4-Makefile # stm32/Q1-Makefile # testing/conftest.py # testing/helpers.py # testing/test_address_explorer.py # testing/test_backup.py # testing/test_bbqr.py # testing/test_export.py # testing/test_msg.py # testing/test_multisig.py # testing/test_notes.py # testing/test_ownership.py # testing/test_sign.py # testing/test_unit.py # testing/txn.py
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
# (c) Copyright 2025 by Coinkite Inc. This file is covered by license found in COPYING-CC.
|
|
#
|
|
from uio import BytesIO
|
|
from serializations import ser_push_data, ser_string_vector, deser_string_vector
|
|
from serializations import ser_compact_size, deser_compact_size, disassemble
|
|
|
|
test_data = [
|
|
# data, result
|
|
(55*b"a", b'7aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
(75*b"a", b'Kaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
(76*b"a", b'LLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
(77*b"a", b'LMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
(254*b"a", b'L\xfe' + (254 * b"a")),
|
|
(255*b"a", b'L\xff' + (255 * b"a")),
|
|
(256*b"a", b'M\x00\x01' + (256 * b"a")),
|
|
(500*b"a", b'M\xf4\x01' + (500 * b"a")),
|
|
(65535*b"a", b'M\xff\xff' + (65535 * b"a")),
|
|
]
|
|
|
|
for i, (data, result) in enumerate(test_data):
|
|
assert ser_push_data(data) == result, i
|
|
d, _ = list(disassemble(result))[0]
|
|
assert d == data
|
|
|
|
try:
|
|
# PUSHDATA 4 not implemented
|
|
ser_push_data(65536 * b"a")
|
|
raise RuntimeError
|
|
except AssertionError: pass
|
|
|
|
# test serialization/deserialization
|
|
# all M/N combinations
|
|
V = range(1, 16)
|
|
for i, v1 in enumerate(V):
|
|
for j in range(i+1, len(V)):
|
|
M, N = v1, V[j]
|
|
# number of pubkeys times 1 pushdata + 33 pubkey = 34 * N
|
|
# +1 M
|
|
# +1 N
|
|
# +1 OP_CHECKMULTISIG
|
|
ms_script_len = (34 * N) + 1 + 1 + 1
|
|
vec = [b"\x00"] + (M * [71*b"s"]) + [ms_script_len*b"w"]
|
|
assert vec == deser_string_vector(BytesIO(ser_string_vector(vec)))
|
|
|
|
|
|
for i in [253, 0x10000, 0x100000000]:
|
|
for j in [-1, 0, 1]:
|
|
num = i + j
|
|
x = ser_compact_size(num)
|
|
|
|
assert num == deser_compact_size(BytesIO(x))
|
|
|
|
# EOF
|