Skip to content

Commit

Permalink
fix: normalize AbiFallback['inputs'] type between abitype and zod (#…
Browse files Browse the repository at this point in the history
…248)

* fix: normalize AbiFallback.inputs type and zod

* refactor: remove fallback inputs

---------

Co-authored-by: Mathieu Bour <[email protected]>
  • Loading branch information
tmm and Mathieu Bour authored Aug 6, 2024
1 parent 9a0995d commit 0870111
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
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
---

Removed `inputs` from `AbiFallback` type and Zod schema.
1 change: 0 additions & 1 deletion packages/abitype/src/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export type AbiConstructor = {
/** ABI ["fallback"](https://docs.soliditylang.org/en/latest/abi-spec.html#json) type */
export type AbiFallback = {
type: 'fallback'
inputs?: readonly [] | 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,17 +5,22 @@ import type {
AbiConstructor,
AbiError,
AbiEvent,
AbiFallback,
AbiFunction,
AbiParameter,
} from './abi.js'
import {
customSolidityErrorsAbi,
ensRegistryWithFallbackAbi,
erc20Abi,
wethAbi,
} from './abis/json.js'
import {
AbiConstructor as AbiConstructorSchema,
AbiError as AbiErrorSchema,
AbiEvent as AbiEventSchema,
AbiFallback as AbiFallbackSchema,
AbiFunction as AbiFunctionSchema,
AbiParameter as AbiParameterSchema,
Abi as AbiSchema,
} 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
3 changes: 0 additions & 3 deletions packages/abitype/src/zod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ describe('AbiFallback', () => {
}),
).toMatchInlineSnapshot(`
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "fallback",
}
Expand All @@ -502,7 +501,6 @@ describe('AbiFallback', () => {
}),
).toMatchInlineSnapshot(`
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "fallback",
Expand All @@ -516,7 +514,6 @@ describe('AbiFallback', () => {
}),
).toMatchInlineSnapshot(`
{
"inputs": [],
"payable": true,
"stateMutability": "payable",
"type": "fallback",
Expand Down
5 changes: 0 additions & 5 deletions packages/abitype/src/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ export const AbiFallback = z.preprocess(
},
z.object({
type: z.literal('fallback'),
/**
* @deprecated use `pure` or `view` from {@link AbiStateMutability} instead
* https://github.com/ethereum/solidity/issues/992
*/
inputs: z.tuple([]).optional(),
/**
* @deprecated use `payable` or `nonpayable` from {@link AbiStateMutability} instead
* https://github.com/ethereum/solidity/issues/992
Expand Down

0 comments on commit 0870111

Please sign in to comment.