Skip to content

Commit

Permalink
fix log without topics response (0xPolygonHermez#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
tclemos authored Mar 31, 2023
1 parent 9a30dc9 commit 83a47f8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions db/migrations/state/0003.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ ALTER TABLE state.log
ALTER COLUMN topic0 DROP NOT NULL;

-- +migrate Down
DELETE FROM state.log WHERE topic0 IS NULL;
ALTER TABLE state.log
ALTER COLUMN topic0 SET NOT NULL;
3 changes: 2 additions & 1 deletion state/pgstatestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1357,8 +1357,9 @@ func scanLogs(rows pgx.Rows) ([]*types.Log, error) {
return nil, err
}

log.Topics = []common.Hash{}
if topic0 != nil {
log.Topics = []common.Hash{common.HexToHash(*topic0)}
log.Topics = append(log.Topics, common.HexToHash(*topic0))
}

if topic1 != nil {
Expand Down
3 changes: 2 additions & 1 deletion state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,11 @@ func TestExecutorLogs(t *testing.T) {
assert.Equal(t, scAddress, common.HexToAddress(string(processBatchResponse.Responses[0].CreateAddress)))

assert.Equal(t, 0, len(processBatchResponse.Responses[0].Logs))
assert.Equal(t, 3, len(processBatchResponse.Responses[1].Logs))
assert.Equal(t, 4, len(processBatchResponse.Responses[1].Logs))
assert.Equal(t, 4, len(processBatchResponse.Responses[1].Logs[0].Topics))
assert.Equal(t, 2, len(processBatchResponse.Responses[1].Logs[1].Topics))
assert.Equal(t, 1, len(processBatchResponse.Responses[1].Logs[2].Topics))
assert.Equal(t, 0, len(processBatchResponse.Responses[1].Logs[3].Topics))
}

func TestExecutorTransfer(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions test/contracts/auto/EmitLog2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ contract EmitLog2 {
event LogABCD(uint256 indexed a, uint256 indexed b, uint256 indexed c, uint256 d);

function emitLogs() public {
assembly {
log0(0, 32)
}
emit Log();
emit LogA(1);
emit LogABCD(1, 2, 3, 4);
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/bin/EmitLog2/EmitLog2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions test/e2e/sc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ func TestEmitLog2(t *testing.T) {
Addresses: []common.Address{scAddr},
})
require.NoError(t, err)
assert.Equal(t, 3, len(logs))
assert.Equal(t, 4, len(logs))

_, err = sc.ParseLog(logs[0])
log0 := logs[0]
assert.Equal(t, 0, len(log0.Topics))

_, err = sc.ParseLog(logs[1])
require.NoError(t, err)
logA, err := sc.ParseLogA(logs[1])

logA, err := sc.ParseLogA(logs[2])
require.NoError(t, err)
assert.Equal(t, big.NewInt(1), logA.A)
logABCD, err := sc.ParseLogABCD(logs[2])

logABCD, err := sc.ParseLogABCD(logs[3])
require.NoError(t, err)
assert.Equal(t, big.NewInt(1), logABCD.A)
assert.Equal(t, big.NewInt(2), logABCD.B)
Expand Down

0 comments on commit 83a47f8

Please sign in to comment.