Skip to content

Commit

Permalink
fix: resolves #3278
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jan 26, 2025
1 parent b5eadf8 commit 1d01f82
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-cycles-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed `encodeEventTopics` for zeroish arguments.
33 changes: 33 additions & 0 deletions src/utils/abi/encodeEventTopics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,36 @@ test("errors: event doesn't exist", () => {
]
`)
})

test('https://github.com/wevm/viem/issues/3278', () => {
const bugAbi = [
{
type: 'event',
name: 'test',
inputs: [
{
name: 'val',
type: 'uint32',
indexed: true,
internalType: 'uint32',
},
],
anonymous: false,
},
] as const

expect(
encodeEventTopics({
abi: bugAbi,
eventName: 'test',
args: {
val: 0, // change this to 1 and it works
},
}),
).toMatchInlineSnapshot(`
[
"0xe3cff634ef3ac1857ee74821b8b4103c803384af6152771eef3a2a92bdda6db6",
"0x0000000000000000000000000000000000000000000000000000000000000000",
]
`)
})
4 changes: 3 additions & 1 deletion src/utils/abi/encodeEventTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export function encodeEventTopics<
return args_[i].map((_: any, j: number) =>
encodeArg({ param, value: args_[i][j] }),
)
return args_[i] ? encodeArg({ param, value: args_[i] }) : null
return typeof args_[i] !== 'undefined' && args_[i] !== null
? encodeArg({ param, value: args_[i] })
: null
}) ?? []
}
}
Expand Down

0 comments on commit 1d01f82

Please sign in to comment.