Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||
| # https://github.com/trezor/python-mnemonic/blob/master/mnemonic/mnemonic.py | ||
| # https://ethereum.stackexchange.com/a/72871/59887 | ||
| def mnemonic_to_bip39seed(mnemonic: str, passphrase: str = ""): | ||
| if not Mnemonic(BIP39_LANGUAGE).check(mnemonic): |
There was a problem hiding this comment.
In our Mnemonic class, we already have this check:
class Mnemonic:
def __init__(self, text: str) -> None:
text = text.strip()
self.assert_text_is_valid(text)
self.text = text
@classmethod
def assert_text_is_valid(cls, text: str) -> None:
if not cls.is_text_valid(text):
raise InvalidMnemonicError()
However, seems fine, now you also add the check at a lower level.
There was a problem hiding this comment.
Let's add a unit test for this.
There was a problem hiding this comment.
Let's also fix the link in the comment, it does not work anymore.
https://github.com/trezor/python-mnemonic/blob/master/src/mnemonic/mnemonic.py
There was a problem hiding this comment.
Added a text and fixed the link.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces small fixes and extra validations across the wallet modules. Key changes include:
- Trimming whitespace in hex-string conversions for validator and user secret keys.
- Adding new exception handling for negative address index and invalid mnemonics.
- Enhancing test coverage by including cases for address index errors and mnemonic validation.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| multiversx_sdk/wallet/validator_keys.py | Added .strip() to hex string before conversion |
| multiversx_sdk/wallet/user_keys.py | Added logging and refined exception handling in the verify method |
| multiversx_sdk/wallet/mnemonic_test.py | Updated tests to validate negative address index and invalid mnemonics |
| multiversx_sdk/wallet/mnemonic.py | Integrated address index validation with new error raised |
| multiversx_sdk/wallet/errors.py | Introduced InvalidAddressIndexError with a custom message |
| multiversx_sdk/wallet/core.py | Added a mnemonic check to raise error on invalid mnemonics |
| logger.info(str(e)) | ||
| return False | ||
| except Exception as e: | ||
| logger.info(str(e)) |
There was a problem hiding this comment.
[nitpick] Consider logging CryptoError exceptions at a higher severity level (e.g., error) rather than info since these represent failed verifications.
| logger.info(str(e)) | |
| return False | |
| except Exception as e: | |
| logger.info(str(e)) | |
| logger.error(str(e)) | |
| return False | |
| except Exception as e: | |
| logger.error(str(e)) |
Added a few extra checks when working with mnemonics:
When instantiating a
ValidatorSecretKeyfrom a hex string, ensure there are no whitespaces.