Skip to content

Commit

Permalink
Add additional block tests (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
MakisChristou authored Nov 6, 2024
1 parent 9d5b515 commit 7a89780
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/rand"
"fmt"
"math/big"
"strings"
"testing"

"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -508,6 +509,54 @@ func TestVerifyBlock(t *testing.T) {
assert.Equal(t, err, expected)
},
},
{
"InvalidStateRoot", func(t *testing.T) {
header := tc.original.Header()
builder := new(block.Builder).
ParentID(header.ParentID()).
Timestamp(header.Timestamp()).
TotalScore(header.TotalScore()).
GasLimit(header.GasLimit()).
GasUsed(header.GasUsed()).
Beneficiary(header.Beneficiary()).
StateRoot(thor.Bytes32{123}).
ReceiptsRoot(header.ReceiptsRoot())
builder.TransactionFeatures(header.TxsFeatures())

blk, err := tc.sign(builder)
if err != nil {
t.Fatal(err)
}
expectedPrefix := "block state root mismatch"
err = tc.consent(blk)

assert.True(t, strings.HasPrefix(err.Error(), expectedPrefix))
},
},
{
"InvalidReceiptsRoot", func(t *testing.T) {
header := tc.original.Header()
builder := new(block.Builder).
ParentID(header.ParentID()).
Timestamp(header.Timestamp()).
TotalScore(header.TotalScore()).
GasLimit(header.GasLimit()).
GasUsed(header.GasUsed()).
Beneficiary(header.Beneficiary()).
StateRoot(header.StateRoot()).
ReceiptsRoot(thor.Bytes32{123})
builder.TransactionFeatures(header.TxsFeatures())

blk, err := tc.sign(builder)
if err != nil {
t.Fatal(err)
}
expectedPrefix := "block receipts root mismatch"
err = tc.consent(blk)

assert.True(t, strings.HasPrefix(err.Error(), expectedPrefix))
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -649,6 +698,27 @@ func TestValidateBlockBody(t *testing.T) {
assert.Equal(t, err, expected)
},
},
{
"ZeroGasTx", func(t *testing.T) {
txBuilder := new(tx.Builder).
GasPriceCoef(0).
Gas(0).
Expiration(100).
Clause(tx.NewClause(&thor.Address{}).WithValue(big.NewInt(0)).WithData(nil)).
Nonce(0).
ChainTag(30)

tx := txSign(txBuilder)

blk, err := tc.sign(tc.builder(tc.original.Header()).Transaction(tx).Transaction(tx))
if err != nil {
t.Fatal(err)
}

err = tc.consent(blk)
assert.Equal(t, "intrinsic gas exceeds provided gas", err.Error())
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 7a89780

Please sign in to comment.