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