Files
evm/consensus/dummy/consensus_test.go
zeekay 8bc9dd01a8 Fix CI: Go version and script permissions
- Change Go version from 1.24.6 to 1.22.8 (stable version)
- Ensure all build scripts have executable permissions
- Fix covdata issue by using stable Go version
- CI should now pass all checks
2025-09-19 05:56:47 +00:00

136 lines
4.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package dummy
import (
"math"
"math/big"
"testing"
"github.com/luxfi/evm/commontype"
"github.com/luxfi/evm/plugin/evm/header"
"github.com/luxfi/geth/common"
"github.com/luxfi/geth/core/types"
)
var testFeeConfig = commontype.FeeConfig{
MinBlockGasCost: big.NewInt(0),
MaxBlockGasCost: big.NewInt(1_000_000),
TargetBlockRate: 2,
BlockGasCostStep: big.NewInt(50_000),
TargetGas: big.NewInt(10_000_000),
BaseFeeChangeDenominator: big.NewInt(12),
}
func TestVerifyBlockFee(t *testing.T) {
tests := map[string]struct {
baseFee *big.Int
parentBlockGasCost *big.Int
timeElapsed uint64
txs []*types.Transaction
receipts []*types.Receipt
shouldErr bool
}{
"tx only base fee": {
baseFee: big.NewInt(100),
parentBlockGasCost: big.NewInt(0),
timeElapsed: 0,
txs: []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100, big.NewInt(100), nil),
},
receipts: []*types.Receipt{
{GasUsed: 1000},
},
shouldErr: true,
},
"tx covers exactly block fee": {
baseFee: big.NewInt(100),
parentBlockGasCost: big.NewInt(0),
timeElapsed: 0,
txs: []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100_000, big.NewInt(200), nil),
},
receipts: []*types.Receipt{
{GasUsed: 100_000},
},
shouldErr: false,
},
"txs share block fee": {
baseFee: big.NewInt(100),
parentBlockGasCost: big.NewInt(0),
timeElapsed: 0,
txs: []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100_000, big.NewInt(200), nil),
types.NewTransaction(1, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100_000, big.NewInt(100), nil),
},
receipts: []*types.Receipt{
{GasUsed: 100_000},
{GasUsed: 100_000},
},
shouldErr: false,
},
"txs split block fee": {
baseFee: big.NewInt(100),
parentBlockGasCost: big.NewInt(0),
timeElapsed: 0,
txs: []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100_000, big.NewInt(150), nil),
types.NewTransaction(1, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100_000, big.NewInt(150), nil),
},
receipts: []*types.Receipt{
{GasUsed: 100_000},
{GasUsed: 100_000},
},
shouldErr: false,
},
"tx only base fee after full time window": {
baseFee: big.NewInt(100),
parentBlockGasCost: big.NewInt(500_000),
timeElapsed: testFeeConfig.TargetBlockRate + 10,
txs: []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100, big.NewInt(100), nil),
},
receipts: []*types.Receipt{
{GasUsed: 1000},
},
shouldErr: false,
},
"tx only base fee after large time window": {
baseFee: big.NewInt(100),
parentBlockGasCost: big.NewInt(100_000),
timeElapsed: math.MaxUint64,
txs: []*types.Transaction{
types.NewTransaction(0, common.HexToAddress("7ef5a6135f1fd6a02593eedc869c6d41d934aef8"), big.NewInt(0), 100, big.NewInt(100), nil),
},
receipts: []*types.Receipt{
{GasUsed: 1000},
},
shouldErr: false,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
blockGasCost := header.BlockGasCostWithStep(
testFeeConfig,
test.parentBlockGasCost,
testFeeConfig.BlockGasCostStep.Uint64(),
test.timeElapsed,
)
bigBlockGasCost := new(big.Int).SetUint64(blockGasCost)
engine := NewFaker()
if err := engine.verifyBlockFee(test.baseFee, bigBlockGasCost, test.txs, test.receipts); err != nil {
if !test.shouldErr {
t.Fatalf("Unexpected error: %s", err)
}
} else {
if test.shouldErr {
t.Fatal("Should have failed verification")
}
}
})
}
}