mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-27 11:41:39 +00:00
types: working on tests...
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
wire "github.com/tendermint/tendermint/wire"
|
||||
)
|
||||
|
||||
func TestGenesis(t *testing.T) {
|
||||
@ -28,17 +28,21 @@ func TestGenesis(t *testing.T) {
|
||||
assert.Error(t, err, "expected error for empty genDoc json")
|
||||
}
|
||||
|
||||
/* TODO WIRE enable json ...
|
||||
// test a good one by raw json
|
||||
genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"type":"ed25519","data":"961EAB8752E51A03618502F55C2B6E09C38C65635C64CCF3173ED452CF86C957"},"power":10,"name":""}],"app_hash":"","app_state":{"account_owner": "Bob"}}`)
|
||||
_, err := GenesisDocFromJSON(genDocBytes)
|
||||
assert.NoError(t, err, "expected no error for good genDoc json")
|
||||
*/
|
||||
var genDocBytes []byte
|
||||
var err error
|
||||
|
||||
// create a base gendoc from struct
|
||||
baseGenDoc := &GenesisDoc{
|
||||
ChainID: "abc",
|
||||
Validators: []GenesisValidator{{crypto.GenPrivKeyEd25519().PubKey(), 10, "myval"}},
|
||||
}
|
||||
genDocBytes, err = json.Marshal(baseGenDoc)
|
||||
genDocBytes, err = wire.MarshalJSON(baseGenDoc)
|
||||
assert.NoError(t, err, "error marshalling genDoc")
|
||||
|
||||
// test base gendoc and check consensus params were filled
|
||||
@ -47,14 +51,14 @@ func TestGenesis(t *testing.T) {
|
||||
assert.NotNil(t, genDoc.ConsensusParams, "expected consensus params to be filled in")
|
||||
|
||||
// create json with consensus params filled
|
||||
genDocBytes, err = json.Marshal(genDoc)
|
||||
genDocBytes, err = wire.MarshalJSON(genDoc)
|
||||
assert.NoError(t, err, "error marshalling genDoc")
|
||||
genDoc, err = GenesisDocFromJSON(genDocBytes)
|
||||
assert.NoError(t, err, "expected no error for valid genDoc json")
|
||||
|
||||
// test with invalid consensus params
|
||||
genDoc.ConsensusParams.BlockSize.MaxBytes = 0
|
||||
genDocBytes, err = json.Marshal(genDoc)
|
||||
genDocBytes, err = wire.MarshalJSON(genDoc)
|
||||
assert.NoError(t, err, "error marshalling genDoc")
|
||||
genDoc, err = GenesisDocFromJSON(genDocBytes)
|
||||
assert.Error(t, err, "expected error for genDoc json with block size of 0")
|
||||
|
Reference in New Issue
Block a user