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

Add unit tests for eth address #571

Merged
merged 9 commits into from
Mar 27, 2024

Conversation

tcoratger
Copy link
Collaborator

Description

This pull request adds unit tests for Ethereum address conversion in the starknet-core crate.

Changes

  • Added new unit tests.
  • The new unit test reads addresses from a JSON file and tests the conversion of addresses to EthAddress types.

@xJonathanLEI
Copy link
Owner

xJonathanLEI commented Mar 27, 2024

While having more tests is generally better, I'm not sure if I get the point of adding these. The tests added are more of testing hex::decode than our own method it seems. I've decided to not merge this, as I feel like it adds unnecessary complexity to the test suite.

@tcoratger
Copy link
Collaborator Author

While having more tests is generally better, I'm not sure if I get the point of adding these. The tests added are more of testing hex::decode than our own method it seems. I've decided to not merge this, as I feel like it adds unnecessary complexity to the test suite.

@xJonathanLEI Here there were several objectives:

  • Carry out tests with more than a single address to eliminate any possibility of bugs and omissions in the test suite (with the list proposed normally this risk is eliminated). The address formats taken into account are for example:
    • With prefix 0x
    • Without prefix
    • Null address
    • ...
  • I don't think we test the hex decode method more than the repo functions. Indeed, there is a path which can be more or less long to generically transform the json addresses which can have different formats but this expected is always compared directly to the repo method itself without transformation. This is the case for example when we do assert_eq!(EthAddress::from_hex(address).unwrap(), eth_address); where we obtain a strict test between a method of the repo (from_hex) and a manual transformation to arrive at a bytes array. This ensures our method meets what we expect for it.
  • There are also the following additions:
    • Obtaining Eth addresses from Felt (which was not previously tested)
    • Test of the error for an address which is beyond the acceptable range (overflow which was not tested before)

@xJonathanLEI
Copy link
Owner

Right. I guess what I meant is that it's better to target specific scenarios directly instead of feeding a list of random addresses. The JSON list thingy feels like you're fuzzing it, but it's just a very simple decoding method that I think we can simply test the edge cases directly.

@tcoratger
Copy link
Collaborator Author

Right. I guess what I meant is that it's better to target specific scenarios directly instead of feeding a list of random addresses. The JSON list thingy feels like you're fuzzing it, but it's just a very simple decoding method that I think we can simply test the edge cases directly.

@xJonathanLEI No problem, let me know if you still want to close it or I can just replace the "fuzzing" by 2-3 edge cases. Both are fine to me (I've no problem with closing a PR, always a way to learn something).

@xJonathanLEI
Copy link
Owner

Specific edge cases are surely desirable. Thanks!

@xJonathanLEI xJonathanLEI reopened this Mar 27, 2024
@tcoratger
Copy link
Collaborator Author

Specific edge cases are surely desirable. Thanks!

@xJonathanLEI Fixed

@xJonathanLEI
Copy link
Owner

Rebased on master for CI and fixed missing WASM test annotation.

Copy link
Owner

@xJonathanLEI xJonathanLEI left a comment

Choose a reason for hiding this comment

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

LGTM

@xJonathanLEI xJonathanLEI merged commit 350c45a into xJonathanLEI:master Mar 27, 2024
26 checks passed
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