Skip to content

Commit

Permalink
fix: decodeEventLog – named args with a missing name (#2092)
Browse files Browse the repository at this point in the history
* decodeEventLog bug fixed: named args with a missing name

* Create curvy-pots-watch.md

---------

Co-authored-by: jxom <jakemoxey@gmail.com>
  • Loading branch information
Sk Sohab and jxom committed Apr 7, 2024
1 parent 6ed97c3 commit 25cd1a2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/curvy-pots-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed decoding of event logs when an event argument was missing a name.
46 changes: 46 additions & 0 deletions src/utils/abi/decodeEventLog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,52 @@ test('named args: Transfer(address,address,uint256)', () => {
})
})

test('named args with a missing name: Transfer(address,address,uint256)', () => {
const event = decodeEventLog({
abi: [
{
inputs: [
{
indexed: true,
name: 'from',
type: 'address',
},
{
indexed: true,
name: 'to',
type: 'address',
},
{
indexed: false,
name: '',
type: 'uint256',
},
],
name: 'Transfer',
type: 'event',
},
],
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
],
})
assertType<typeof event>({
eventName: 'Transfer',
args: ['0x', '0x', 1n],
})
expect(event).toEqual({
args: [
'0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
'0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
1n,
],
eventName: 'Transfer',
})
})

test('unnamed args: Transfer(address,address,uint256)', () => {
const event = decodeEventLog({
abi: [
Expand Down
2 changes: 1 addition & 1 deletion src/utils/abi/decodeEventLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function decodeEventLog<
abiItem,
param: param as AbiParameter & { indexed: boolean },
})
args[param.name || i] = decodeTopic({ param, value: topic })
args[isUnnamed ? i : param.name || i] = decodeTopic({ param, value: topic })
}

// Decode data (non-indexed args).
Expand Down

0 comments on commit 25cd1a2

Please sign in to comment.