Merge pull request #748 from tendermint/params-test
types: ConsensusParams test + document the ranges/limits
This commit is contained in:
commit
f97229f05a
|
@ -60,31 +60,3 @@ func TestGenesis(t *testing.T) {
|
|||
genDoc, err = GenesisDocFromJSON(genDocBytes)
|
||||
assert.Error(t, err, "expected error for genDoc json with block size of 0")
|
||||
}
|
||||
|
||||
func newConsensusParams(blockSize, partSize int) ConsensusParams {
|
||||
return ConsensusParams{
|
||||
BlockSizeParams: BlockSizeParams{MaxBytes: blockSize},
|
||||
BlockGossipParams: BlockGossipParams{BlockPartSizeBytes: partSize},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestConsensusParams(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
params ConsensusParams
|
||||
valid bool
|
||||
}{
|
||||
{newConsensusParams(1, 1), true},
|
||||
{newConsensusParams(1, 0), false},
|
||||
{newConsensusParams(0, 1), false},
|
||||
{newConsensusParams(0, 0), false},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
if testCase.valid {
|
||||
assert.NoError(t, testCase.params.Validate(), "expected no error for valid params")
|
||||
} else {
|
||||
assert.Error(t, testCase.params.Validate(), "expected error for non valid params")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ type ConsensusParams struct {
|
|||
|
||||
// BlockSizeParams contain limits on the block size.
|
||||
type BlockSizeParams struct {
|
||||
MaxBytes int `json:"max_bytes"` // NOTE: must not be 0
|
||||
MaxBytes int `json:"max_bytes"` // NOTE: must not be 0 nor greater than 100MB
|
||||
MaxTxs int `json:"max_txs"`
|
||||
MaxGas int `json:"max_gas"`
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func newConsensusParams(blockSize, partSize int) ConsensusParams {
|
||||
return ConsensusParams{
|
||||
BlockSizeParams: BlockSizeParams{MaxBytes: blockSize},
|
||||
BlockGossipParams: BlockGossipParams{BlockPartSizeBytes: partSize},
|
||||
}
|
||||
}
|
||||
|
||||
func TestConsensusParamsValidation(t *testing.T) {
|
||||
testCases := []struct {
|
||||
params ConsensusParams
|
||||
valid bool
|
||||
}{
|
||||
{newConsensusParams(1, 1), true},
|
||||
{newConsensusParams(1, 0), false},
|
||||
{newConsensusParams(0, 1), false},
|
||||
{newConsensusParams(0, 0), false},
|
||||
{newConsensusParams(0, 10), false},
|
||||
{newConsensusParams(10, -1), false},
|
||||
{newConsensusParams(47*1024*1024, 400), true},
|
||||
{newConsensusParams(10, 400), true},
|
||||
{newConsensusParams(100*1024*1024, 400), true},
|
||||
{newConsensusParams(101*1024*1024, 400), false},
|
||||
{newConsensusParams(1024*1024*1024, 400), false},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
if testCase.valid {
|
||||
assert.NoError(t, testCase.params.Validate(), "expected no error for valid params")
|
||||
} else {
|
||||
assert.Error(t, testCase.params.Validate(), "expected error for non valid params")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue