genesis_test.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. "bytes"
  19. "encoding/json"
  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. t.Logf("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. enc, err := json.MarshalIndent(spec, "", " ")
  79. if err != nil {
  80. t.Fatalf("failed encoding chainspec: %v", err)
  81. }
  82. expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json")
  83. if err != nil {
  84. t.Fatalf("could not read file: %v", err)
  85. }
  86. if !bytes.Equal(expBlob, enc) {
  87. t.Fatalf("chainspec mismatch")
  88. }
  89. }