github.com/kapoio/go-kapoio@v1.9.7/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 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 33 if err != nil { 34 t.Fatalf("could not read file: %v", err) 35 } 36 var genesis core.Genesis 37 if err := json.Unmarshal(blob, &genesis); err != nil { 38 t.Fatalf("failed parsing genesis: %v", err) 39 } 40 spec, err := newAlethGenesisSpec("stureby", &genesis) 41 if err != nil { 42 t.Fatalf("failed creating chainspec: %v", err) 43 } 44 45 expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json") 46 if err != nil { 47 t.Fatalf("could not read file: %v", err) 48 } 49 expspec := &alethGenesisSpec{} 50 if err := json.Unmarshal(expBlob, expspec); err != nil { 51 t.Fatalf("failed parsing genesis: %v", err) 52 } 53 if !reflect.DeepEqual(expspec, spec) { 54 t.Errorf("chainspec mismatch") 55 c := spew.ConfigState{ 56 DisablePointerAddresses: true, 57 SortKeys: true, 58 } 59 exp := strings.Split(c.Sdump(expspec), "\n") 60 got := strings.Split(c.Sdump(spec), "\n") 61 for i := 0; i < len(exp) && i < len(got); i++ { 62 if exp[i] != got[i] { 63 t.Logf("got: %v\nexp: %v\n", exp[i], got[i]) 64 } 65 } 66 } 67 } 68 69 // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet. 70 func TestParitySturebyConverter(t *testing.T) { 71 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 72 if err != nil { 73 t.Fatalf("could not read file: %v", err) 74 } 75 var genesis core.Genesis 76 if err := json.Unmarshal(blob, &genesis); err != nil { 77 t.Fatalf("failed parsing genesis: %v", err) 78 } 79 spec, err := newParityChainSpec("stureby", &genesis, []string{}) 80 if err != nil { 81 t.Fatalf("failed creating chainspec: %v", err) 82 } 83 84 expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") 85 if err != nil { 86 t.Fatalf("could not read file: %v", err) 87 } 88 expspec := &parityChainSpec{} 89 if err := json.Unmarshal(expBlob, expspec); err != nil { 90 t.Fatalf("failed parsing genesis: %v", err) 91 } 92 expspec.Nodes = []string{} 93 94 if !reflect.DeepEqual(expspec, spec) { 95 t.Errorf("chainspec mismatch") 96 c := spew.ConfigState{ 97 DisablePointerAddresses: true, 98 SortKeys: true, 99 } 100 exp := strings.Split(c.Sdump(expspec), "\n") 101 got := strings.Split(c.Sdump(spec), "\n") 102 for i := 0; i < len(exp) && i < len(got); i++ { 103 if exp[i] != got[i] { 104 t.Logf("got: %v\nexp: %v\n", exp[i], got[i]) 105 } 106 } 107 } 108 }