mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 12:51:22 +00:00
reap max bytes from the mempool & check transaction size
See ADR 020: Limiting txs size inside a block docs/architecture/adr-020-block-size.md Refs #2035
This commit is contained in:
@ -2,11 +2,13 @@ package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
)
|
||||
|
||||
@ -118,7 +120,7 @@ func TestBlockMakePartSetWithEvidence(t *testing.T) {
|
||||
|
||||
partSet := MakeBlock(h, txs, commit, evList).MakePartSet(1024)
|
||||
assert.NotNil(t, partSet)
|
||||
assert.Equal(t, 3, partSet.Total())
|
||||
assert.Equal(t, 2, partSet.Total())
|
||||
}
|
||||
|
||||
func TestBlockHashesTo(t *testing.T) {
|
||||
@ -159,16 +161,16 @@ func TestBlockString(t *testing.T) {
|
||||
}
|
||||
|
||||
func makeBlockIDRandom() BlockID {
|
||||
blockHash, blockPartsHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)}
|
||||
blockHash, blockPartsHeader := crypto.CRandBytes(tmhash.Size), PartSetHeader{123, crypto.CRandBytes(tmhash.Size)}
|
||||
return BlockID{blockHash, blockPartsHeader}
|
||||
}
|
||||
|
||||
func makeBlockID(hash string, partSetSize int, partSetHash string) BlockID {
|
||||
func makeBlockID(hash []byte, partSetSize int, partSetHash []byte) BlockID {
|
||||
return BlockID{
|
||||
Hash: []byte(hash),
|
||||
Hash: hash,
|
||||
PartsHeader: PartSetHeader{
|
||||
Total: partSetSize,
|
||||
Hash: []byte(partSetHash),
|
||||
Hash: partSetHash,
|
||||
},
|
||||
}
|
||||
|
||||
@ -233,6 +235,40 @@ func TestCommitValidateBasic(t *testing.T) {
|
||||
assert.Error(t, commit.ValidateBasic())
|
||||
}
|
||||
|
||||
func TestMaxHeaderBytes(t *testing.T) {
|
||||
// Construct a UTF-8 string of MaxChainIDLen length using the supplementary
|
||||
// characters.
|
||||
// Each supplementary character takes 4 bytes.
|
||||
// http://www.i18nguy.com/unicode/supplementary-test.html
|
||||
maxChainID := ""
|
||||
for i := 0; i < MaxChainIDLen; i++ {
|
||||
maxChainID += "𠜎"
|
||||
}
|
||||
|
||||
h := Header{
|
||||
ChainID: maxChainID,
|
||||
Height: 10,
|
||||
Time: time.Now().UTC(),
|
||||
NumTxs: 100,
|
||||
TotalTxs: 200,
|
||||
LastBlockID: makeBlockID(make([]byte, 20), 300, make([]byte, 20)),
|
||||
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
|
||||
DataHash: tmhash.Sum([]byte("data_hash")),
|
||||
ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
|
||||
NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")),
|
||||
ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
|
||||
AppHash: tmhash.Sum([]byte("app_hash")),
|
||||
LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
|
||||
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
|
||||
ProposerAddress: tmhash.Sum([]byte("proposer_address")),
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalBinary(h)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, MaxHeaderBytes, len(bz))
|
||||
}
|
||||
|
||||
func randCommit() *Commit {
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
|
Reference in New Issue
Block a user