|
|
@ -1,66 +1,40 @@ |
|
|
|
package types_test |
|
|
|
package types |
|
|
|
|
|
|
|
import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/types" |
|
|
|
) |
|
|
|
|
|
|
|
func newConsensusParams(blockSize, partSize int) ConsensusParams { |
|
|
|
return ConsensusParams{ |
|
|
|
BlockSizeParams: BlockSizeParams{MaxBytes: blockSize}, |
|
|
|
BlockGossipParams: BlockGossipParams{BlockPartSizeBytes: partSize}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestConsensusParamsValidation(t *testing.T) { |
|
|
|
tests := [...]struct { |
|
|
|
params *types.ConsensusParams |
|
|
|
wantErr string |
|
|
|
testCases := []struct { |
|
|
|
params ConsensusParams |
|
|
|
valid bool |
|
|
|
}{ |
|
|
|
{&types.ConsensusParams{}, "BlockSizeParams.MaxBytes must be greater than 0"}, |
|
|
|
{ |
|
|
|
&types.ConsensusParams{BlockSizeParams: types.BlockSizeParams{MaxBytes: 10}}, |
|
|
|
"BlockGossipParams.BlockPartSizeBytes must be greater than 0", |
|
|
|
}, |
|
|
|
{ |
|
|
|
&types.ConsensusParams{ |
|
|
|
BlockSizeParams: types.BlockSizeParams{MaxBytes: 10}, |
|
|
|
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: -1}, |
|
|
|
}, "BlockGossipParams.BlockPartSizeBytes must be greater than 0", |
|
|
|
}, |
|
|
|
{ |
|
|
|
&types.ConsensusParams{ |
|
|
|
BlockSizeParams: types.BlockSizeParams{MaxBytes: 10}, |
|
|
|
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400}, |
|
|
|
}, ""}, |
|
|
|
{ |
|
|
|
&types.ConsensusParams{ |
|
|
|
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 47}, |
|
|
|
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400}, |
|
|
|
}, "", |
|
|
|
}, |
|
|
|
{ |
|
|
|
&types.ConsensusParams{ |
|
|
|
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 100}, |
|
|
|
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400}, |
|
|
|
}, "", |
|
|
|
}, |
|
|
|
{ |
|
|
|
&types.ConsensusParams{ |
|
|
|
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 101}, |
|
|
|
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400}, |
|
|
|
}, "BlockSizeParams.MaxBytes is too big", |
|
|
|
}, |
|
|
|
{ |
|
|
|
&types.ConsensusParams{ |
|
|
|
BlockSizeParams: types.BlockSizeParams{MaxBytes: 1024 * 1024 * 1024}, |
|
|
|
BlockGossipParams: types.BlockGossipParams{BlockPartSizeBytes: 400}, |
|
|
|
}, "BlockSizeParams.MaxBytes is too big", |
|
|
|
}, |
|
|
|
{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 i, tt := range tests { |
|
|
|
err := tt.params.Validate() |
|
|
|
if tt.wantErr != "" { |
|
|
|
assert.Contains(t, err.Error(), tt.wantErr, "#%d: params: %#v", i, tt.params) |
|
|
|
for _, testCase := range testCases { |
|
|
|
if testCase.valid { |
|
|
|
assert.NoError(t, testCase.params.Validate(), "expected no error for valid params") |
|
|
|
} else { |
|
|
|
assert.Nil(t, err, "#%d: want nil error; Params: %#v", i, tt.params) |
|
|
|
assert.Error(t, testCase.params.Validate(), "expected error for non valid params") |
|
|
|
} |
|
|
|
} |
|
|
|
} |