-
-
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.
feat: extends readonly to all AbiParameter
- Loading branch information
Mathieu Bour
committed
Oct 9, 2023
1 parent
477c914
commit a399099
Showing
4 changed files
with
115 additions
and
68 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,106 @@ | ||
import type { Abi, AbiEvent } from './abi.js' | ||
import { Abi as AbiSchema, AbiEvent as AbiEventSchema } 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>() | ||
}) | ||
}) | ||
|
||
test('extends Abi', () => { | ||
const parsed = AbiSchema.parse([]) | ||
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('assignable to AbiEvent', () => { | ||
const parsed: AbiEvent = AbiEventSchema.parse({ | ||
anonymous: false, | ||
inputs: [ | ||
{ indexed: true, name: 'owner', type: 'address' }, | ||
{ indexed: true, name: 'spender', type: 'address' }, | ||
{ indexed: false, name: 'value', type: 'uint256' }, | ||
], | ||
name: 'Approval', | ||
type: 'event', | ||
}) | ||
type Result = typeof parsed extends AbiEvent ? 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>() | ||
}) | ||
}) | ||
|
||
test('extends Abi', () => { | ||
const parsed = AbiEventSchema.parse({ | ||
anonymous: false, | ||
inputs: [ | ||
{ indexed: true, name: 'owner', type: 'address' }, | ||
{ indexed: true, name: 'spender', type: 'address' }, | ||
{ indexed: false, name: 'value', type: 'uint256' }, | ||
], | ||
name: 'Approval', | ||
type: 'event', | ||
}) | ||
type Result = typeof parsed extends AbiEvent ? 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