Skip to content

Commit 29a131c

Browse files
authored
test(eth): fix bloom filter test flake (#12643)
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.
1 parent cc718fb commit 29a131c

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

itests/eth_filter_test.go

+4-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/hex"
88
"encoding/json"
99
"fmt"
10-
"math/bits"
1110
"os"
1211
"sort"
1312
"strconv"
@@ -615,26 +614,13 @@ func TestTxReceiptBloom(t *testing.T) {
615614

616615
// computed by calling EventMatrix/logEventZeroData in remix
617616
// note this only contains topic bits
618-
matchMask := "0x00000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
619-
620-
maskBytes, err := hex.DecodeString(matchMask[2:])
617+
expectedBloom, err := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
621618
require.NoError(t, err)
622619

623-
bitsSet := 0
624-
for i, maskByte := range maskBytes {
625-
bitsSet += bits.OnesCount8(receipt.LogsBloom[i])
626-
627-
if maskByte > 0 {
628-
require.True(t, maskByte&receipt.LogsBloom[i] > 0)
629-
}
630-
}
620+
// We need to add the address bits before comparing.
621+
ethtypes.EthBloomSet(expectedBloom, receipt.To[:])
631622

632-
// Deflake plan: (Flake: 5 bits instead of 6)
633-
// Debug + search logs for "LogsBloom"
634-
// compare to passing case.
635-
//
636-
// 3 bits from the topic, 3 bits from the address
637-
require.Equal(t, 6, bitsSet)
623+
require.Equal(t, []uint8(expectedBloom), []uint8(receipt.LogsBloom))
638624
}
639625

640626
func TestMultipleEvents(t *testing.T) {

0 commit comments

Comments
 (0)