-
Notifications
You must be signed in to change notification settings - Fork 50
fix(precompiles): export solo precompile from ethers entrypoint #323
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1490be6
fix(precompiles): export solo precompile from ethers entrypoint
alexander-sei 4454839
test(precompiles): guard barrel parity across entrypoints
alexander-sei 20a5829
test(precompiles): compare factory names, not just factory count
alexander-sei 7045788
test(precompiles): keep factory and ABI name patterns symmetric
alexander-sei 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,7 @@ | ||
| --- | ||
| '@sei-js/precompiles': minor | ||
| --- | ||
|
|
||
| Export the Solo precompile from the `ethers` entrypoint. `ETHERS_SOLO_PRECOMPILE_ABI` and `getSoloPrecompileEthersV6Contract` were implemented but never re-exported from `src/ethers/index.ts`, so they were unreachable from the `@sei-js/precompiles` package root. | ||
|
|
||
| The `@sei-js/precompiles/ethers` subpath shown in the doc examples remains unresolvable and is unchanged here — the package still publishes no `exports` map. That is tracked separately. |
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,41 @@ | ||
| import * as ethersBarrel from '../ethers'; | ||
| import * as precompilesBarrel from '../precompiles'; | ||
| import * as viemBarrel from '../viem'; | ||
|
|
||
| const precompileNamesFrom = (barrel: Record<string, unknown>, prefix: '' | 'ETHERS_' | 'VIEM_'): string[] => { | ||
| const pattern = new RegExp(`^${prefix}([A-Z0-9]+)_PRECOMPILE_ABI$`); | ||
|
|
||
| return Object.keys(barrel) | ||
| .map((key) => pattern.exec(key)?.[1]) | ||
| .filter((name): name is string => name !== undefined) | ||
| .sort(); | ||
| }; | ||
|
|
||
| describe('Precompile barrel parity', () => { | ||
| const precompileNames = precompileNamesFrom(precompilesBarrel, ''); | ||
| const ethersNames = precompileNamesFrom(ethersBarrel, 'ETHERS_'); | ||
| const viemNames = precompileNamesFrom(viemBarrel, 'VIEM_'); | ||
|
|
||
| // Without this the three comparisons below would pass on three empty sets if the | ||
| // ABI naming convention ever changes out from under the pattern above. | ||
| it('discovers precompiles in the base barrel', () => { | ||
| expect(precompileNames.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('exposes the same precompiles from the ethers barrel as the base barrel', () => { | ||
| expect(ethersNames).toEqual(precompileNames); | ||
| }); | ||
|
|
||
| it('exposes the same precompiles from the viem barrel as the base barrel', () => { | ||
| expect(viemNames).toEqual(precompileNames); | ||
| }); | ||
|
|
||
| it('exposes an ethers contract factory for each precompile', () => { | ||
| const factories = Object.keys(ethersBarrel) | ||
| .map((key) => /^get([A-Za-z0-9]+)PrecompileEthersV6Contract$/.exec(key)?.[1]?.toUpperCase()) | ||
| .filter((name): name is string => name !== undefined) | ||
| .sort(); | ||
|
|
||
| expect(factories).toEqual(precompileNames); | ||
| }); | ||
| }); | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion]
[A-Z0-9]+excludes_, so a precompile whose name spans multiple words is silently invisible to this guard. A futureCONFIDENTIAL_TRANSFERS_PRECOMPILE_ABIfails^([A-Z0-9]+)_PRECOMPILE_ABI$(the class can't span the interior underscore, and^blocks a partial match on the trailing segment), andETHERS_CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABIfails the prefixed form identically — so the name drops out of all three lists symmetrically and the comparisons still pass. That's exactly the bug this PR is fixing: solo missing from just the ethers barrel would go undetected for such a precompile. ThetoBeGreaterThan(0)guard above doesn't help either, since the other 12 names keep the base list non-empty.[A-Z0-9_]+fixes it. Note the prefixed patterns then need the anchor to stay meaningful —^ETHERS_([A-Z0-9_]+)_PRECOMPILE_ABI$is fine, but the unprefixed^([A-Z0-9_]+)_PRECOMPILE_ABI$applied to a barrel that also heldETHERS_*keys would captureETHERS_FOO. It's safe here becausesrc/precompilesre-exports nothing prefixed, though a short comment recording that assumption would help the next editor.