Skip to content

Commit 6480607

Browse files
committed
fix: resolves viem#3278
1 parent 7d7c90b commit 6480607

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ox": patch
3+
---
4+
5+
Fixed `AbiEvent.encode` for zeroish arguments.

src/core/AbiEvent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,9 @@ export function encode<const abiEvent extends AbiEvent>(
530530
return args_[i].map((_: any, j: number) =>
531531
encode(param, args_[i][j]),
532532
)
533-
return args_[i] ? encode(param, args_[i]) : null
533+
return typeof args_[i] !== 'undefined' && args_[i] !== null
534+
? encode(param, args_[i])
535+
: null
534536
}) ?? []
535537
}
536538
}

src/core/_test/AbiEvent.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,22 @@ describe('encode', () => {
863863
}
864864
`)
865865
})
866+
867+
test('https://github.com/wevm/viem/issues/3278', () => {
868+
const event = AbiEvent.from('event test(uint32 indexed val)')
869+
expect(
870+
AbiEvent.encode(event, {
871+
val: 0,
872+
}),
873+
).toMatchInlineSnapshot(`
874+
{
875+
"topics": [
876+
"0xe3cff634ef3ac1857ee74821b8b4103c803384af6152771eef3a2a92bdda6db6",
877+
"0x0000000000000000000000000000000000000000000000000000000000000000",
878+
],
879+
}
880+
`)
881+
})
866882
})
867883

868884
describe('format', () => {

0 commit comments

Comments
 (0)