Skip to content
Closed
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
43 changes: 43 additions & 0 deletions src/utils/abi/encodeEventTopics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,46 @@ test('https://github.com/wevm/viem/issues/3278', () => {
]
`)
})

test('anonymous event: no args', () => {
expect(
encodeEventTopics({
abi: [
{
name: 'RawEvent',
type: 'event',
anonymous: true,
inputs: [
{ name: 'topic0', type: 'bytes32', indexed: true },
{ name: 'topic1', type: 'bytes32', indexed: true },
],
},
] as const,
}),
).toEqual([])
})

test('anonymous event: with args', () => {
expect(
encodeEventTopics({
abi: [
{
name: 'RawEvent',
type: 'event',
anonymous: true,
inputs: [
{ name: 'topic0', type: 'bytes32', indexed: true },
{ name: 'topic1', type: 'bytes32', indexed: true },
],
},
] as const,
args: {
topic0:
'0x000000000000000000000000000000000000000000000000000000000000abcd',
},
}),
).toEqual([
'0x000000000000000000000000000000000000000000000000000000000000abcd',
null,
])
})
9 changes: 6 additions & 3 deletions src/utils/abi/encodeEventTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ export function encodeEventTopics<
if (abiItem.type !== 'event')
throw new AbiEventNotFoundError(undefined, { docsPath })

const definition = formatAbiItem(abiItem)
const signature = toEventSelector(definition as EventDefinition)

let topics: (Hex | Hex[] | null)[] = []
if (args && 'inputs' in abiItem) {
const indexedInputs = abiItem.inputs?.filter(
Expand All @@ -121,6 +118,12 @@ export function encodeEventTopics<
}) ?? []
}
}

if ('anonymous' in abiItem && abiItem.anonymous)
return topics as (Hex | Hex[] | null)[] as EncodeEventTopicsReturnType

const definition = formatAbiItem(abiItem)
const signature = toEventSelector(definition as EventDefinition)
return [signature, ...topics]
}

Expand Down