Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/types/contract.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ test('GetEventArgs', () => {
'Transfer'
>
expectTypeOf<Result['from']>().toEqualTypeOf<
`0x${string}` | `0x${string}`[] | null | undefined
`0x${string}` | readonly `0x${string}`[] | null | undefined
>()
expectTypeOf<Result['to']>().toEqualTypeOf<
`0x${string}` | `0x${string}`[] | null | undefined
`0x${string}` | readonly `0x${string}`[] | null | undefined
>()
})

Expand Down Expand Up @@ -260,7 +260,7 @@ test('GetValue', () => {

test('LogTopicType', () => {
expectTypeOf<LogTopicType<string, Hex>>().toEqualTypeOf<string>()
expectTypeOf<LogTopicType<string, Hex[]>>().toEqualTypeOf<string[]>()
expectTypeOf<LogTopicType<string, Hex[]>>().toEqualTypeOf<readonly string[]>()
expectTypeOf<LogTopicType<string, null>>().toEqualTypeOf<null>()

expectTypeOf<LogTopicType<string, Hex | null>>().toEqualTypeOf<
Expand All @@ -271,7 +271,7 @@ test('LogTopicType', () => {
test('AbiEventParameterToPrimitiveType', () => {
expectTypeOf<
AbiEventParameterToPrimitiveType<{ name: 'foo'; type: 'string' }>
>().toEqualTypeOf<string | string[] | null>()
>().toEqualTypeOf<string | readonly string[] | null>()
expectTypeOf<
AbiEventParameterToPrimitiveType<
{ name: 'foo'; type: 'string' },
Expand All @@ -286,7 +286,7 @@ test('AbiEventTopicToPrimitiveType', () => {
>().toEqualTypeOf<`0x${string}`>()
expectTypeOf<
AbiEventTopicToPrimitiveType<{ name: 'foo'; type: 'string' }, Hex[]>
>().toEqualTypeOf<`0x${string}`[][]>() // TODO: Is this correct?
>().toEqualTypeOf<readonly `0x${string}`[][]>() // TODO: Is this correct?
expectTypeOf<
AbiEventTopicToPrimitiveType<{ name: 'foo'; type: 'string' }, null>
>().toEqualTypeOf<null>()
Expand All @@ -300,7 +300,7 @@ test('AbiEventTopicToPrimitiveType', () => {
>().toEqualTypeOf<boolean>()
expectTypeOf<
AbiEventTopicToPrimitiveType<{ name: 'foo'; type: 'bool' }, Hex[]>
>().toEqualTypeOf<boolean[]>()
>().toEqualTypeOf<readonly boolean[]>()
})

test('AbiEventParametersToPrimitiveTypes', () => {
Expand All @@ -310,7 +310,7 @@ test('AbiEventParametersToPrimitiveTypes', () => {
[{ name: 'foo'; type: 'string'; indexed: true }]
>
>().toEqualTypeOf<{
foo?: string | string[] | null | undefined
foo?: string | readonly string[] | null | undefined
}>()
expectTypeOf<
AbiEventParametersToPrimitiveTypes<
Expand All @@ -321,8 +321,8 @@ test('AbiEventParametersToPrimitiveTypes', () => {
]
>
>().toEqualTypeOf<{
foo?: string | string[] | null | undefined
bar?: number | number[] | null | undefined
foo?: string | readonly string[] | null | undefined
bar?: number | readonly number[] | null | undefined
}>()

type Named_AllowNonIndexed = AbiEventParametersToPrimitiveTypes<
Expand All @@ -338,9 +338,9 @@ test('AbiEventParametersToPrimitiveTypes', () => {
}
>
expectTypeOf<Named_AllowNonIndexed>().toEqualTypeOf<{
foo?: string | string[] | null | undefined
bar?: number | number[] | null | undefined
baz?: `0x${string}` | `0x${string}`[] | null | undefined
foo?: string | readonly string[] | null | undefined
bar?: number | readonly number[] | null | undefined
baz?: `0x${string}` | readonly `0x${string}`[] | null | undefined
}>()
type Named_DisableUnion = AbiEventParametersToPrimitiveTypes<
[
Expand Down Expand Up @@ -373,8 +373,8 @@ test('AbiEventParametersToPrimitiveTypes', () => {
>
>().toEqualTypeOf<
| readonly []
| readonly [string | string[] | null]
| readonly [string | string[] | null, number | number[] | null]
| readonly [string | readonly string[] | null]
| readonly [string | readonly string[] | null, number | readonly number[] | null]
>()

type Unnamed_AllowNonIndexed = AbiEventParametersToPrimitiveTypes<
Expand All @@ -391,12 +391,12 @@ test('AbiEventParametersToPrimitiveTypes', () => {
>
expectTypeOf<Unnamed_AllowNonIndexed>().toEqualTypeOf<
| readonly []
| readonly [string | string[] | null]
| readonly [string | string[] | null, number | number[] | null]
| readonly [string | readonly string[] | null]
| readonly [string | readonly string[] | null, number | readonly number[] | null]
| readonly [
string | string[] | null,
number | number[] | null,
`0x${string}` | `0x${string}`[] | null,
string | readonly string[] | null,
number | readonly number[] | null,
`0x${string}` | readonly `0x${string}`[] | null,
]
>()

Expand Down Expand Up @@ -426,7 +426,7 @@ test('AbiEventParametersToPrimitiveTypes', () => {
>
>().toEqualTypeOf<
| readonly []
| readonly [string | string[] | null]
| readonly [string | string[] | null, number | number[] | null]
| readonly [string | readonly string[] | null]
| readonly [string | readonly string[] | null, number | readonly number[] | null]
>()
})
4 changes: 2 additions & 2 deletions src/types/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ export type LogTopicType<
topic extends LogTopic = LogTopic,
> = topic extends Hex
? primitiveType
: topic extends Hex[]
? primitiveType[]
: topic extends readonly Hex[]
? readonly primitiveType[]
: topic extends null
? null
: never
Expand Down
2 changes: 1 addition & 1 deletion src/types/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { OneOf } from './utils.js'
export type ByteArray = Uint8Array
export type Hex = `0x${string}`
export type Hash = `0x${string}`
export type LogTopic = Hex | Hex[] | null
export type LogTopic = Hex | readonly Hex[] | null
export type SignableMessage =
| string
| {
Expand Down