@ -22,6 +22,10 @@ func TestGenesisBad(t *testing.T) {
[ ] byte ( ` { "validators":[ { "pub_key": { "value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]} ` ) ,
// missing chain_id
[ ] byte ( ` { "validators":[ { "pub_key": { "type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]} ` ) ,
// too big chain_id
[ ] byte ( ` { "chain_id": "Lorem ipsum dolor sit amet, consectetuer adipiscing", "validators": [ { "pub_key": { "type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]} ` ) ,
// wrong address
[ ] byte ( ` { "chain_id":"mychain", "validators":[ { "address": "A", "pub_key": { "type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]} ` ) ,
}
for _ , testCase := range testCases {
@ -36,10 +40,11 @@ func TestGenesisGood(t *testing.T) {
_ , err := GenesisDocFromJSON ( genDocBytes )
assert . NoError ( t , err , "expected no error for good genDoc json" )
pubkey := ed25519 . GenPrivKey ( ) . PubKey ( )
// create a base gendoc from struct
baseGenDoc := & GenesisDoc {
ChainID : "abc" ,
Validators : [ ] GenesisValidator { { ed25519 . GenPrivKey ( ) . PubKey ( ) , 10 , "myval" } } ,
Validators : [ ] GenesisValidator { { pubkey . Address ( ) , pubkey , 10 , "myval" } } ,
}
genDocBytes , err = cdc . MarshalJSON ( baseGenDoc )
assert . NoError ( t , err , "error marshalling genDoc" )
@ -49,6 +54,9 @@ func TestGenesisGood(t *testing.T) {
assert . NoError ( t , err , "expected no error for valid genDoc json" )
assert . NotNil ( t , genDoc . ConsensusParams , "expected consensus params to be filled in" )
// check validator's address is filled
assert . NotNil ( t , genDoc . Validators [ 0 ] . Address , "expected validator's address to be filled in" )
// create json with consensus params filled
genDocBytes , err = cdc . MarshalJSON ( genDoc )
assert . NoError ( t , err , "error marshalling genDoc" )
@ -109,10 +117,11 @@ func TestGenesisValidatorHash(t *testing.T) {
}
func randomGenesisDoc ( ) * GenesisDoc {
pubkey := ed25519 . GenPrivKey ( ) . PubKey ( )
return & GenesisDoc {
GenesisTime : tmtime . Now ( ) ,
ChainID : "abc" ,
Validators : [ ] GenesisValidator { { ed25519 . GenPrivKey ( ) . PubKey ( ) , 10 , "myval" } } ,
Validators : [ ] GenesisValidator { { pubkey . Address ( ) , pubkey , 10 , "myval" } } ,
ConsensusParams : DefaultConsensusParams ( ) ,
}
}