-
Notifications
You must be signed in to change notification settings - Fork 193
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
fix(world): dedupe functions in getWorldAbi result #3025
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
831dc13
deduplicate world abi
karooolis aa433f9
use function signature as key
karooolis 79d5c80
concatenate base + world abi, add test
karooolis c4c4066
add missing world abi mock
karooolis 3f6be19
Merge branch 'main' into kumpis/deduplicate-world-abi
karooolis 7a07c35
Merge branch 'main' into kumpis/deduplicate-world-abi
karooolis 3f6ce3c
remove deduplicateAbi
karooolis aa36627
Merge branch 'kumpis/deduplicate-world-abi' of https://github.com/lat…
karooolis 992def5
use only function selectors to filter
karooolis 00e7562
simplify test
karooolis ffe6403
remove concatBaseApi helper function
karooolis faaf4d3
simplify test client creation
karooolis 520e634
adjust functionSignatureToAbiItem return type
karooolis 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 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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { AbiItem, parseAbiItem } from "viem"; | ||
import { AbiFunction, parseAbiItem } from "viem"; | ||
|
||
export function functionSignatureToAbiItem(functionSignature: string): AbiItem { | ||
export function functionSignatureToAbiItem(functionSignature: string): AbiFunction { | ||
const formattedSignature = `function ${functionSignature}`; | ||
return parseAbiItem(formattedSignature); | ||
const abiItem = parseAbiItem(formattedSignature); | ||
|
||
if (abiItem.type !== "function") { | ||
throw new Error(`Expected function signature, got ${abiItem.type}`); | ||
} | ||
|
||
return abiItem; | ||
} |
This file contains 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,51 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { createTestClient, http } from "viem"; | ||
import { getWorldAbi } from "./getWorldAbi"; | ||
import { foundry } from "viem/chains"; | ||
|
||
vi.mock("./getFunctions", () => { | ||
const mockGetFunctionsResult = [{ signature: "setNumber(bool)" }, { signature: "batchCall((bytes32,bytes)[])" }]; | ||
const getFunctions = vi.fn(); | ||
getFunctions.mockResolvedValue(mockGetFunctionsResult); | ||
|
||
return { | ||
getFunctions, | ||
}; | ||
}); | ||
|
||
describe("World ABI", () => { | ||
it("should concat base and world ABI", async () => { | ||
const client = createTestClient({ | ||
chain: foundry, | ||
mode: "anvil", | ||
transport: http(), | ||
}); | ||
|
||
const abi = await getWorldAbi({ | ||
client, | ||
worldAddress: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", | ||
fromBlock: 0n, | ||
toBlock: 0n, | ||
}); | ||
|
||
expect(abi).toContainEqual({ | ||
inputs: [ | ||
{ | ||
type: "bool", | ||
}, | ||
], | ||
name: "setNumber", | ||
outputs: [], | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
}); | ||
|
||
expect(abi).not.toContainEqual({ | ||
name: "batchCall", | ||
type: "function", | ||
stateMutability: "nonpayable", | ||
inputs: [{ type: "tuple[]", components: [{ type: "bytes32" }, { type: "bytes" }] }], | ||
outputs: [], | ||
}); | ||
}); | ||
}); |
This file contains 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.
is
as Abi
casting necessary?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.
Without it, even with type predicate, typescript fails to recognize in the
.map(..)
that it's of typeAbiFunction