|
17 | 17 | package rawdb
|
18 | 18 |
|
19 | 19 | import (
|
| 20 | + "bytes" |
20 | 21 | "math/big"
|
21 | 22 | "testing"
|
22 | 23 |
|
23 | 24 | "github.com/ethereum/go-ethereum/common"
|
24 | 25 | "github.com/ethereum/go-ethereum/core/types"
|
25 | 26 | "github.com/ethereum/go-ethereum/ethdb"
|
| 27 | + "github.com/ethereum/go-ethereum/params" |
26 | 28 | "github.com/ethereum/go-ethereum/rlp"
|
27 | 29 | )
|
28 | 30 |
|
@@ -106,3 +108,46 @@ func TestLookupStorage(t *testing.T) {
|
106 | 108 | })
|
107 | 109 | }
|
108 | 110 | }
|
| 111 | + |
| 112 | +func TestDeleteBloomBits(t *testing.T) { |
| 113 | + // Prepare testing data |
| 114 | + db := NewMemoryDatabase() |
| 115 | + for i := uint(0); i < 2; i++ { |
| 116 | + for s := uint64(0); s < 2; s++ { |
| 117 | + WriteBloomBits(db, i, s, params.MainnetGenesisHash, []byte{0x01, 0x02}) |
| 118 | + WriteBloomBits(db, i, s, params.RinkebyGenesisHash, []byte{0x01, 0x02}) |
| 119 | + } |
| 120 | + } |
| 121 | + check := func(bit uint, section uint64, head common.Hash, exist bool) { |
| 122 | + bits, _ := ReadBloomBits(db, bit, section, head) |
| 123 | + if exist && !bytes.Equal(bits, []byte{0x01, 0x02}) { |
| 124 | + t.Fatalf("Bloombits mismatch") |
| 125 | + } |
| 126 | + if !exist && len(bits) > 0 { |
| 127 | + t.Fatalf("Bloombits should be removed") |
| 128 | + } |
| 129 | + } |
| 130 | + // Check the existence of written data. |
| 131 | + check(0, 0, params.MainnetGenesisHash, true) |
| 132 | + check(0, 0, params.RinkebyGenesisHash, true) |
| 133 | + |
| 134 | + // Check the existence of deleted data. |
| 135 | + DeleteBloombits(db, 0, 0, 1) |
| 136 | + check(0, 0, params.MainnetGenesisHash, false) |
| 137 | + check(0, 0, params.RinkebyGenesisHash, false) |
| 138 | + check(0, 1, params.MainnetGenesisHash, true) |
| 139 | + check(0, 1, params.RinkebyGenesisHash, true) |
| 140 | + |
| 141 | + // Check the existence of deleted data. |
| 142 | + DeleteBloombits(db, 0, 0, 2) |
| 143 | + check(0, 0, params.MainnetGenesisHash, false) |
| 144 | + check(0, 0, params.RinkebyGenesisHash, false) |
| 145 | + check(0, 1, params.MainnetGenesisHash, false) |
| 146 | + check(0, 1, params.RinkebyGenesisHash, false) |
| 147 | + |
| 148 | + // Bit1 shouldn't be affect. |
| 149 | + check(1, 0, params.MainnetGenesisHash, true) |
| 150 | + check(1, 0, params.RinkebyGenesisHash, true) |
| 151 | + check(1, 1, params.MainnetGenesisHash, true) |
| 152 | + check(1, 1, params.RinkebyGenesisHash, true) |
| 153 | +} |
0 commit comments