add test case

This commit is contained in:
kdmukai
2025-01-02 18:38:03 -06:00
parent 75ba1e07ec
commit cf83ebe033
+25 -1
View File
@@ -4,7 +4,6 @@ from seedsigner.helpers.qr import QR
from seedsigner.models.decode_qr import DecodeQR, DecodeQRStatus
from seedsigner.models.encode_qr import SeedQrEncoder, CompactSeedQrEncoder
from seedsigner.models.qr_type import QRType
from seedsigner.models.seed import Seed
@@ -104,3 +103,28 @@ def test_compact_seedqr_handles_null_bytes():
# 12-word seed, multiple null bytes in a row
entropy = os.urandom(10) + b'\x00\x00' + os.urandom(4)
run_encode_decode_test(entropy, mnemonic_length=12, qr_type=QRType.SEED__COMPACTSEEDQR)
def test_compact_seedqr_bytes_interpretable_as_str():
"""
Should successfully decode a Compact SeedQR whose bytes can be interpreted as a valid
string. Most Compact SeedQR byte data will raise a UnicodeDecodeError when attempting to
interpret it as a string, but edge cases are possible.
see: Issue #656
"""
# Randomly generated to pass the str.decode() step; 12- and 24-word entropy.
entropy_bytes_tests = [
b'\x00' * 16, # abandon * 11 + about
b'\x12\x15\\1j`3\x0bkL}f\x00ZYK',
b'tv\x1bZjmqN@t\x13\x1aK\\v)',
b'|9\x05\x1aHF9j\xda\xb6v\x05\x08#\x12=',
b"iHK`4\x1a5\xd3\xaf\xd3\xb47htJ.}<\xea\xbf\x88Xh\x01.?R2^\xc2\xb1'",
b'|Z\x11\x1dt\xdd\x97~t&f &G$H|^[\xd3\x9d<q]z\x14.\x11`!\xd1\x91',
b'0\xd4\xb3\\,\xcd\x8d7c/Rp\x0e\xc2\xbb\xe4\x99\xa3=j5,\xcc\x9a[>\x19Z{\ng^',
]
for entropy_bytes in entropy_bytes_tests:
entropy_bytes.decode() # should not raise an exception
mnemonic_length = 12 if len(entropy_bytes) == 16 else 24
run_encode_decode_test(entropy_bytes, mnemonic_length=mnemonic_length, qr_type=QRType.SEED__COMPACTSEEDQR)