database_util_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package core
  17. import (
  18. "bytes"
  19. "io/ioutil"
  20. "math/big"
  21. "os"
  22. "testing"
  23. "github.com/ethereum/go-ethereum/common"
  24. "github.com/ethereum/go-ethereum/core/types"
  25. "github.com/ethereum/go-ethereum/crypto"
  26. "github.com/ethereum/go-ethereum/crypto/sha3"
  27. "github.com/ethereum/go-ethereum/ethdb"
  28. "github.com/ethereum/go-ethereum/params"
  29. "github.com/ethereum/go-ethereum/rlp"
  30. )
  31. // Tests block header storage and retrieval operations.
  32. func TestHeaderStorage(t *testing.T) {
  33. db, _ := ethdb.NewMemDatabase()
  34. // Create a test header to move around the database and make sure it's really new
  35. header := &types.Header{Number: big.NewInt(42), Extra: []byte("test header")}
  36. if entry := GetHeader(db, header.Hash(), header.Number.Uint64()); entry != nil {
  37. t.Fatalf("Non existent header returned: %v", entry)
  38. }
  39. // Write and verify the header in the database
  40. if err := WriteHeader(db, header); err != nil {
  41. t.Fatalf("Failed to write header into database: %v", err)
  42. }
  43. if entry := GetHeader(db, header.Hash(), header.Number.Uint64()); entry == nil {
  44. t.Fatalf("Stored header not found")
  45. } else if entry.Hash() != header.Hash() {
  46. t.Fatalf("Retrieved header mismatch: have %v, want %v", entry, header)
  47. }
  48. if entry := GetHeaderRLP(db, header.Hash(), header.Number.Uint64()); entry == nil {
  49. t.Fatalf("Stored header RLP not found")
  50. } else {
  51. hasher := sha3.NewKeccak256()
  52. hasher.Write(entry)
  53. if hash := common.BytesToHash(hasher.Sum(nil)); hash != header.Hash() {
  54. t.Fatalf("Retrieved RLP header mismatch: have %v, want %v", entry, header)
  55. }
  56. }
  57. // Delete the header and verify the execution
  58. DeleteHeader(db, header.Hash(), header.Number.Uint64())
  59. if entry := GetHeader(db, header.Hash(), header.Number.Uint64()); entry != nil {
  60. t.Fatalf("Deleted header returned: %v", entry)
  61. }
  62. }
  63. // Tests block body storage and retrieval operations.
  64. func TestBodyStorage(t *testing.T) {
  65. db, _ := ethdb.NewMemDatabase()
  66. // Create a test body to move around the database and make sure it's really new
  67. body := &types.Body{Uncles: []*types.Header{{Extra: []byte("test header")}}}
  68. hasher := sha3.NewKeccak256()
  69. rlp.Encode(hasher, body)
  70. hash := common.BytesToHash(hasher.Sum(nil))
  71. if entry := GetBody(db, hash, 0); entry != nil {
  72. t.Fatalf("Non existent body returned: %v", entry)
  73. }
  74. // Write and verify the body in the database
  75. if err := WriteBody(db, hash, 0, body); err != nil {
  76. t.Fatalf("Failed to write body into database: %v", err)
  77. }
  78. if entry := GetBody(db, hash, 0); entry == nil {
  79. t.Fatalf("Stored body not found")
  80. } else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(types.Transactions(body.Transactions)) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(body.Uncles) {
  81. t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, body)
  82. }
  83. if entry := GetBodyRLP(db, hash, 0); entry == nil {
  84. t.Fatalf("Stored body RLP not found")
  85. } else {
  86. hasher := sha3.NewKeccak256()
  87. hasher.Write(entry)
  88. if calc := common.BytesToHash(hasher.Sum(nil)); calc != hash {
  89. t.Fatalf("Retrieved RLP body mismatch: have %v, want %v", entry, body)
  90. }
  91. }
  92. // Delete the body and verify the execution
  93. DeleteBody(db, hash, 0)
  94. if entry := GetBody(db, hash, 0); entry != nil {
  95. t.Fatalf("Deleted body returned: %v", entry)
  96. }
  97. }
  98. // Tests block storage and retrieval operations.
  99. func TestBlockStorage(t *testing.T) {
  100. db, _ := ethdb.NewMemDatabase()
  101. // Create a test block to move around the database and make sure it's really new
  102. block := types.NewBlockWithHeader(&types.Header{
  103. Extra: []byte("test block"),
  104. UncleHash: types.EmptyUncleHash,
  105. TxHash: types.EmptyRootHash,
  106. ReceiptHash: types.EmptyRootHash,
  107. })
  108. if entry := GetBlock(db, block.Hash(), block.NumberU64()); entry != nil {
  109. t.Fatalf("Non existent block returned: %v", entry)
  110. }
  111. if entry := GetHeader(db, block.Hash(), block.NumberU64()); entry != nil {
  112. t.Fatalf("Non existent header returned: %v", entry)
  113. }
  114. if entry := GetBody(db, block.Hash(), block.NumberU64()); entry != nil {
  115. t.Fatalf("Non existent body returned: %v", entry)
  116. }
  117. // Write and verify the block in the database
  118. if err := WriteBlock(db, block); err != nil {
  119. t.Fatalf("Failed to write block into database: %v", err)
  120. }
  121. if entry := GetBlock(db, block.Hash(), block.NumberU64()); entry == nil {
  122. t.Fatalf("Stored block not found")
  123. } else if entry.Hash() != block.Hash() {
  124. t.Fatalf("Retrieved block mismatch: have %v, want %v", entry, block)
  125. }
  126. if entry := GetHeader(db, block.Hash(), block.NumberU64()); entry == nil {
  127. t.Fatalf("Stored header not found")
  128. } else if entry.Hash() != block.Header().Hash() {
  129. t.Fatalf("Retrieved header mismatch: have %v, want %v", entry, block.Header())
  130. }
  131. if entry := GetBody(db, block.Hash(), block.NumberU64()); entry == nil {
  132. t.Fatalf("Stored body not found")
  133. } else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(block.Transactions()) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(block.Uncles()) {
  134. t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, block.Body())
  135. }
  136. // Delete the block and verify the execution
  137. DeleteBlock(db, block.Hash(), block.NumberU64())
  138. if entry := GetBlock(db, block.Hash(), block.NumberU64()); entry != nil {
  139. t.Fatalf("Deleted block returned: %v", entry)
  140. }
  141. if entry := GetHeader(db, block.Hash(), block.NumberU64()); entry != nil {
  142. t.Fatalf("Deleted header returned: %v", entry)
  143. }
  144. if entry := GetBody(db, block.Hash(), block.NumberU64()); entry != nil {
  145. t.Fatalf("Deleted body returned: %v", entry)
  146. }
  147. }
  148. // Tests that partial block contents don't get reassembled into full blocks.
  149. func TestPartialBlockStorage(t *testing.T) {
  150. db, _ := ethdb.NewMemDatabase()
  151. block := types.NewBlockWithHeader(&types.Header{
  152. Extra: []byte("test block"),
  153. UncleHash: types.EmptyUncleHash,
  154. TxHash: types.EmptyRootHash,
  155. ReceiptHash: types.EmptyRootHash,
  156. })
  157. // Store a header and check that it's not recognized as a block
  158. if err := WriteHeader(db, block.Header()); err != nil {
  159. t.Fatalf("Failed to write header into database: %v", err)
  160. }
  161. if entry := GetBlock(db, block.Hash(), block.NumberU64()); entry != nil {
  162. t.Fatalf("Non existent block returned: %v", entry)
  163. }
  164. DeleteHeader(db, block.Hash(), block.NumberU64())
  165. // Store a body and check that it's not recognized as a block
  166. if err := WriteBody(db, block.Hash(), block.NumberU64(), block.Body()); err != nil {
  167. t.Fatalf("Failed to write body into database: %v", err)
  168. }
  169. if entry := GetBlock(db, block.Hash(), block.NumberU64()); entry != nil {
  170. t.Fatalf("Non existent block returned: %v", entry)
  171. }
  172. DeleteBody(db, block.Hash(), block.NumberU64())
  173. // Store a header and a body separately and check reassembly
  174. if err := WriteHeader(db, block.Header()); err != nil {
  175. t.Fatalf("Failed to write header into database: %v", err)
  176. }
  177. if err := WriteBody(db, block.Hash(), block.NumberU64(), block.Body()); err != nil {
  178. t.Fatalf("Failed to write body into database: %v", err)
  179. }
  180. if entry := GetBlock(db, block.Hash(), block.NumberU64()); entry == nil {
  181. t.Fatalf("Stored block not found")
  182. } else if entry.Hash() != block.Hash() {
  183. t.Fatalf("Retrieved block mismatch: have %v, want %v", entry, block)
  184. }
  185. }
  186. // Tests block total difficulty storage and retrieval operations.
  187. func TestTdStorage(t *testing.T) {
  188. db, _ := ethdb.NewMemDatabase()
  189. // Create a test TD to move around the database and make sure it's really new
  190. hash, td := common.Hash{}, big.NewInt(314)
  191. if entry := GetTd(db, hash, 0); entry != nil {
  192. t.Fatalf("Non existent TD returned: %v", entry)
  193. }
  194. // Write and verify the TD in the database
  195. if err := WriteTd(db, hash, 0, td); err != nil {
  196. t.Fatalf("Failed to write TD into database: %v", err)
  197. }
  198. if entry := GetTd(db, hash, 0); entry == nil {
  199. t.Fatalf("Stored TD not found")
  200. } else if entry.Cmp(td) != 0 {
  201. t.Fatalf("Retrieved TD mismatch: have %v, want %v", entry, td)
  202. }
  203. // Delete the TD and verify the execution
  204. DeleteTd(db, hash, 0)
  205. if entry := GetTd(db, hash, 0); entry != nil {
  206. t.Fatalf("Deleted TD returned: %v", entry)
  207. }
  208. }
  209. // Tests that canonical numbers can be mapped to hashes and retrieved.
  210. func TestCanonicalMappingStorage(t *testing.T) {
  211. db, _ := ethdb.NewMemDatabase()
  212. // Create a test canonical number and assinged hash to move around
  213. hash, number := common.Hash{0: 0xff}, uint64(314)
  214. if entry := GetCanonicalHash(db, number); entry != (common.Hash{}) {
  215. t.Fatalf("Non existent canonical mapping returned: %v", entry)
  216. }
  217. // Write and verify the TD in the database
  218. if err := WriteCanonicalHash(db, hash, number); err != nil {
  219. t.Fatalf("Failed to write canonical mapping into database: %v", err)
  220. }
  221. if entry := GetCanonicalHash(db, number); entry == (common.Hash{}) {
  222. t.Fatalf("Stored canonical mapping not found")
  223. } else if entry != hash {
  224. t.Fatalf("Retrieved canonical mapping mismatch: have %v, want %v", entry, hash)
  225. }
  226. // Delete the TD and verify the execution
  227. DeleteCanonicalHash(db, number)
  228. if entry := GetCanonicalHash(db, number); entry != (common.Hash{}) {
  229. t.Fatalf("Deleted canonical mapping returned: %v", entry)
  230. }
  231. }
  232. // Tests that head headers and head blocks can be assigned, individually.
  233. func TestHeadStorage(t *testing.T) {
  234. db, _ := ethdb.NewMemDatabase()
  235. blockHead := types.NewBlockWithHeader(&types.Header{Extra: []byte("test block header")})
  236. blockFull := types.NewBlockWithHeader(&types.Header{Extra: []byte("test block full")})
  237. blockFast := types.NewBlockWithHeader(&types.Header{Extra: []byte("test block fast")})
  238. // Check that no head entries are in a pristine database
  239. if entry := GetHeadHeaderHash(db); entry != (common.Hash{}) {
  240. t.Fatalf("Non head header entry returned: %v", entry)
  241. }
  242. if entry := GetHeadBlockHash(db); entry != (common.Hash{}) {
  243. t.Fatalf("Non head block entry returned: %v", entry)
  244. }
  245. if entry := GetHeadFastBlockHash(db); entry != (common.Hash{}) {
  246. t.Fatalf("Non fast head block entry returned: %v", entry)
  247. }
  248. // Assign separate entries for the head header and block
  249. if err := WriteHeadHeaderHash(db, blockHead.Hash()); err != nil {
  250. t.Fatalf("Failed to write head header hash: %v", err)
  251. }
  252. if err := WriteHeadBlockHash(db, blockFull.Hash()); err != nil {
  253. t.Fatalf("Failed to write head block hash: %v", err)
  254. }
  255. if err := WriteHeadFastBlockHash(db, blockFast.Hash()); err != nil {
  256. t.Fatalf("Failed to write fast head block hash: %v", err)
  257. }
  258. // Check that both heads are present, and different (i.e. two heads maintained)
  259. if entry := GetHeadHeaderHash(db); entry != blockHead.Hash() {
  260. t.Fatalf("Head header hash mismatch: have %v, want %v", entry, blockHead.Hash())
  261. }
  262. if entry := GetHeadBlockHash(db); entry != blockFull.Hash() {
  263. t.Fatalf("Head block hash mismatch: have %v, want %v", entry, blockFull.Hash())
  264. }
  265. if entry := GetHeadFastBlockHash(db); entry != blockFast.Hash() {
  266. t.Fatalf("Fast head block hash mismatch: have %v, want %v", entry, blockFast.Hash())
  267. }
  268. }
  269. // Tests that positional lookup metadata can be stored and retrieved.
  270. func TestLookupStorage(t *testing.T) {
  271. db, _ := ethdb.NewMemDatabase()
  272. tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), big.NewInt(1111), big.NewInt(11111), []byte{0x11, 0x11, 0x11})
  273. tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), big.NewInt(2222), big.NewInt(22222), []byte{0x22, 0x22, 0x22})
  274. tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), big.NewInt(3333), big.NewInt(33333), []byte{0x33, 0x33, 0x33})
  275. txs := []*types.Transaction{tx1, tx2, tx3}
  276. block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, nil)
  277. // Check that no transactions entries are in a pristine database
  278. for i, tx := range txs {
  279. if txn, _, _, _ := GetTransaction(db, tx.Hash()); txn != nil {
  280. t.Fatalf("tx #%d [%x]: non existent transaction returned: %v", i, tx.Hash(), txn)
  281. }
  282. }
  283. // Insert all the transactions into the database, and verify contents
  284. if err := WriteBlock(db, block); err != nil {
  285. t.Fatalf("failed to write block contents: %v", err)
  286. }
  287. if err := WriteTxLookupEntries(db, block); err != nil {
  288. t.Fatalf("failed to write transactions: %v", err)
  289. }
  290. for i, tx := range txs {
  291. if txn, hash, number, index := GetTransaction(db, tx.Hash()); txn == nil {
  292. t.Fatalf("tx #%d [%x]: transaction not found", i, tx.Hash())
  293. } else {
  294. if hash != block.Hash() || number != block.NumberU64() || index != uint64(i) {
  295. t.Fatalf("tx #%d [%x]: positional metadata mismatch: have %x/%d/%d, want %x/%v/%v", i, tx.Hash(), hash, number, index, block.Hash(), block.NumberU64(), i)
  296. }
  297. if tx.String() != txn.String() {
  298. t.Fatalf("tx #%d [%x]: transaction mismatch: have %v, want %v", i, tx.Hash(), txn, tx)
  299. }
  300. }
  301. }
  302. // Delete the transactions and check purge
  303. for i, tx := range txs {
  304. DeleteTxLookupEntry(db, tx.Hash())
  305. if txn, _, _, _ := GetTransaction(db, tx.Hash()); txn != nil {
  306. t.Fatalf("tx #%d [%x]: deleted transaction returned: %v", i, tx.Hash(), txn)
  307. }
  308. }
  309. }
  310. // Tests that receipts associated with a single block can be stored and retrieved.
  311. func TestBlockReceiptStorage(t *testing.T) {
  312. db, _ := ethdb.NewMemDatabase()
  313. receipt1 := &types.Receipt{
  314. PostState: []byte{0x01},
  315. CumulativeGasUsed: big.NewInt(1),
  316. Logs: []*types.Log{
  317. {Address: common.BytesToAddress([]byte{0x11})},
  318. {Address: common.BytesToAddress([]byte{0x01, 0x11})},
  319. },
  320. TxHash: common.BytesToHash([]byte{0x11, 0x11}),
  321. ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
  322. GasUsed: big.NewInt(111111),
  323. }
  324. receipt2 := &types.Receipt{
  325. PostState: []byte{0x02},
  326. CumulativeGasUsed: big.NewInt(2),
  327. Logs: []*types.Log{
  328. {Address: common.BytesToAddress([]byte{0x22})},
  329. {Address: common.BytesToAddress([]byte{0x02, 0x22})},
  330. },
  331. TxHash: common.BytesToHash([]byte{0x22, 0x22}),
  332. ContractAddress: common.BytesToAddress([]byte{0x02, 0x22, 0x22}),
  333. GasUsed: big.NewInt(222222),
  334. }
  335. receipts := []*types.Receipt{receipt1, receipt2}
  336. // Check that no receipt entries are in a pristine database
  337. hash := common.BytesToHash([]byte{0x03, 0x14})
  338. if rs := GetBlockReceipts(db, hash, 0); len(rs) != 0 {
  339. t.Fatalf("non existent receipts returned: %v", rs)
  340. }
  341. // Insert the receipt slice into the database and check presence
  342. if err := WriteBlockReceipts(db, hash, 0, receipts); err != nil {
  343. t.Fatalf("failed to write block receipts: %v", err)
  344. }
  345. if rs := GetBlockReceipts(db, hash, 0); len(rs) == 0 {
  346. t.Fatalf("no receipts returned")
  347. } else {
  348. for i := 0; i < len(receipts); i++ {
  349. rlpHave, _ := rlp.EncodeToBytes(rs[i])
  350. rlpWant, _ := rlp.EncodeToBytes(receipts[i])
  351. if !bytes.Equal(rlpHave, rlpWant) {
  352. t.Fatalf("receipt #%d: receipt mismatch: have %v, want %v", i, rs[i], receipts[i])
  353. }
  354. }
  355. }
  356. // Delete the receipt slice and check purge
  357. DeleteBlockReceipts(db, hash, 0)
  358. if rs := GetBlockReceipts(db, hash, 0); len(rs) != 0 {
  359. t.Fatalf("deleted receipts returned: %v", rs)
  360. }
  361. }
  362. func TestMipmapBloom(t *testing.T) {
  363. db, _ := ethdb.NewMemDatabase()
  364. receipt1 := new(types.Receipt)
  365. receipt1.Logs = []*types.Log{
  366. {Address: common.BytesToAddress([]byte("test"))},
  367. {Address: common.BytesToAddress([]byte("address"))},
  368. }
  369. receipt2 := new(types.Receipt)
  370. receipt2.Logs = []*types.Log{
  371. {Address: common.BytesToAddress([]byte("test"))},
  372. {Address: common.BytesToAddress([]byte("address1"))},
  373. }
  374. WriteMipmapBloom(db, 1, types.Receipts{receipt1})
  375. WriteMipmapBloom(db, 2, types.Receipts{receipt2})
  376. for _, level := range MIPMapLevels {
  377. bloom := GetMipmapBloom(db, 2, level)
  378. if !bloom.Test(new(big.Int).SetBytes([]byte("address1"))) {
  379. t.Error("expected test to be included on level:", level)
  380. }
  381. }
  382. // reset
  383. db, _ = ethdb.NewMemDatabase()
  384. receipt := new(types.Receipt)
  385. receipt.Logs = []*types.Log{
  386. {Address: common.BytesToAddress([]byte("test"))},
  387. }
  388. WriteMipmapBloom(db, 999, types.Receipts{receipt1})
  389. receipt = new(types.Receipt)
  390. receipt.Logs = []*types.Log{
  391. {Address: common.BytesToAddress([]byte("test 1"))},
  392. }
  393. WriteMipmapBloom(db, 1000, types.Receipts{receipt})
  394. bloom := GetMipmapBloom(db, 1000, 1000)
  395. if bloom.TestBytes([]byte("test")) {
  396. t.Error("test should not have been included")
  397. }
  398. }
  399. func TestMipmapChain(t *testing.T) {
  400. dir, err := ioutil.TempDir("", "mipmap")
  401. if err != nil {
  402. t.Fatal(err)
  403. }
  404. defer os.RemoveAll(dir)
  405. var (
  406. db, _ = ethdb.NewLDBDatabase(dir, 0, 0)
  407. key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
  408. addr = crypto.PubkeyToAddress(key1.PublicKey)
  409. addr2 = common.BytesToAddress([]byte("jeff"))
  410. hash1 = common.BytesToHash([]byte("topic1"))
  411. )
  412. defer db.Close()
  413. gspec := &Genesis{
  414. Config: params.TestChainConfig,
  415. Alloc: GenesisAlloc{addr: {Balance: big.NewInt(1000000)}},
  416. }
  417. genesis := gspec.MustCommit(db)
  418. chain, receipts := GenerateChain(params.TestChainConfig, genesis, db, 1010, func(i int, gen *BlockGen) {
  419. var receipts types.Receipts
  420. switch i {
  421. case 1:
  422. receipt := types.NewReceipt(nil, new(big.Int))
  423. receipt.Logs = []*types.Log{{Address: addr, Topics: []common.Hash{hash1}}}
  424. gen.AddUncheckedReceipt(receipt)
  425. receipts = types.Receipts{receipt}
  426. case 1000:
  427. receipt := types.NewReceipt(nil, new(big.Int))
  428. receipt.Logs = []*types.Log{{Address: addr2}}
  429. gen.AddUncheckedReceipt(receipt)
  430. receipts = types.Receipts{receipt}
  431. }
  432. // store the receipts
  433. WriteMipmapBloom(db, uint64(i+1), receipts)
  434. })
  435. for i, block := range chain {
  436. WriteBlock(db, block)
  437. if err := WriteCanonicalHash(db, block.Hash(), block.NumberU64()); err != nil {
  438. t.Fatalf("failed to insert block number: %v", err)
  439. }
  440. if err := WriteHeadBlockHash(db, block.Hash()); err != nil {
  441. t.Fatalf("failed to insert block number: %v", err)
  442. }
  443. if err := WriteBlockReceipts(db, block.Hash(), block.NumberU64(), receipts[i]); err != nil {
  444. t.Fatal("error writing block receipts:", err)
  445. }
  446. }
  447. bloom := GetMipmapBloom(db, 0, 1000)
  448. if bloom.TestBytes(addr2[:]) {
  449. t.Error("address was included in bloom and should not have")
  450. }
  451. }