genesis_test.go 3.2 KB

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