github.com/aergoio/aergo@v1.3.1/types/genesis_test.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/json"
     5  	fmt "fmt"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/aergoio/aergo/internal/enc"
    10  	"github.com/davecgh/go-spew/spew"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestDefaultGenesis(t *testing.T) {
    15  	a := assert.New(t)
    16  	g := GetDefaultGenesis()
    17  	a.Equal(g.ID, defaultChainID)
    18  }
    19  
    20  func TestGenesisJSON(t *testing.T) {
    21  	a := assert.New(t)
    22  	g := GetDefaultGenesis()
    23  	d := time.Unix(0, g.Timestamp)
    24  	fmt.Println("timestamp", d)
    25  	g.Balance = map[string]string{"abc": "1234"}
    26  	b, err := json.Marshal(g)
    27  	a.Nil(err)
    28  	fmt.Println(string(b))
    29  }
    30  
    31  func TestGenesisChainID(t *testing.T) {
    32  	a := assert.New(t)
    33  	g := GetDefaultGenesis()
    34  	chainID, err := g.ChainID()
    35  	a.Nil(err)
    36  	a.True(g.ID.Equals(&defaultChainID))
    37  	fmt.Println("len:", len(chainID))
    38  	fmt.Println("chain_id: ", enc.ToString(chainID))
    39  }
    40  
    41  func TestGenesisBytes(t *testing.T) {
    42  	a := assert.New(t)
    43  	g1 := GetDefaultGenesis()
    44  	g1.Balance = map[string]string{"abc": "1234"}
    45  	g1.BPs = []string{"xxx", "yyy", "zzz"}
    46  
    47  	b := g1.Bytes()
    48  	fmt.Println(spew.Sdump(g1))
    49  
    50  	g2 := GetGenesisFromBytes(b)
    51  	a.Nil(g2.Balance)
    52  }
    53  
    54  func TestCodecChainID(t *testing.T) {
    55  	a := assert.New(t)
    56  	id1 := NewChainID()
    57  
    58  	id1.AsDefault()
    59  	a.True(id1.Equals(&defaultChainID))
    60  
    61  	b, err := id1.Bytes()
    62  	a.Nil(err)
    63  
    64  	id2 := NewChainID()
    65  	err = id2.Read(b)
    66  	a.Nil(err)
    67  	a.True(id1.Equals(id2))
    68  }