github.com/codingfuture/orig-energi3@v0.8.4/cmd/puppeth/genesis_test.go (about) 1 // Copyright 2018 The Energi Core Authors 2 // Copyright 2018 The go-ethereum Authors 3 // This file is part of Energi Core. 4 // 5 // Energi Core is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Energi Core is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Energi Core. If not, see <http://www.gnu.org/licenses/>. 17 18 package main 19 20 import ( 21 "encoding/json" 22 "fmt" 23 "io/ioutil" 24 "reflect" 25 "strings" 26 "testing" 27 28 "github.com/davecgh/go-spew/spew" 29 "github.com/ethereum/go-ethereum/core" 30 ) 31 32 // Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet. 33 func TestAlethSturebyConverter(t *testing.T) { 34 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 35 if err != nil { 36 t.Fatalf("could not read file: %v", err) 37 } 38 var genesis core.Genesis 39 if err := json.Unmarshal(blob, &genesis); err != nil { 40 t.Fatalf("failed parsing genesis: %v", err) 41 } 42 spec, err := newAlethGenesisSpec("stureby", &genesis) 43 if err != nil { 44 t.Fatalf("failed creating chainspec: %v", err) 45 } 46 47 expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json") 48 if err != nil { 49 t.Fatalf("could not read file: %v", err) 50 } 51 expspec := &alethGenesisSpec{} 52 if err := json.Unmarshal(expBlob, expspec); err != nil { 53 t.Fatalf("failed parsing genesis: %v", err) 54 } 55 if !reflect.DeepEqual(expspec, spec) { 56 t.Errorf("chainspec mismatch") 57 c := spew.ConfigState{ 58 DisablePointerAddresses: true, 59 SortKeys: true, 60 } 61 exp := strings.Split(c.Sdump(expspec), "\n") 62 got := strings.Split(c.Sdump(spec), "\n") 63 for i := 0; i < len(exp) && i < len(got); i++ { 64 if exp[i] != got[i] { 65 fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i]) 66 } 67 } 68 } 69 } 70 71 // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet. 72 func TestParitySturebyConverter(t *testing.T) { 73 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 74 if err != nil { 75 t.Fatalf("could not read file: %v", err) 76 } 77 var genesis core.Genesis 78 if err := json.Unmarshal(blob, &genesis); err != nil { 79 t.Fatalf("failed parsing genesis: %v", err) 80 } 81 spec, err := newParityChainSpec("Stureby", &genesis, []string{}) 82 if err != nil { 83 t.Fatalf("failed creating chainspec: %v", err) 84 } 85 86 expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") 87 if err != nil { 88 t.Fatalf("could not read file: %v", err) 89 } 90 expspec := &parityChainSpec{} 91 if err := json.Unmarshal(expBlob, expspec); err != nil { 92 t.Fatalf("failed parsing genesis: %v", err) 93 } 94 expspec.Nodes = []string{} 95 96 if !reflect.DeepEqual(expspec, spec) { 97 t.Errorf("chainspec mismatch") 98 c := spew.ConfigState{ 99 DisablePointerAddresses: true, 100 SortKeys: true, 101 } 102 exp := strings.Split(c.Sdump(expspec), "\n") 103 got := strings.Split(c.Sdump(spec), "\n") 104 for i := 0; i < len(exp) && i < len(got); i++ { 105 if exp[i] != got[i] { 106 fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i]) 107 } 108 } 109 } 110 }