backend_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 eth
  17. import (
  18. "math/big"
  19. "testing"
  20. "github.com/ethereum/go-ethereum/common"
  21. "github.com/ethereum/go-ethereum/core"
  22. "github.com/ethereum/go-ethereum/core/types"
  23. "github.com/ethereum/go-ethereum/ethdb"
  24. "github.com/ethereum/go-ethereum/params"
  25. )
  26. func TestMipmapUpgrade(t *testing.T) {
  27. db, _ := ethdb.NewMemDatabase()
  28. addr := common.BytesToAddress([]byte("jeff"))
  29. genesis := core.WriteGenesisBlockForTesting(db)
  30. chain, receipts := core.GenerateChain(params.TestChainConfig, genesis, db, 10, func(i int, gen *core.BlockGen) {
  31. var receipts types.Receipts
  32. switch i {
  33. case 1:
  34. receipt := types.NewReceipt(nil, new(big.Int))
  35. receipt.Logs = []*types.Log{&types.Log{Address: addr}}
  36. gen.AddUncheckedReceipt(receipt)
  37. receipts = types.Receipts{receipt}
  38. case 2:
  39. receipt := types.NewReceipt(nil, new(big.Int))
  40. receipt.Logs = []*types.Log{&types.Log{Address: addr}}
  41. gen.AddUncheckedReceipt(receipt)
  42. receipts = types.Receipts{receipt}
  43. }
  44. // store the receipts
  45. err := core.WriteReceipts(db, receipts)
  46. if err != nil {
  47. t.Fatal(err)
  48. }
  49. })
  50. for i, block := range chain {
  51. core.WriteBlock(db, block)
  52. if err := core.WriteCanonicalHash(db, block.Hash(), block.NumberU64()); err != nil {
  53. t.Fatalf("failed to insert block number: %v", err)
  54. }
  55. if err := core.WriteHeadBlockHash(db, block.Hash()); err != nil {
  56. t.Fatalf("failed to insert block number: %v", err)
  57. }
  58. if err := core.WriteBlockReceipts(db, block.Hash(), block.NumberU64(), receipts[i]); err != nil {
  59. t.Fatal("error writing block receipts:", err)
  60. }
  61. }
  62. err := addMipmapBloomBins(db)
  63. if err != nil {
  64. t.Fatal(err)
  65. }
  66. bloom := core.GetMipmapBloom(db, 1, core.MIPMapLevels[0])
  67. if (bloom == types.Bloom{}) {
  68. t.Error("got empty bloom filter")
  69. }
  70. data, _ := db.Get([]byte("setting-mipmap-version"))
  71. if len(data) == 0 {
  72. t.Error("setting-mipmap-version not written to database")
  73. }
  74. }