core: restrict the muximum number of contents per block
This commit is contained in:
parent
c79d440c21
commit
e1e586f18b
6 changed files with 140 additions and 3 deletions
|
@ -3,6 +3,7 @@ package block
|
|||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -218,3 +219,27 @@ func TestBlockCompare(t *testing.T) {
|
|||
assert.Equal(t, 0, b2.Compare(&b2))
|
||||
assert.Equal(t, -1, b2.Compare(&b3))
|
||||
}
|
||||
|
||||
func TestBlockEncodeDecode(t *testing.T) {
|
||||
t.Run("positive", func(t *testing.T) {
|
||||
b := newDumbBlock()
|
||||
b.Transactions = []*transaction.Transaction{}
|
||||
_ = b.Hash()
|
||||
testserdes.EncodeDecodeBinary(t, b, new(Block))
|
||||
})
|
||||
|
||||
t.Run("bad contents count", func(t *testing.T) {
|
||||
b := newDumbBlock()
|
||||
b.Transactions = make([]*transaction.Transaction, MaxContentsPerBlock)
|
||||
for i := range b.Transactions {
|
||||
b.Transactions[i] = &transaction.Transaction{
|
||||
Script: []byte("my_pretty_script"),
|
||||
}
|
||||
}
|
||||
_ = b.Hash()
|
||||
data, err := testserdes.EncodeBinary(b)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, errors.Is(testserdes.DecodeBinary(data, new(Block)), ErrMaxContentsPerBlock))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue