Skip to content

Commit

Permalink
test(eth): fix bloom filter test flake (#12643)
Browse files Browse the repository at this point in the history
The mask changes based on the address of the deployed actor. In this
test, this address is not constant because we don't deploy with CREATE2.

Instead of checking bits and then counting the number of bits, just
re-create the expected bloom filter and verify that it's correct.

NOTE: the original test was broken because it expected 6 bits: 3 from
the topic, 3 from the address. But bloom filters are probabilistic and
we could have anywhere from 3-6 bits depending on how many collisions we
get.
  • Loading branch information
Stebalien authored Oct 26, 2024
1 parent cc718fb commit 29a131c
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions itests/eth_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"math/bits"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -615,26 +614,13 @@ func TestTxReceiptBloom(t *testing.T) {

// computed by calling EventMatrix/logEventZeroData in remix
// note this only contains topic bits
matchMask := "0x00000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

maskBytes, err := hex.DecodeString(matchMask[2:])
expectedBloom, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
require.NoError(t, err)

bitsSet := 0
for i, maskByte := range maskBytes {
bitsSet += bits.OnesCount8(receipt.LogsBloom[i])

if maskByte > 0 {
require.True(t, maskByte&receipt.LogsBloom[i] > 0)
}
}
// We need to add the address bits before comparing.
ethtypes.EthBloomSet(expectedBloom, receipt.To[:])

// Deflake plan: (Flake: 5 bits instead of 6)
// Debug + search logs for "LogsBloom"
// compare to passing case.
//
// 3 bits from the topic, 3 bits from the address
require.Equal(t, 6, bitsSet)
require.Equal(t, []uint8(expectedBloom), []uint8(receipt.LogsBloom))

Check failure on line 623 in itests/eth_filter_test.go

View workflow job for this annotation

GitHub Actions / Check (lint-all)

unnecessary conversion (unconvert)
}

func TestMultipleEvents(t *testing.T) {
Expand Down

0 comments on commit 29a131c

Please sign in to comment.