Browse Source

add tests for genesis

Refs #693
pull/1936/head
Anton Kaliaev 7 years ago
parent
commit
3132f7fad4
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 45 additions and 0 deletions
  1. +45
    -0
      types/genesis_test.go

+ 45
- 0
types/genesis_test.go View File

@ -1,9 +1,13 @@
package types
import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
)
@ -59,3 +63,44 @@ func TestGenesisGood(t *testing.T) {
genDoc, err = GenesisDocFromJSON(genDocBytes)
assert.Error(t, err, "expected error for genDoc json with block size of 0")
}
func TestGenesisSaveAs(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "genesis")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
genDoc := randomGenesisDoc()
// save
genDoc.SaveAs(tmpfile.Name())
stat, err := tmpfile.Stat()
require.NoError(t, err)
if err != nil && stat.Size() <= 0 {
t.Fatalf("SaveAs failed to write any bytes to %v", tmpfile.Name())
}
err = tmpfile.Close()
require.NoError(t, err)
// load
genDoc2, err := GenesisDocFromFile(tmpfile.Name())
require.NoError(t, err)
// fails to unknown reason
// assert.EqualValues(t, genDoc2, genDoc)
assert.Equal(t, genDoc2.Validators, genDoc.Validators)
}
func TestGenesisValidatorHash(t *testing.T) {
genDoc := randomGenesisDoc()
assert.NotEmpty(t, genDoc.ValidatorHash())
}
func randomGenesisDoc() *GenesisDoc {
return &GenesisDoc{
GenesisTime: time.Now().UTC(),
ChainID: "abc",
Validators: []GenesisValidator{{crypto.GenPrivKeyEd25519().PubKey(), 10, "myval"}},
ConsensusParams: DefaultConsensusParams(),
}
}

Loading…
Cancel
Save