Skip to content
Merged
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
2 changes: 1 addition & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"compilerOptions": {
"composite": true,
"noEmit": true,
"types": ["@types/bun"]
"types": ["@types/bun", "node"]
}
}
3 changes: 2 additions & 1 deletion site/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"noEmit": true,
"jsx": "react-jsx",
"resolveJsonModule": true
"resolveJsonModule": true,
"types": ["node"]
},
"include": ["./**/*.ts", "./**/*.tsx"],
"exclude": ["snippets"]
Expand Down
38 changes: 19 additions & 19 deletions src/actions/public/getFilterChanges.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, expectTypeOf, test } from 'vitest'

import { usdcContractConfig } from '~test/abis.js'
import { anvilMainnet } from '~test/anvil.js'
import type { NormalizeType } from '~test/typeUtils.js'

import type { Log } from '../../types/log.js'
import type { Hash, Hex } from '../../types/misc.js'
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('createEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down Expand Up @@ -174,7 +175,7 @@ describe('createEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down Expand Up @@ -284,7 +285,7 @@ describe('createEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer' | 'Approval'>()
expectTypeOf(logs[0].args).toEqualTypeOf<
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<
| {
from?: Address
to?: Address
Expand All @@ -297,19 +298,18 @@ describe('createEventFilter', () => {
}
>()

expectTypeOf(
logs[0].eventName === 'Transfer' && logs[0].args,
).toEqualTypeOf<
const transferArgs = logs[0].eventName === 'Transfer' && logs[0].args
const approvalArgs = logs[0].eventName === 'Approval' && logs[0].args

expectTypeOf<NormalizeType<typeof transferArgs>>().toEqualTypeOf<
| false
| {
from?: Address
to?: Address
value?: bigint
}
>()
expectTypeOf(
logs[0].eventName === 'Approval' && logs[0].args,
).toEqualTypeOf<
expectTypeOf<NormalizeType<typeof approvalArgs>>().toEqualTypeOf<
| false
| {
owner?: Address
Expand Down Expand Up @@ -459,7 +459,7 @@ describe('createContractEventFilter', () => {
expectTypeOf(logs[0].eventName).toEqualTypeOf<
'Transfer' | 'Approval' | 'Foo'
>()
expectTypeOf(logs[0].args).toEqualTypeOf<
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<
| {
from?: Address
to?: Address
Expand All @@ -479,27 +479,27 @@ describe('createContractEventFilter', () => {
}
>()

expectTypeOf(
logs[0].eventName === 'Transfer' && logs[0].args,
).toEqualTypeOf<
const transferArgs = logs[0].eventName === 'Transfer' && logs[0].args
const approvalArgs = logs[0].eventName === 'Approval' && logs[0].args
const fooArgs = logs[0].eventName === 'Foo' && logs[0].args

expectTypeOf<NormalizeType<typeof transferArgs>>().toEqualTypeOf<
| false
| {
from?: Address
to?: Address
value?: bigint
}
>()
expectTypeOf(
logs[0].eventName === 'Approval' && logs[0].args,
).toEqualTypeOf<
expectTypeOf<NormalizeType<typeof approvalArgs>>().toEqualTypeOf<
| false
| {
owner?: Address
spender?: Address
value?: bigint
}
>()
expectTypeOf(logs[0].eventName === 'Foo' && logs[0].args).toEqualTypeOf<
expectTypeOf<NormalizeType<typeof fooArgs>>().toEqualTypeOf<
| false
| {
owner?: Address
Expand Down Expand Up @@ -586,7 +586,7 @@ describe('createContractEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down Expand Up @@ -639,7 +639,7 @@ describe('createContractEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down
5 changes: 3 additions & 2 deletions src/actions/public/getFilterChanges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ERC20InvalidTransferEvent } from '~contracts/generated.js'
import { usdcContractConfig } from '~test/abis.js'
import { anvilMainnet } from '~test/anvil.js'
import { accounts, address } from '~test/constants.js'
import type { NormalizeType } from '~test/typeUtils.js'
import { deployErc20InvalidTransferEvent } from '~test/utils.js'
import type { Log } from '../../types/log.js'
import type { Hash } from '../../types/misc.js'
Expand Down Expand Up @@ -711,7 +712,7 @@ describe('events', () => {
Log<bigint, number, false, typeof event.default>[]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
from?: Address
to?: Address
value?: bigint
Expand Down Expand Up @@ -882,7 +883,7 @@ describe('events', () => {

expect(logs.length).toBe(1482)

expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
from?: Address
to?: Address
value?: bigint
Expand Down
24 changes: 12 additions & 12 deletions src/actions/public/getFilterLogs.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, expectTypeOf, test } from 'vitest'

import { usdcContractConfig } from '~test/abis.js'
import { anvilMainnet } from '~test/anvil.js'
import type { NormalizeType } from '~test/typeUtils.js'

import type { Log } from '../../types/log.js'
import type { Hash, Hex } from '../../types/misc.js'
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('createEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down Expand Up @@ -174,7 +175,7 @@ describe('createEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down Expand Up @@ -284,7 +285,7 @@ describe('createEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer' | 'Approval'>()
expectTypeOf(logs[0].args).toEqualTypeOf<
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<
| {
from?: Address
to?: Address
Expand All @@ -297,19 +298,18 @@ describe('createEventFilter', () => {
}
>()

expectTypeOf(
logs[0].eventName === 'Transfer' && logs[0].args,
).toEqualTypeOf<
const transferArgs = logs[0].eventName === 'Transfer' && logs[0].args
const approvalArgs = logs[0].eventName === 'Approval' && logs[0].args

expectTypeOf<NormalizeType<typeof transferArgs>>().toEqualTypeOf<
| false
| {
from?: Address
to?: Address
value?: bigint
}
>()
expectTypeOf(
logs[0].eventName === 'Approval' && logs[0].args,
).toEqualTypeOf<
expectTypeOf<NormalizeType<typeof approvalArgs>>().toEqualTypeOf<
| false
| {
owner?: Address
Expand Down Expand Up @@ -459,7 +459,7 @@ describe('createContractEventFilter', () => {
expectTypeOf(logs[0].eventName).toEqualTypeOf<
'Transfer' | 'Approval' | 'Foo'
>()
expectTypeOf(logs[0].args).toEqualTypeOf<
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<
| {
from?: Address
to?: Address
Expand Down Expand Up @@ -555,7 +555,7 @@ describe('createContractEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down Expand Up @@ -608,7 +608,7 @@ describe('createContractEventFilter', () => {
[`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
owner?: Address
spender?: Address
foo?: Address
Expand Down
5 changes: 3 additions & 2 deletions src/actions/public/getFilterLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ERC20InvalidTransferEvent } from '~contracts/generated.js'
import { usdcContractConfig } from '~test/abis.js'
import { anvilMainnet } from '~test/anvil.js'
import { accounts, address } from '~test/constants.js'
import type { NormalizeType } from '~test/typeUtils.js'
import { deployErc20InvalidTransferEvent } from '~test/utils.js'
import type { Log } from '../../types/log.js'
import { getAddress } from '../../utils/address/getAddress.js'
Expand Down Expand Up @@ -170,7 +171,7 @@ describe('contract events', () => {
>[]
>()
expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer' | 'Approval'>()
expectTypeOf(logs[0].args).toEqualTypeOf<
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<
| {
from?: Address
to?: Address
Expand Down Expand Up @@ -759,7 +760,7 @@ describe('raw events', () => {

expect(logs.length).toBe(1482)

expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
from?: Address
to?: Address
value?: bigint
Expand Down
5 changes: 3 additions & 2 deletions src/actions/public/getLogs.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AbiEvent } from 'abitype'
import { expectTypeOf, test } from 'vitest'

import { anvilMainnet } from '~test/anvil.js'
import type { NormalizeType } from '~test/typeUtils.js'

import type { Hash, Hex } from '../../types/misc.js'
import { getLogs } from './getLogs.js'
Expand Down Expand Up @@ -47,7 +48,7 @@ test('event: const assertion', async () => {
expectTypeOf(logs[0].topics).toEqualTypeOf<
[`0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
from?: `0x${string}`
to?: `0x${string}`
value?: bigint
Expand Down Expand Up @@ -94,7 +95,7 @@ test('event: defined inline', async () => {
expectTypeOf(logs[0].topics).toEqualTypeOf<
[`0x${string}`, `0x${string}`, `0x${string}`]
>()
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
from?: `0x${string}`
to?: `0x${string}`
value?: bigint
Expand Down
3 changes: 2 additions & 1 deletion src/actions/public/getLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ERC20InvalidTransferEvent } from '~contracts/generated.js'
import { usdcContractConfig } from '~test/abis.js'
import { anvilMainnet } from '~test/anvil.js'
import { accounts, address } from '~test/constants.js'
import type { NormalizeType } from '~test/typeUtils.js'
import { deployErc20InvalidTransferEvent } from '~test/utils.js'
import type { Log } from '../../types/log.js'
import { getAddress } from '../../utils/address/getAddress.js'
Expand Down Expand Up @@ -304,7 +305,7 @@ describe('events', () => {
)
expect(logs.length).toBe(1482)

expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf<NormalizeType<(typeof logs)[number]['args']>>().toEqualTypeOf<{
from?: `0x${string}`
to?: `0x${string}`
value?: bigint
Expand Down
2 changes: 1 addition & 1 deletion src/actions/wallet/waitForCallsStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export async function waitForCallsStatus<chain extends Chain | undefined>(
const { promise, resolve, reject } =
withResolvers<WaitForCallsStatusReturnType>()

let timer: Timer | undefined
let timer: ReturnType<typeof setTimeout> | undefined

const unobserve = observe(observerId, { resolve, reject }, (emit) => {
const unpoll = poll(
Expand Down
3 changes: 2 additions & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts", "./**/*.bench-d.ts"],
"compilerOptions": {
"composite": true,
"noEmit": true
"noEmit": true,
"types": ["node"]
}
}
23 changes: 15 additions & 8 deletions src/types/contract.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'abitype'
import type { seaportAbi } from 'abitype/abis'
import { expectTypeOf, test } from 'vitest'
import type { NormalizeType } from '~test/typeUtils.js'

import type {
AbiEventParametersToPrimitiveTypes,
Expand Down Expand Up @@ -213,22 +214,28 @@ test('GetEventArgs', () => {
],
'Transfer'
>
expectTypeOf<Result>().toEqualTypeOf<{
from?: `0x${string}` | `0x${string}`[] | null | undefined
to?: `0x${string}` | `0x${string}`[] | null | undefined
}>()
expectTypeOf<Result['from']>().toEqualTypeOf<
`0x${string}` | `0x${string}`[] | null | undefined
>()
expectTypeOf<Result['to']>().toEqualTypeOf<
`0x${string}` | `0x${string}`[] | null | undefined
>()
})

test('GetValue', () => {
// payable
type Result = GetValue<typeof seaportAbi, 'fulfillAdvancedOrder'>
expectTypeOf<Result>().toEqualTypeOf<{ value?: bigint }>()
expectTypeOf<NormalizeType<Result>>().toEqualTypeOf<{ value?: bigint }>()

// other
expectTypeOf<GetValue<typeof seaportAbi, 'getOrderStatus'>>().toEqualTypeOf<{
expectTypeOf<
NormalizeType<GetValue<typeof seaportAbi, 'getOrderStatus'>>
>().toEqualTypeOf<{
value?: never
}>()
expectTypeOf<GetValue<typeof seaportAbi, 'cancel'>>().toEqualTypeOf<{
expectTypeOf<
NormalizeType<GetValue<typeof seaportAbi, 'cancel'>>
>().toEqualTypeOf<{
value?: never
}>()

Expand Down Expand Up @@ -347,7 +354,7 @@ test('AbiEventParametersToPrimitiveTypes', () => {
Required: false
}
>
expectTypeOf<Named_DisableUnion>().toEqualTypeOf<{
expectTypeOf<NormalizeType<Named_DisableUnion>>().toEqualTypeOf<{
foo?: string
bar?: number
}>()
Expand Down
Loading
Loading