github.com/susy-go/susy-graviton@v0.0.0-20190614130430-36cddae42305/cmd/puppsof/genesis_test.go (about)

     1  // Copyleft 2018 The susy-graviton Authors
     2  // This file is part of susy-graviton.
     3  //
     4  // susy-graviton 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  // susy-graviton is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MSRCHANTABILITY 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 susy-graviton. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"encoding/json"
    21  	"fmt"
    22  	"io/ioutil"
    23  	"reflect"
    24  	"strings"
    25  	"testing"
    26  
    27  	"github.com/davecgh/go-spew/spew"
    28  	"github.com/susy-go/susy-graviton/core"
    29  )
    30  
    31  // Tests the susy-graviton to Alsof chainspec conversion for the Stureby testnet.
    32  func TestAlsofSturebyConverter(t *testing.T) {
    33  	blob, err := ioutil.ReadFile("testdata/stureby_graviton.json")
    34  	if err != nil {
    35  		t.Fatalf("could not read file: %v", err)
    36  	}
    37  	var genesis core.Genesis
    38  	if err := json.Unmarshal(blob, &genesis); err != nil {
    39  		t.Fatalf("failed parsing genesis: %v", err)
    40  	}
    41  	spec, err := newAlsofGenesisSpec("stureby", &genesis)
    42  	if err != nil {
    43  		t.Fatalf("failed creating chainspec: %v", err)
    44  	}
    45  
    46  	expBlob, err := ioutil.ReadFile("testdata/stureby_alsof.json")
    47  	if err != nil {
    48  		t.Fatalf("could not read file: %v", err)
    49  	}
    50  	expspec := &alsofGenesisSpec{}
    51  	if err := json.Unmarshal(expBlob, expspec); err != nil {
    52  		t.Fatalf("failed parsing genesis: %v", err)
    53  	}
    54  	if !reflect.DeepEqual(expspec, spec) {
    55  		t.Errorf("chainspec mismatch")
    56  		c := spew.ConfigState{
    57  			DisablePointerAddresses: true,
    58  			SortKeys:                true,
    59  		}
    60  		exp := strings.Split(c.Sdump(expspec), "\n")
    61  		got := strings.Split(c.Sdump(spec), "\n")
    62  		for i := 0; i < len(exp) && i < len(got); i++ {
    63  			if exp[i] != got[i] {
    64  				fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
    65  			}
    66  		}
    67  	}
    68  }
    69  
    70  // Tests the susy-graviton to Susy chainspec conversion for the Stureby testnet.
    71  func TestSusySturebyConverter(t *testing.T) {
    72  	blob, err := ioutil.ReadFile("testdata/stureby_graviton.json")
    73  	if err != nil {
    74  		t.Fatalf("could not read file: %v", err)
    75  	}
    76  	var genesis core.Genesis
    77  	if err := json.Unmarshal(blob, &genesis); err != nil {
    78  		t.Fatalf("failed parsing genesis: %v", err)
    79  	}
    80  	spec, err := newSusyChainSpec("Stureby", &genesis, []string{})
    81  	if err != nil {
    82  		t.Fatalf("failed creating chainspec: %v", err)
    83  	}
    84  
    85  	expBlob, err := ioutil.ReadFile("testdata/stureby_susy.json")
    86  	if err != nil {
    87  		t.Fatalf("could not read file: %v", err)
    88  	}
    89  	expspec := &susyChainSpec{}
    90  	if err := json.Unmarshal(expBlob, expspec); err != nil {
    91  		t.Fatalf("failed parsing genesis: %v", err)
    92  	}
    93  	expspec.Nodes = []string{}
    94  
    95  	if !reflect.DeepEqual(expspec, spec) {
    96  		t.Errorf("chainspec mismatch")
    97  		c := spew.ConfigState{
    98  			DisablePointerAddresses: true,
    99  			SortKeys:                true,
   100  		}
   101  		exp := strings.Split(c.Sdump(expspec), "\n")
   102  		got := strings.Split(c.Sdump(spec), "\n")
   103  		for i := 0; i < len(exp) && i < len(got); i++ {
   104  			if exp[i] != got[i] {
   105  				fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
   106  			}
   107  		}
   108  	}
   109  }