backend_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 := new(core.Genesis).MustCommit(db)
  30. chain, receipts := core.GenerateChain(params.TestChainConfig, genesis, db, 10, func(i int, gen *core.BlockGen) {
  31. switch i {
  32. case 1:
  33. receipt := types.NewReceipt(nil, new(big.Int))
  34. receipt.Logs = []*types.Log{{Address: addr}}
  35. gen.AddUncheckedReceipt(receipt)
  36. case 2:
  37. receipt := types.NewReceipt(nil, new(big.Int))
  38. receipt.Logs = []*types.Log{{Address: addr}}
  39. gen.AddUncheckedReceipt(receipt)
  40. }
  41. })
  42. for i, block := range chain {
  43. core.WriteBlock(db, block)
  44. if err := core.WriteCanonicalHash(db, block.Hash(), block.NumberU64()); err != nil {
  45. t.Fatalf("failed to insert block number: %v", err)
  46. }
  47. if err := core.WriteHeadBlockHash(db, block.Hash()); err != nil {
  48. t.Fatalf("failed to insert block number: %v", err)
  49. }
  50. if err := core.WriteBlockReceipts(db, block.Hash(), block.NumberU64(), receipts[i]); err != nil {
  51. t.Fatal("error writing block receipts:", err)
  52. }
  53. }
  54. err := addMipmapBloomBins(db)
  55. if err != nil {
  56. t.Fatal(err)
  57. }
  58. bloom := core.GetMipmapBloom(db, 1, core.MIPMapLevels[0])
  59. if (bloom == types.Bloom{}) {
  60. t.Error("got empty bloom filter")
  61. }
  62. data, _ := db.Get([]byte("setting-mipmap-version"))
  63. if len(data) == 0 {
  64. t.Error("setting-mipmap-version not written to database")
  65. }
  66. }