Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first tests #863

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"crypto/rand"
"fmt"
"math/big"
"strings"
"testing"

"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -508,6 +509,54 @@
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 @@ -650,6 +699,28 @@
assert.Equal(t, err, expected)
},
},
{

Check failure on line 702 in consensus/consensus_test.go

View workflow job for this annotation

GitHub Actions / Lint / golangci-lint

unnecessary leading newline (whitespace)
"EmptyTx", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be renamed to ZeroGasTx since it's focusing on sending a tx with 0 gas

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than ^ looks good


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
Loading