github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/cmd/puppeth/genesis_test.go (about)

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