genesis_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // Quorum - skip this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum
  30. t.Skipf("skipping this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum")
  31. blob, err := ioutil.ReadFile("testdata/stureby_geth.json")
  32. if err != nil {
  33. t.Fatalf("could not read file: %v", err)
  34. }
  35. var genesis core.Genesis
  36. if err := json.Unmarshal(blob, &genesis); err != nil {
  37. t.Fatalf("failed parsing genesis: %v", err)
  38. }
  39. spec, err := newAlethGenesisSpec("stureby", &genesis)
  40. if err != nil {
  41. t.Fatalf("failed creating chainspec: %v", err)
  42. }
  43. expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json")
  44. if err != nil {
  45. t.Fatalf("could not read file: %v", err)
  46. }
  47. expspec := &alethGenesisSpec{}
  48. if err := json.Unmarshal(expBlob, expspec); err != nil {
  49. t.Fatalf("failed parsing genesis: %v", err)
  50. }
  51. if !reflect.DeepEqual(expspec, spec) {
  52. t.Errorf("chainspec mismatch")
  53. c := spew.ConfigState{
  54. DisablePointerAddresses: true,
  55. SortKeys: true,
  56. }
  57. exp := strings.Split(c.Sdump(expspec), "\n")
  58. got := strings.Split(c.Sdump(spec), "\n")
  59. for i := 0; i < len(exp) && i < len(got); i++ {
  60. if exp[i] != got[i] {
  61. t.Logf("got: %v\nexp: %v\n", exp[i], got[i])
  62. }
  63. }
  64. }
  65. }
  66. // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet.
  67. func TestParitySturebyConverter(t *testing.T) {
  68. // Quorum - skip this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum
  69. t.Skipf("skipping this test as MinGasLimit and GasLimitBoundDivisor has been overridden for quorum")
  70. blob, err := ioutil.ReadFile("testdata/stureby_geth.json")
  71. if err != nil {
  72. t.Fatalf("could not read file: %v", err)
  73. }
  74. var genesis core.Genesis
  75. if err := json.Unmarshal(blob, &genesis); err != nil {
  76. t.Fatalf("failed parsing genesis: %v", err)
  77. }
  78. spec, err := newParityChainSpec("stureby", &genesis, []string{})
  79. if err != nil {
  80. t.Fatalf("failed creating chainspec: %v", err)
  81. }
  82. enc, err := json.MarshalIndent(spec, "", " ")
  83. if err != nil {
  84. t.Fatalf("failed encoding chainspec: %v", err)
  85. }
  86. expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json")
  87. if err != nil {
  88. t.Fatalf("could not read file: %v", err)
  89. }
  90. if !bytes.Equal(expBlob, enc) {
  91. t.Fatalf("chainspec mismatch")
  92. }
  93. }