Repository navigation
Fix CallDecoder.decode_inputs crash and Optional return hints #68
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
Open
JonoPrest
wants to merge
2
commits into
main
Choose a base branch
from
fix/call-decoder-inputs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| pytest: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.12" | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - name: Build and install extension | ||
| run: | | ||
| python -m venv .venv | ||
| .venv/bin/pip install maturin pytest | ||
| .venv/bin/maturin develop | ||
| - name: Run tests | ||
| run: .venv/bin/pytest -q tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """Offline tests for the Python CallDecoder wrapper (no network needed).""" | ||
|
|
||
| import asyncio | ||
|
|
||
| import pytest | ||
|
|
||
| import hypersync | ||
|
|
||
| # transfer(0x000000000000000000000000000000000000dEaD, 1000) | ||
| _TRANSFER_INPUT = ( | ||
| "0xa9059cbb" | ||
| "000000000000000000000000000000000000000000000000000000000000dead" | ||
| "00000000000000000000000000000000000000000000000000000000000003e8" | ||
| ) | ||
| _UNKNOWN_INPUT = "0xdeadbeef" | ||
|
|
||
|
|
||
| def _decoder() -> hypersync.CallDecoder: | ||
| return hypersync.CallDecoder(["transfer(address to, uint256 amount)"]) | ||
|
|
||
|
|
||
| def _assert_shape(out): | ||
| assert len(out) == 2 | ||
| assert out[0] is not None and len(out[0]) == 2 | ||
| # Unmatched selectors decode to None. | ||
| assert out[1] is None | ||
|
|
||
|
|
||
| def test_decode_inputs_sync(): | ||
| _assert_shape(_decoder().decode_inputs_sync([_TRANSFER_INPUT, _UNKNOWN_INPUT])) | ||
|
|
||
|
|
||
| def test_decode_inputs_async(): | ||
| _assert_shape(asyncio.run(_decoder().decode_inputs([_TRANSFER_INPUT, _UNKNOWN_INPUT]))) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "bad_input", | ||
| [ | ||
| "0x", # plain ETH transfer | ||
| "0xa905", # shorter than a selector | ||
| "0xa9059cbb0000", # known selector, truncated args | ||
| "not hex", | ||
| ], | ||
| ) | ||
| def test_decode_inputs_invalid_calldata_is_none(bad_input): | ||
| assert _decoder().decode_inputs_sync([bad_input]) == [None] | ||
| assert asyncio.run(_decoder().decode_inputs([bad_input])) == [None] | ||
|
|
||
|
|
||
| @pytest.mark.xfail( | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| strict=True, | ||
| reason="hypersync-client's CallDecoder::decode_input doesn't strip the 4-byte selector; " | ||
| "remove once the Rust fix is released and bumped here", | ||
| ) | ||
| def test_decode_inputs_values(): | ||
| to, amount = _decoder().decode_inputs_sync([_TRANSFER_INPUT])[0] | ||
| assert to.val.lower() == "0x000000000000000000000000000000000000dead" | ||
| assert amount.val == 1000 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.