Skip to content
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: normalize AbiFallback.inputs type between abitype and zod #203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-taxis-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"abitype": patch
---

normalize AbiFallback.inputs type and zod
2 changes: 1 addition & 1 deletion packages/abitype/src/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export type AbiConstructor = {
/** ABI ["fallback"](https://docs.soliditylang.org/en/latest/abi-spec.html#json) type */
export type AbiFallback = {
type: 'fallback'
inputs?: readonly [] | undefined
inputs?: readonly never[] | undefined
/**
* @deprecated use `payable` or `nonpayable` from {@link AbiStateMutability} instead
* @see https://github.com/ethereum/solidity/issues/992
Expand Down
53 changes: 53 additions & 0 deletions packages/abitype/src/zod.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import type {
AbiConstructor,
AbiError,
AbiEvent,
AbiFallback,
AbiFunction,
AbiParameter,
} from './abi.js'
import {
customSolidityErrorsAbi,
ensRegistryWithFallbackAbi,
erc20Abi,
wethAbi,
} from './abis/json.js'
import {
Abi as AbiSchema,
AbiConstructor as AbiConstructorSchema,
AbiError as AbiErrorSchema,
AbiEvent as AbiEventSchema,
AbiFallback as AbiFallbackSchema,
AbiFunction as AbiFunctionSchema,
AbiParameter as AbiParameterSchema,
} from './zod.js'

Expand Down Expand Up @@ -87,6 +92,54 @@ describe('Zod Types', () => {
})
})

describe('AbiFunction', () => {
const approveFunction = erc20Abi[3]

test('assignable to AbiFunction', () => {
const parsed: AbiFunction = AbiFunctionSchema.parse(approveFunction)
type Result = typeof parsed extends AbiFunction ? true : false
expectTypeOf<Result>().toEqualTypeOf<true>()
})

test('extends AbiFunction', () => {
const parsed = AbiFunctionSchema.parse(approveFunction)
type Result = typeof parsed extends AbiFunction ? true : false
expectTypeOf<Result>().toEqualTypeOf<true>()
})
})

describe('AbiFallback', () => {
const approveFunction = wethAbi[11]

test('assignable to AbiFallback', () => {
const parsed: AbiFallback = AbiFallbackSchema.parse(approveFunction)
type Result = typeof parsed extends AbiFallback ? true : false
expectTypeOf<Result>().toEqualTypeOf<true>()
})

test('extends AbiFallback', () => {
const parsed = AbiFallbackSchema.parse(approveFunction)
type Result = typeof parsed extends AbiFallback ? true : false
expectTypeOf<Result>().toEqualTypeOf<true>()
})
})

describe('AbiFunction', () => {
const approveFunction = erc20Abi[3]

test('assignable to AbiFunction', () => {
const parsed: AbiFunction = AbiFunctionSchema.parse(approveFunction)
type Result = typeof parsed extends AbiFunction ? true : false
expectTypeOf<Result>().toEqualTypeOf<true>()
})

test('extends AbiFunction', () => {
const parsed = AbiFunctionSchema.parse(approveFunction)
type Result = typeof parsed extends AbiFunction ? true : false
expectTypeOf<Result>().toEqualTypeOf<true>()
})
})

describe('AbiParameter', () => {
const approvalOwnerParameter = erc20Abi[0].inputs[0]

Expand Down
2 changes: 1 addition & 1 deletion packages/abitype/src/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const AbiFallback = z.preprocess(
* @deprecated use `pure` or `view` from {@link AbiStateMutability} instead
* https://github.com/ethereum/solidity/issues/992
*/
inputs: z.tuple([]).optional(),
inputs: z.tuple([]).readonly().optional(),
/**
* @deprecated use `payable` or `nonpayable` from {@link AbiStateMutability} instead
* https://github.com/ethereum/solidity/issues/992
Expand Down