github.com/ConsenSys/Quorum@v20.10.0+incompatible/cmd/puppeth/genesis_test.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU 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 // go-ethereum 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 General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "encoding/json" 21 "io/ioutil" 22 "reflect" 23 "strings" 24 "testing" 25 26 "github.com/davecgh/go-spew/spew" 27 "github.com/ethereum/go-ethereum/core" 28 ) 29 30 // Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet. 31 func TestAlethSturebyConverter(t *testing.T) { 32 // //Quorum - skip this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum 33 t.Skipf("skipping this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum") 34 35 // /Quorum 36 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 37 if err != nil { 38 t.Fatalf("could not read file: %v", err) 39 } 40 var genesis core.Genesis 41 if err := json.Unmarshal(blob, &genesis); err != nil { 42 t.Fatalf("failed parsing genesis: %v", err) 43 } 44 spec, err := newAlethGenesisSpec("stureby", &genesis) 45 if err != nil { 46 t.Fatalf("failed creating chainspec: %v", err) 47 } 48 49 expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json") 50 if err != nil { 51 t.Fatalf("could not read file: %v", err) 52 } 53 expspec := &alethGenesisSpec{} 54 if err := json.Unmarshal(expBlob, expspec); err != nil { 55 t.Fatalf("failed parsing genesis: %v", err) 56 } 57 if !reflect.DeepEqual(expspec, spec) { 58 t.Errorf("chainspec mismatch") 59 c := spew.ConfigState{ 60 DisablePointerAddresses: true, 61 SortKeys: true, 62 } 63 exp := strings.Split(c.Sdump(expspec), "\n") 64 got := strings.Split(c.Sdump(spec), "\n") 65 for i := 0; i < len(exp) && i < len(got); i++ { 66 if exp[i] != got[i] { 67 t.Logf("got: %v\nexp: %v\n", exp[i], got[i]) 68 } 69 } 70 } 71 } 72 73 // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet. 74 func TestParitySturebyConverter(t *testing.T) { 75 // //Quorum - skip this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum 76 t.Skipf("skipping this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum") 77 78 // /Quorum 79 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 80 if err != nil { 81 t.Fatalf("could not read file: %v", err) 82 } 83 var genesis core.Genesis 84 if err := json.Unmarshal(blob, &genesis); err != nil { 85 t.Fatalf("failed parsing genesis: %v", err) 86 } 87 spec, err := newParityChainSpec("stureby", &genesis, []string{}) 88 if err != nil { 89 t.Fatalf("failed creating chainspec: %v", err) 90 } 91 92 expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") 93 if err != nil { 94 t.Fatalf("could not read file: %v", err) 95 } 96 expspec := &parityChainSpec{} 97 if err := json.Unmarshal(expBlob, expspec); err != nil { 98 t.Fatalf("failed parsing genesis: %v", err) 99 } 100 expspec.Nodes = []string{} 101 102 if !reflect.DeepEqual(expspec, spec) { 103 t.Errorf("chainspec mismatch") 104 c := spew.ConfigState{ 105 DisablePointerAddresses: true, 106 SortKeys: true, 107 } 108 exp := strings.Split(c.Sdump(expspec), "\n") 109 got := strings.Split(c.Sdump(spec), "\n") 110 for i := 0; i < len(exp) && i < len(got); i++ { 111 if exp[i] != got[i] { 112 t.Logf("got: %v\nexp: %v\n", exp[i], got[i]) 113 } 114 } 115 } 116 }