Skip to content

Commit

Permalink
Fix (#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal authored Jul 25, 2023
1 parent 13e82b6 commit 2d3e101
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jsonrpc/filter_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ func (f *FilterManager) appendLogsToFilters(header *block) error {
return nil
}

logIndex := uint64(0)

for indx, receipt := range receipts {
if receipt.TxHash == types.ZeroHash {
// Extract tx Hash
Expand All @@ -696,9 +698,12 @@ func (f *FilterManager) appendLogsToFilters(header *block) error {
TxHash: receipt.TxHash,
TxIndex: argUint64(indx),
Removed: false,
LogIndex: argUint64(logIndex),
})
}
}

logIndex++
}
}

Expand Down
87 changes: 87 additions & 0 deletions jsonrpc/filter_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,90 @@ func TestClosedFilterDeletion(t *testing.T) {
// false because filter was removed automatically
assert.False(t, m.Exists(id))
}

func Test_appendLogsToFilters(t *testing.T) {
t.Parallel()

numOfLogs := 4

block := &types.Block{
Header: &types.Header{Hash: types.StringToHash("someHash"), Number: 1},
Transactions: []*types.Transaction{
createTestTransaction(types.StringToHash("tx1")),
createTestTransaction(types.StringToHash("tx2")),
createTestTransaction(types.StringToHash("tx3")),
},
}

// setup test with block with 3 transactions and 4 logs
store := &mockBlockStore{
receipts: map[types.Hash][]*types.Receipt{
block.Header.Hash: {
{
// transaction 1 logs
Logs: []*types.Log{
{
Topics: []types.Hash{
hash1,
},
},
{
Topics: []types.Hash{
hash2,
},
},
},
},
{
// transaction 2 logs
Logs: []*types.Log{
{
Topics: []types.Hash{
hash3,
},
},
},
},
{
// transaction 3 logs
Logs: []*types.Log{
{
Topics: []types.Hash{
hash4,
},
},
},
},
},
}}

store.appendBlocksToStore([]*types.Block{block})

f := NewFilterManager(hclog.NewNullLogger(), store, 1000)

logFilter := &logFilter{
filterBase: newFilterBase(nil),
query: &LogQuery{
fromBlock: 1,
toBlock: 1,
},
}

f.filters = map[string]filter{
"test": logFilter,
}

t.Cleanup(func() {
defer f.Close()
})

b := toBlock(&types.Block{Header: block.Header}, false)
err := f.appendLogsToFilters(b)

require.NoError(t, err)
require.Len(t, logFilter.logs, numOfLogs)

for i := 0; i < numOfLogs; i++ {
require.Equal(t, uint64(i), uint64(logFilter.logs[i].LogIndex))
}
}

0 comments on commit 2d3e101

Please sign in to comment.