genesis_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. package main
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "io/ioutil"
  21. "reflect"
  22. "strings"
  23. "testing"
  24. "github.com/davecgh/go-spew/spew"
  25. "github.com/ethereum/go-ethereum/core"
  26. )
  27. // Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet.
  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. expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json")
  42. if err != nil {
  43. t.Fatalf("could not read file: %v", err)
  44. }
  45. expspec := &alethGenesisSpec{}
  46. if err := json.Unmarshal(expBlob, expspec); err != nil {
  47. t.Fatalf("failed parsing genesis: %v", err)
  48. }
  49. if !reflect.DeepEqual(expspec, spec) {
  50. t.Errorf("chainspec mismatch")
  51. c := spew.ConfigState{
  52. DisablePointerAddresses: true,
  53. SortKeys: true,
  54. }
  55. exp := strings.Split(c.Sdump(expspec), "\n")
  56. got := strings.Split(c.Sdump(spec), "\n")
  57. for i := 0; i < len(exp) && i < len(got); i++ {
  58. if exp[i] != got[i] {
  59. fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
  60. }
  61. }
  62. }
  63. }
  64. // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet.
  65. func TestParitySturebyConverter(t *testing.T) {
  66. blob, err := ioutil.ReadFile("testdata/stureby_geth.json")
  67. if err != nil {
  68. t.Fatalf("could not read file: %v", err)
  69. }
  70. var genesis core.Genesis
  71. if err := json.Unmarshal(blob, &genesis); err != nil {
  72. t.Fatalf("failed parsing genesis: %v", err)
  73. }
  74. spec, err := newParityChainSpec("Stureby", &genesis, []string{})
  75. if err != nil {
  76. t.Fatalf("failed creating chainspec: %v", err)
  77. }
  78. expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json")
  79. if err != nil {
  80. t.Fatalf("could not read file: %v", err)
  81. }
  82. expspec := &parityChainSpec{}
  83. if err := json.Unmarshal(expBlob, expspec); err != nil {
  84. t.Fatalf("failed parsing genesis: %v", err)
  85. }
  86. expspec.Nodes = []string{}
  87. if !reflect.DeepEqual(expspec, spec) {
  88. t.Errorf("chainspec mismatch")
  89. c := spew.ConfigState{
  90. DisablePointerAddresses: true,
  91. SortKeys: true,
  92. }
  93. exp := strings.Split(c.Sdump(expspec), "\n")
  94. got := strings.Split(c.Sdump(spec), "\n")
  95. for i := 0; i < len(exp) && i < len(got); i++ {
  96. if exp[i] != got[i] {
  97. fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
  98. }
  99. }
  100. }
  101. }