-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
autoload: Add abiFillEmptyNames
helper
#150
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c00e2ea
helpers: Add abiFillEmptyNames
yohamta 6f120b5
auto: Add abiHelpers option to AutoloadConfig
yohamta ed0d9a5
Adjusted a test case
yohamta 31feb63
helpers: modify fucntion comment
yohamta 4a1af22
whatsabi: Add exports
yohamta d582649
use startsWith to type check
yohamta 6a0590f
merge helper.ts and abi.ts
yohamta add0386
fix convention
yohamta 1b24265
update convention
yohamta 2ba3e9e
rename function
yohamta 32be43b
remove from autoload
yohamta 6f618fc
fix comments
yohamta 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 |
---|---|---|
@@ -0,0 +1,259 @@ | ||
import { expect, describe, it } from "vitest"; | ||
|
||
import { abiFillEmptyNames } from "../helpers"; | ||
import { ABI } from "../abi"; | ||
|
||
describe("abiFillEmptyNames", () => { | ||
type testCase = { | ||
name: string; | ||
abi: Array<ABI[number] | unknown>; | ||
want: Array<ABI[number] | unknown>; | ||
}; | ||
|
||
const testCases: testCase[] = [ | ||
{ | ||
name: "Basic test", | ||
abi: [ | ||
{ | ||
type: "function", | ||
selector: "0x95d376d7", | ||
payable: false, | ||
stateMutability: "payable", | ||
inputs: [ | ||
{ | ||
type: "tuple", | ||
name: "", | ||
components: [ | ||
{ type: "uint32", name: "" }, | ||
{ type: "bytes", name: "" }, | ||
{ type: "bytes32", name: "" }, | ||
{ type: "uint64", name: "" }, | ||
{ type: "address", name: "" }, | ||
], | ||
}, | ||
{ type: "bytes", name: "" }, | ||
], | ||
outputs: [ | ||
{ | ||
type: "tuple", | ||
name: "", | ||
components: [ | ||
{ type: "uint32", name: "" }, | ||
{ type: "bytes", name: "" }, | ||
{ type: "bytes32", name: "" }, | ||
{ type: "uint64", name: "" }, | ||
{ type: "address", name: "" }, | ||
], | ||
}, | ||
{ type: "bytes", name: "" }, | ||
], | ||
sig: "assignJob((uint32,bytes,bytes32,uint64,address),bytes)", | ||
name: "assignJob", | ||
constant: false, | ||
}, | ||
], | ||
want: [ | ||
{ | ||
type: "function", | ||
selector: "0x95d376d7", | ||
payable: false, | ||
stateMutability: "payable", | ||
inputs: [ | ||
{ | ||
type: "tuple", | ||
name: "", | ||
components: [ | ||
{ type: "uint32", name: "field0" }, | ||
{ type: "bytes", name: "field1" }, | ||
{ type: "bytes32", name: "field2" }, | ||
{ type: "uint64", name: "field3" }, | ||
{ type: "address", name: "field4" }, | ||
], | ||
}, | ||
{ type: "bytes", name: "" }, | ||
], | ||
outputs: [ | ||
{ | ||
type: "tuple", | ||
name: "", | ||
components: [ | ||
{ type: "uint32", name: "field0" }, | ||
{ type: "bytes", name: "field1" }, | ||
{ type: "bytes32", name: "field2" }, | ||
{ type: "uint64", name: "field3" }, | ||
{ type: "address", name: "field4" }, | ||
], | ||
}, | ||
{ type: "bytes", name: "" }, | ||
], | ||
sig: "assignJob((uint32,bytes,bytes32,uint64,address),bytes)", | ||
name: "assignJob", | ||
constant: false, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "Nested tuple test", | ||
abi: [ | ||
{ | ||
name: "test", | ||
selector: "0x12345679", | ||
inputs: [ | ||
{ | ||
name: "", | ||
type: "tuple", | ||
components: [ | ||
{ | ||
type: "tuple", | ||
name: "", | ||
components: [ | ||
{ | ||
type: "tuple", | ||
name: "", | ||
components: [ | ||
{ type: "uint256", name: "" }, | ||
{ type: "address", name: "x" }, | ||
], | ||
}, | ||
{ | ||
type: "tuple", | ||
name: "n1", | ||
components: [ | ||
{ type: "uint256", name: "y" }, | ||
{ type: "address", name: "" }, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
], | ||
want: [ | ||
{ | ||
name: "test", | ||
selector: "0x12345679", | ||
inputs: [ | ||
{ | ||
name: "", | ||
type: "tuple", | ||
components: [ | ||
{ | ||
type: "tuple", | ||
name: "field0", | ||
components: [ | ||
{ | ||
type: "tuple", | ||
name: "field0", | ||
components: [ | ||
{ | ||
type: "uint256", | ||
name: "field0", | ||
}, | ||
{ type: "address", name: "x" }, | ||
], | ||
}, | ||
{ | ||
type: "tuple", | ||
name: "n1", | ||
components: [ | ||
{ type: "uint256", name: "y" }, | ||
{ | ||
type: "address", | ||
name: "field1", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "Other Tuple types: Tuple[] and Tuple[k]", | ||
abi: [ | ||
{ | ||
name: "test", | ||
selector: "0x12345679", | ||
inputs: [ | ||
{ | ||
name: "", | ||
type: "tuple", | ||
components: [ | ||
{ | ||
name: "", | ||
type: "tuple[]", | ||
components: [ | ||
{ name: "", type: "uint256" }, | ||
{ name: "", type: "uint256" }, | ||
], | ||
}, | ||
{ | ||
name: "", | ||
type: "tuple[2]", | ||
components: [ | ||
{ name: "", type: "uint256" }, | ||
{ name: "", type: "uint256" }, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
], | ||
want: [ | ||
{ | ||
name: "test", | ||
selector: "0x12345679", | ||
inputs: [ | ||
{ | ||
name: "", | ||
type: "tuple", | ||
components: [ | ||
{ | ||
name: "field0", | ||
type: "tuple[]", | ||
components: [ | ||
{ name: "field0", type: "uint256" }, | ||
{ name: "field1", type: "uint256" }, | ||
], | ||
}, | ||
{ | ||
name: "field1", | ||
type: "tuple[2]", | ||
components: [ | ||
{ name: "field0", type: "uint256" }, | ||
{ name: "field1", type: "uint256" }, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "Empty ABI", | ||
abi: [], | ||
want: [], | ||
}, | ||
]; | ||
|
||
testCases.forEach((tc) => { | ||
it(tc.name, () => { | ||
expect(abiFillEmptyNames(tc.abi as ABI)).toStrictEqual(tc.want); | ||
}); | ||
}); | ||
}); |
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
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.
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.
This still doesn't feel great to me, because the code difference is...
vs
Which doesn't feel like it warrants putting it into autoload?
Also now I'm thinking maybe it should be whatsabi.abi.fillEmptyNames, but I can update that later.
By the way, are you using
enableExperimentalMetadata
?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.
Sure, let's remove it from autoload for now: 32be43b
I also renamed the function: 2ba3e9e
We're using
enableExperimentalMetadata
, though we’re not entirely sure if it's necessary at this point.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.
I'd feel more comfortable making it default under the
enableExperimentalMetadata
flag, since I don't think many people use it so it won't be very breaking (plus it is experimental).Also I think WhatsABI would only generate types with empty names with that flag enabled? Or I might be mistaken.
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.
Appreciate the changes. No need to make further changes, just brainstorming at the moment. :)