github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/puppeth/genesis_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:32</date> 10 //</624450069101285376> 11 12 13 package main 14 15 import ( 16 "encoding/json" 17 "fmt" 18 "io/ioutil" 19 "reflect" 20 "strings" 21 "testing" 22 23 "github.com/davecgh/go-spew/spew" 24 "github.com/ethereum/go-ethereum/core" 25 ) 26 27 //测试stureby testnet的go-ethereum-to-aleth chainspec转换。 28 func TestAlethSturebyConverter(t *testing.T) { 29 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 30 if err != nil { 31 t.Fatalf("could not read file: %v", err) 32 } 33 var genesis core.Genesis 34 if err := json.Unmarshal(blob, &genesis); err != nil { 35 t.Fatalf("failed parsing genesis: %v", err) 36 } 37 spec, err := newAlethGenesisSpec("stureby", &genesis) 38 if err != nil { 39 t.Fatalf("failed creating chainspec: %v", err) 40 } 41 42 expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json") 43 if err != nil { 44 t.Fatalf("could not read file: %v", err) 45 } 46 expspec := &alethGenesisSpec{} 47 if err := json.Unmarshal(expBlob, expspec); err != nil { 48 t.Fatalf("failed parsing genesis: %v", err) 49 } 50 if !reflect.DeepEqual(expspec, spec) { 51 t.Errorf("chainspec mismatch") 52 c := spew.ConfigState{ 53 DisablePointerAddresses: true, 54 SortKeys: true, 55 } 56 exp := strings.Split(c.Sdump(expspec), "\n") 57 got := strings.Split(c.Sdump(spec), "\n") 58 for i := 0; i < len(exp) && i < len(got); i++ { 59 if exp[i] != got[i] { 60 fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i]) 61 } 62 } 63 } 64 } 65 66 //测试stureby testnet的go-ethereum-to-parity-chainspec转换。 67 func TestParitySturebyConverter(t *testing.T) { 68 blob, err := ioutil.ReadFile("testdata/stureby_geth.json") 69 if err != nil { 70 t.Fatalf("could not read file: %v", err) 71 } 72 var genesis core.Genesis 73 if err := json.Unmarshal(blob, &genesis); err != nil { 74 t.Fatalf("failed parsing genesis: %v", err) 75 } 76 spec, err := newParityChainSpec("Stureby", &genesis, []string{}) 77 if err != nil { 78 t.Fatalf("failed creating chainspec: %v", err) 79 } 80 81 expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") 82 if err != nil { 83 t.Fatalf("could not read file: %v", err) 84 } 85 expspec := &parityChainSpec{} 86 if err := json.Unmarshal(expBlob, expspec); err != nil { 87 t.Fatalf("failed parsing genesis: %v", err) 88 } 89 expspec.Nodes = []string{} 90 91 if !reflect.DeepEqual(expspec, spec) { 92 t.Errorf("chainspec mismatch") 93 c := spew.ConfigState{ 94 DisablePointerAddresses: true, 95 SortKeys: true, 96 } 97 exp := strings.Split(c.Sdump(expspec), "\n") 98 got := strings.Split(c.Sdump(spec), "\n") 99 for i := 0; i < len(exp) && i < len(got); i++ { 100 if exp[i] != got[i] { 101 fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i]) 102 } 103 } 104 } 105 } 106