-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: changes
zod
schemas inputs/outputs to readonly
to match abit…
…ype (#194) * fix: change zod AbiEvent.inputs to readonly to match AbiType.inputs * feat: extends readonly to all AbiParameter * docs: document that abitype must be built before testing types * chore(dependencies): rollback tpo pnpm v8.3.1 and typescript v5.0.4 * docs: explicitly specify pnpm and TypeScript versions in CONTRIBUTING.md * docs: fix TypeScript typo * docs: revert explicit pnpm and TS versions, add suggested note
- Loading branch information
Mathieu Bour
authored
Oct 9, 2023
1 parent
529da5c
commit 380c9d9
Showing
6 changed files
with
134 additions
and
48 deletions.
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,10 @@ | ||
--- | ||
"abitype": patch | ||
--- | ||
|
||
Changed the following types to readonly in zod package: | ||
|
||
- `AbiContructor.inputs` | ||
- `AbiError.inputs` | ||
- `AbiEvent.inputs` | ||
- `AbiFunction.inputs` / `AbiFunction.outputs` |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,106 @@ | ||
import type { Abi } from './abi.js' | ||
import { Abi as AbiSchema } from './zod.js' | ||
import type { | ||
Abi, | ||
AbiConstructor, | ||
AbiError, | ||
AbiEvent, | ||
AbiParameter, | ||
} from './abi.js' | ||
import { | ||
customSolidityErrorsAbi, | ||
ensRegistryWithFallbackAbi, | ||
erc20Abi, | ||
} from './test/abis.js' | ||
import { | ||
Abi as AbiSchema, | ||
AbiConstructor as AbiConstructorSchema, | ||
AbiError as AbiErrorSchema, | ||
AbiEvent as AbiEventSchema, | ||
AbiParameter as AbiParameterSchema, | ||
} from './zod.js' | ||
import { describe, expectTypeOf, test } from 'vitest' | ||
|
||
describe('Zod Types', () => { | ||
test('assignable to Abi', () => { | ||
const parsed: Abi = AbiSchema.parse([]) | ||
type Result = typeof parsed extends Abi ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
describe('Abi', () => { | ||
test('assignable to Abi', () => { | ||
const parsed: Abi = AbiSchema.parse(erc20Abi) | ||
type Result = typeof parsed extends Abi ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
|
||
test('extends Abi', () => { | ||
const parsed = AbiSchema.parse(erc20Abi) | ||
type Result = typeof parsed extends Abi ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
}) | ||
|
||
describe('AbiConstructor', () => { | ||
const ensRegistryConstructor = ensRegistryWithFallbackAbi[0] | ||
|
||
test('assignable to AbiConstructor', () => { | ||
const parsed: AbiConstructor = AbiConstructorSchema.parse( | ||
ensRegistryConstructor, | ||
) | ||
type Result = typeof parsed extends AbiConstructor ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
|
||
test('extends AbiConstructor', () => { | ||
const parsed = AbiConstructorSchema.parse(ensRegistryConstructor) | ||
type Result = typeof parsed extends AbiConstructor ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
}) | ||
|
||
test('extends Abi', () => { | ||
const parsed = AbiSchema.parse([]) | ||
type Result = typeof parsed extends Abi ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
describe('AbiError', () => { | ||
const approvalCallerNotOwnerNorApproved = customSolidityErrorsAbi[1] | ||
|
||
test('assignable to AbiError', () => { | ||
const parsed: AbiError = AbiErrorSchema.parse( | ||
approvalCallerNotOwnerNorApproved, | ||
) | ||
type Result = typeof parsed extends AbiError ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
|
||
test('extends AbiError', () => { | ||
const parsed = AbiErrorSchema.parse(approvalCallerNotOwnerNorApproved) | ||
type Result = typeof parsed extends AbiError ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
}) | ||
|
||
describe('AbiEvent', () => { | ||
const approvalEvent = erc20Abi[0] | ||
|
||
test('assignable to AbiEvent', () => { | ||
const parsed: AbiEvent = AbiEventSchema.parse(approvalEvent) | ||
type Result = typeof parsed extends AbiEvent ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
|
||
test('extends AbiEvent', () => { | ||
const parsed = AbiEventSchema.parse(approvalEvent) | ||
type Result = typeof parsed extends AbiEvent ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
}) | ||
|
||
describe('AbiParameter', () => { | ||
const approvalOwnerParameter = erc20Abi[0].inputs[0] | ||
|
||
test('assignable to AbiParameter', () => { | ||
const parsed: AbiParameter = AbiParameterSchema.parse( | ||
approvalOwnerParameter, | ||
) | ||
type Result = typeof parsed extends AbiParameter ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
|
||
test('extends AbiParameter', () => { | ||
const parsed = AbiParameterSchema.parse(approvalOwnerParameter) | ||
type Result = typeof parsed extends AbiParameter ? true : false | ||
expectTypeOf<Result>().toEqualTypeOf<true>() | ||
}) | ||
}) | ||
}) |
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
380c9d9
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.
Successfully deployed to the following URLs:
abitype – ./
abitype-wagmi-dev.vercel.app
abitype.dev
abitype-git-main-wagmi-dev.vercel.app
abitype.vercel.app