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