-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat(human-readable): parameter validation and strict mode #138
Changes from 3 commits
835538e
5716a47
acfab54
3e688f0
46cf96f
7ece49f
b02a4dd
b15db53
53175b3
a9301de
bf17518
5502867
350f957
d9d5ea6
0fa74f4
e415135
9c93439
b0e4f7d
101b165
07f0d97
29b86b4
aedd808
c397940
e90ae65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,15 +115,15 @@ test('InvalidFunctionModifierError', () => { | |
test('InvalidAbiTypeParameterError', () => { | ||
expect( | ||
new InvalidAbiTypeParameterError({ | ||
abiParameter: { type: 'addres' }, | ||
abiParameter: { type: 'address' }, | ||
}), | ||
).toMatchInlineSnapshot(` | ||
[InvalidAbiTypeParameterError: Invalid ABI parameter. | ||
|
||
ABI parameter type is invalid. | ||
|
||
Details: { | ||
"type": "addres" | ||
"type": "address" | ||
} | ||
Version: [email protected]] | ||
`) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { AbiStateMutability } from '../../abi.js' | ||
import type { ResolvedConfig } from '../../config.js' | ||
import type { Error } from '../../types.js' | ||
|
||
export type ErrorSignature< | ||
|
@@ -128,7 +129,7 @@ export type IsName<TName extends string> = TName extends '' | |
: false | ||
export type ValidateName< | ||
TName extends string, | ||
CheckCharacters extends boolean = false, | ||
CheckCharacters extends boolean = ResolvedConfig['Strict'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now gets enabled once folks enable strict mode instead of always being false. |
||
> = TName extends `${string}${' '}${string}` | ||
? Error<`Name "${TName}" cannot contain whitespace.`> | ||
: IsSolidityKeyword<TName> extends true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import type { AbiParameter } from '../../abi.js' | ||
import type { InferredAbiParameter } from '../../abi.js' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to change this to |
||
import type { Error, Trim } from '../../types.js' | ||
import type { StructSignature } from './signatures.js' | ||
import type { ParseAbiParameter } from './utils.js' | ||
|
||
export type StructLookup = Record<string, readonly AbiParameter[]> | ||
export type StructLookup = Record<string, readonly InferredAbiParameter[]> | ||
|
||
export type ParseStructs<TSignatures extends readonly string[]> = | ||
// Create "shallow" version of each struct (and filter out non-structs or invalid structs) | ||
|
@@ -16,7 +16,7 @@ export type ParseStructs<TSignatures extends readonly string[]> = | |
: never]: ParseStruct<Signature>['components'] | ||
} extends infer Structs extends Record< | ||
string, | ||
readonly (AbiParameter & { type: string })[] | ||
readonly (InferredAbiParameter & { type: string })[] | ||
> | ||
? // Resolve nested structs inside each struct | ||
{ | ||
|
@@ -38,8 +38,11 @@ export type ParseStruct< | |
: never | ||
|
||
export type ResolveStructs< | ||
TAbiParameters extends readonly (AbiParameter & { type: string })[], | ||
TStructs extends Record<string, readonly (AbiParameter & { type: string })[]>, | ||
TAbiParameters extends readonly (InferredAbiParameter & { type: string })[], | ||
TStructs extends Record< | ||
string, | ||
readonly (InferredAbiParameter & { type: string })[] | ||
>, | ||
TKeyReferences extends { [_: string]: unknown } | unknown = unknown, | ||
> = readonly [ | ||
...{ | ||
|
@@ -82,6 +85,6 @@ export type ParseStructProperties< | |
? ParseStructProperties< | ||
Tail, | ||
TStructs, | ||
[...Result, ParseAbiParameter<Head, { Structs: TStructs }>] | ||
[...Result, ParseAbiParameter<Head, { Structs: TStructs; Strict: false }>] | ||
> | ||
: Result |
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.
With this change it will affect type checking not only on types but also valid modifiers and parameter names. Kept as default so folks can hop in instead of out.