Skip to content

test: add tests to cover new Exceptions in arguments.py #2

Open
qlrd wants to merge 4 commits intoodudex:replace_main_code_assertsfrom
qlrd:replace_main_code_asserts
Open

test: add tests to cover new Exceptions in arguments.py #2
qlrd wants to merge 4 commits intoodudex:replace_main_code_assertsfrom
qlrd:replace_main_code_asserts

Conversation

@qlrd
Copy link
Copy Markdown

@qlrd qlrd commented Jul 30, 2025

Add tests for arguments.py

@qlrd qlrd force-pushed the replace_main_code_asserts branch from 926a713 to 036c75e Compare July 30, 2025 15:57
@qlrd qlrd changed the title test: fix exptected exception message in tests/tests/test_bip85.py test: add tests to cover new Exceptions in arguments.py Jul 30, 2025
Comment thread src/embit/descriptor/arguments.py Outdated
@classmethod
def from_string(cls, s: str):
arr = s.split("/")
if len(arr[0]) % 2 != 0:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this check aims to avoid unhandled exceptions with unhexlify, right? Maybe unhexlify could be inside a try/except to also catch other invalid strings and non hex characters.
Also, remembering this lib is made to run on limited devices, I would reduce verbosity to a minimum:
"Invalid fingerprint format"
"Invalid fingerprint length"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, this will allow another tests

@qlrd qlrd force-pushed the replace_main_code_asserts branch 2 times, most recently from 4cadb16 to bf6d69c Compare July 31, 2025 13:56
@qlrd qlrd requested a review from odudex July 31, 2025 22:48
Comment thread src/embit/descriptor/arguments.py Outdated
try:
mfp = unhexlify(arr[0])
except Exception as err:
raise ArgumentError(err) from err
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, did you test in device if raise from is functional in micropython?
If it was not used so for by Krux or Embit, it would be good to test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, good point. Didn't tested. My bad for this lack of attention. I believe micropython do not supoort it right? Maybe something like the below can be better?

Suggested change
raise ArgumentError(err) from err
raise ArgumentError(str(err))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it works the way it is, but it needs to be tested

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that you said, maybe these are theoretical cases, but I believe that in real devices, they may not happen. Maybe it's a dead-code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested in a wondermv, but did not get any of these theoretical errors (IMO because the devices, in a real situations, will never load incorrect fingerprints).

qlrd added 2 commits August 2, 2025 10:12
These tests cover, indirectly, the new exceptions in `test_descriptor`
(covering wrong fingerprints lenghts) as well in `test_taproot`
(covering a try to tweak taproot in a non taproot generated key from a
wpkh descriptor).
@qlrd qlrd force-pushed the replace_main_code_asserts branch from bf6d69c to 502e4f6 Compare August 2, 2025 13:13
@qlrd qlrd requested a review from odudex August 2, 2025 14:18
qlrd added 2 commits August 4, 2025 11:43
…ptree

The current `Descriptor` class do not verify if the instances are
comming from `Key`, `Miniscript` or `TapTree`. This commit add these
checks and raise exceptions when needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants