From 08701112d7bdfb0c6bdcf053e80a5b8441e95327 Mon Sep 17 00:00:00 2001 From: awkweb Date: Tue, 6 Aug 2024 11:37:56 -0400 Subject: [PATCH] fix: normalize `AbiFallback['inputs']` type between abitype and zod (#248) * fix: normalize AbiFallback.inputs type and zod * refactor: remove fallback inputs --------- Co-authored-by: Mathieu Bour --- .changeset/angry-taxis-enjoy.md | 5 +++ packages/abitype/src/abi.ts | 1 - packages/abitype/src/zod.test-d.ts | 53 ++++++++++++++++++++++++++++++ packages/abitype/src/zod.test.ts | 3 -- packages/abitype/src/zod.ts | 5 --- 5 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 .changeset/angry-taxis-enjoy.md diff --git a/.changeset/angry-taxis-enjoy.md b/.changeset/angry-taxis-enjoy.md new file mode 100644 index 00000000..edbedcd8 --- /dev/null +++ b/.changeset/angry-taxis-enjoy.md @@ -0,0 +1,5 @@ +--- +"abitype": patch +--- + +Removed `inputs` from `AbiFallback` type and Zod schema. diff --git a/packages/abitype/src/abi.ts b/packages/abitype/src/abi.ts index 033658fe..90247c54 100644 --- a/packages/abitype/src/abi.ts +++ b/packages/abitype/src/abi.ts @@ -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 diff --git a/packages/abitype/src/zod.test-d.ts b/packages/abitype/src/zod.test-d.ts index d9da3c3e..0be028e3 100644 --- a/packages/abitype/src/zod.test-d.ts +++ b/packages/abitype/src/zod.test-d.ts @@ -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' @@ -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().toEqualTypeOf() + }) + + test('extends AbiFunction', () => { + const parsed = AbiFunctionSchema.parse(approveFunction) + type Result = typeof parsed extends AbiFunction ? true : false + expectTypeOf().toEqualTypeOf() + }) + }) + + 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().toEqualTypeOf() + }) + + test('extends AbiFallback', () => { + const parsed = AbiFallbackSchema.parse(approveFunction) + type Result = typeof parsed extends AbiFallback ? true : false + expectTypeOf().toEqualTypeOf() + }) + }) + + 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().toEqualTypeOf() + }) + + test('extends AbiFunction', () => { + const parsed = AbiFunctionSchema.parse(approveFunction) + type Result = typeof parsed extends AbiFunction ? true : false + expectTypeOf().toEqualTypeOf() + }) + }) + describe('AbiParameter', () => { const approvalOwnerParameter = erc20Abi[0].inputs[0] diff --git a/packages/abitype/src/zod.test.ts b/packages/abitype/src/zod.test.ts index fbcbe679..bec5356e 100644 --- a/packages/abitype/src/zod.test.ts +++ b/packages/abitype/src/zod.test.ts @@ -485,7 +485,6 @@ describe('AbiFallback', () => { }), ).toMatchInlineSnapshot(` { - "inputs": [], "stateMutability": "nonpayable", "type": "fallback", } @@ -502,7 +501,6 @@ describe('AbiFallback', () => { }), ).toMatchInlineSnapshot(` { - "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "fallback", @@ -516,7 +514,6 @@ describe('AbiFallback', () => { }), ).toMatchInlineSnapshot(` { - "inputs": [], "payable": true, "stateMutability": "payable", "type": "fallback", diff --git a/packages/abitype/src/zod.ts b/packages/abitype/src/zod.ts index b074f9f5..76a5d024 100644 --- a/packages/abitype/src/zod.ts +++ b/packages/abitype/src/zod.ts @@ -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