backend_test.go 2.7 KB

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