Commit efeb3663 authored by David Vorick's avatar David Vorick

add a test for too large blocks

parent 58f59d54
......@@ -29,6 +29,7 @@ var (
BlockKnownErr = errors.New("block exists in block map.")
FutureBlockErr = errors.New("timestamp too far in future, will try again later.")
KnownOrphanErr = errors.New("block is a known orphan")
LargeBlockErr = errors.New("block is too large to be accepted")
UnknownOrphanErr = errors.New("block is an unknown orphan")
)
......@@ -107,7 +108,7 @@ func (s *State) validHeader(b Block) (err error) {
// Check that the block is the correct size.
encodedBlock := encoding.Marshal(b)
if len(encodedBlock) > BlockSizeLimit {
err = errors.New("Block is too large, will not be accepted.")
err = LargeBlockErr
return
}
......
......@@ -85,6 +85,25 @@ func testEmptyBlock(t *testing.T, s *State) {
}
}
// testLargeBlock creates a block that is too large to be accepted by the state
// and checks that it actually gets rejected.
func testLargeBlock(t *testing.T, s *State) {
txns := make([]Transaction, 1)
bigData := string(make([]byte, BlockSizeLimit)) // TODO: test all the way down to one byte over the limit.
txns[0] = Transaction{
ArbitraryData: []string{bigData},
}
b, err := mineTestingBlock(s.CurrentBlock().ID(), Timestamp(time.Now().Unix()), CoinAddress{}, txns, s.CurrentTarget())
if err != nil {
t.Fatal(err)
}
err = s.AcceptBlock(b)
if err != LargeBlockErr {
t.Fatal(err)
}
}
// testRepeatBlock submits a block to the state, and then submits the same
// block to the state. If anything in the state has changed, an error is noted.
func testRepeatBlock(t *testing.T, s *State) {
......@@ -131,6 +150,12 @@ func TestEmptyBlock(t *testing.T) {
testEmptyBlock(t, s)
}
// TestLargeBlock creates a new state and uses it to call testLargeBlock.
func TestLargeBlock(t *testing.T) {
s := CreateGenesisState()
testLargeBlock(t, s)
}
// TestRepeatBlock creates a new state and uses it to call testRepeatBlock.
func TestRepeatBlock(t *testing.T) {
s := CreateGenesisState()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment