|
|
@ -1,6 +1,8 @@ |
|
|
|
package types |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"sort" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
@ -38,3 +40,49 @@ func TestConsensusParamsValidation(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func makeParams(blockBytes, blockTx, blockGas, txBytes, |
|
|
|
txGas, partSize int) ConsensusParams { |
|
|
|
|
|
|
|
return ConsensusParams{ |
|
|
|
BlockSizeParams: BlockSizeParams{ |
|
|
|
MaxBytes: blockBytes, |
|
|
|
MaxTxs: blockTx, |
|
|
|
MaxGas: blockGas, |
|
|
|
}, |
|
|
|
TxSizeParams: TxSizeParams{ |
|
|
|
MaxBytes: txBytes, |
|
|
|
MaxGas: txGas, |
|
|
|
}, |
|
|
|
BlockGossipParams: BlockGossipParams{ |
|
|
|
BlockPartSizeBytes: partSize, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestConsensusParamsHash(t *testing.T) { |
|
|
|
params := []ConsensusParams{ |
|
|
|
makeParams(1, 2, 3, 4, 5, 6), |
|
|
|
makeParams(7, 2, 3, 4, 5, 6), |
|
|
|
makeParams(1, 7, 3, 4, 5, 6), |
|
|
|
makeParams(1, 2, 7, 4, 5, 6), |
|
|
|
makeParams(1, 2, 3, 7, 5, 6), |
|
|
|
makeParams(1, 2, 3, 4, 7, 6), |
|
|
|
makeParams(1, 2, 3, 4, 5, 7), |
|
|
|
makeParams(6, 5, 4, 3, 2, 1), |
|
|
|
} |
|
|
|
|
|
|
|
hashes := make([][]byte, len(params)) |
|
|
|
for i := range params { |
|
|
|
hashes[i] = params[i].Hash() |
|
|
|
} |
|
|
|
|
|
|
|
// make sure there are no duplicates...
|
|
|
|
// sort, then check in order for matches
|
|
|
|
sort.Slice(hashes, func(i, j int) bool { |
|
|
|
return bytes.Compare(hashes[i], hashes[j]) < 0 |
|
|
|
}) |
|
|
|
for i := 0; i < len(hashes)-1; i++ { |
|
|
|
assert.NotEqual(t, hashes[i], hashes[i+1]) |
|
|
|
} |
|
|
|
} |