-
-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
3 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,5 @@ | ||
--- | ||
"viem": patch | ||
--- | ||
|
||
Added inference to `getLogs` `event` type. |
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,96 @@ | ||
import { expectTypeOf, test } from 'vitest' | ||
|
||
import { publicClient } from '../../_test/index.js' | ||
import { getLogs } from './getLogs.js' | ||
import type { AbiEvent } from 'abitype' | ||
|
||
test('event: const assertion', async () => { | ||
const event = { | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: 'from', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: true, | ||
name: 'to', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: false, | ||
name: 'value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'Transfer', | ||
type: 'event', | ||
} as const | ||
const logs = await getLogs(publicClient, { | ||
event, | ||
}) | ||
expectTypeOf(logs[0]['args']).toEqualTypeOf<{ | ||
from: `0x${string}` | ||
to: `0x${string}` | ||
value: bigint | ||
}>() | ||
}) | ||
|
||
test('event: defined inline', async () => { | ||
const logs = await getLogs(publicClient, { | ||
event: { | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: 'from', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: true, | ||
name: 'to', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: false, | ||
name: 'value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'Transfer', | ||
type: 'event', | ||
}, | ||
}) | ||
expectTypeOf(logs[0]['args']).toEqualTypeOf<{ | ||
from: `0x${string}` | ||
to: `0x${string}` | ||
value: bigint | ||
}>() | ||
}) | ||
|
||
test('event: declared as `AbiEvent`', async () => { | ||
const event: AbiEvent = { | ||
inputs: [ | ||
{ | ||
indexed: true, | ||
name: 'from', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: true, | ||
name: 'to', | ||
type: 'address', | ||
}, | ||
{ | ||
indexed: false, | ||
name: 'value', | ||
type: 'uint256', | ||
}, | ||
], | ||
name: 'Transfer', | ||
type: 'event', | ||
} | ||
const logs = await getLogs(publicClient, { | ||
event, | ||
}) | ||
expectTypeOf(logs[0]['args']).toEqualTypeOf<readonly unknown[]>() | ||
}) |
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
ee1cb7f
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:
viem – ./site
viem.vercel.app
viem-git-main-wagmi-dev.vercel.app
viem-site.vercel.app
viem.sh
viem-wagmi-dev.vercel.app
www.viem.sh
ee1cb7f
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:
viem-playground – ./playgrounds/browser
viem-playground.vercel.app
viem-playground-git-main-wagmi-dev.vercel.app
viem-playground-wagmi-dev.vercel.app