erigon-pulse/consensus/misc/eip1559_test.go
ledgerwatch 12cde41772
Aleut support (Eip1559) (#1704)
* Where I am at

* Refactoring of transaction types

* More refactoring

* Use Homested signer in rpc daemon

* Unified signer

* Continue unified signer

* A bit more

* Fixes and down the rabbit hole...

* More tx pool fixes

* More refactoring fixes

* More fixes'

* more fixes

* More fixes

* More compile fixes

* More RLP hand-writing

* Finish RLP encoding/decoding of transactions

* Fixes to header encoding, start on protocol packets

* Transaction decoding

* Use DecodeTransaction function

* Decoding BlockBodyPacket

* Encode and decode for pool txs

* Start fixing tests

* Introduce SigningHash

* Fixes to SignHash

* RLP encoding fixes

* Fixes for encoding/decoding

* More test fixes

* Fix more tests

* More test fixes

* More test fixes

* Fix core tests

* More fixes for signer

* Fix for tx

* Fixes to string encoding/size

* Fix eip2930 test

* Fix rest of ./tests

* More fixes

* Fix compilation

* More test fixes

* More test fixes

* Test fixes

* More fixes

* Reuse EncodingSize in EncodeRLP for accessList

* Rearrange things in dynamic fee tx

* Add MarshalBinary

* More fixes

* Make V,R,S non-pointers

* More NPE fixes

* More fixes

* Receipt fixes

* Fix core/types

* Fix ./eth

* More compile fixes for tests

* More test fixes

* More test fixes

* Try to see lint errors better

* Try to see lint errors better

* Fix lint

* Debugging eip1559 test

* Fix TestEIP1559Transition test

* Fix NewBlockPacket encoding/decoding

* Fix calculation of TxHash

* Fix perf problem with senders

* Update aleut config values

* Try adding static peers

* Add staticpeers to defaul flags

* Change aleut networkID

* Fix test

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 18:11:37 +01:00

75 lines
1.9 KiB
Go

package misc
import (
"fmt"
"math/big"
"testing"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/params"
)
func TestBlockElasticity(t *testing.T) {
initial := new(big.Int).SetUint64(params.InitialBaseFee)
parent := &types.Header{
GasUsed: 10000000,
GasLimit: 10000000,
BaseFee: initial,
}
header := &types.Header{
GasUsed: 20000000,
GasLimit: 10000000,
BaseFee: initial,
}
if err := VerifyEip1559Header(parent, header, false); err != nil {
t.Errorf("Expected valid header: %s", err)
}
header.GasUsed += 1
expected := fmt.Sprintf("exceeded elasticity multiplier: gasUsed %d, gasTarget*elasticityMultiplier %d", header.GasUsed, header.GasLimit*params.ElasticityMultiplier)
if err := VerifyEip1559Header(parent, header, false); fmt.Sprint(err) != expected {
t.Errorf("Expected invalid header")
}
}
func TestCalcBaseFee(t *testing.T) {
tests := []struct {
parentBaseFee *big.Int
parentGasLimit uint64
parentGasUsed uint64
expectedBaseFee *big.Int
}{
// baseFee should remain unchaned when the gasUsed is equal to the gasTarget
{
new(big.Int).SetUint64(params.InitialBaseFee),
10000000,
10000000,
new(big.Int).SetUint64(params.InitialBaseFee),
},
// baseFee should decrease when the gasUsed is below the gasTarget
{
new(big.Int).SetUint64(params.InitialBaseFee),
10000000,
9000000,
new(big.Int).SetUint64(987500000),
},
// baseFee should increase when the gasUsed is below the gasTarget
{
new(big.Int).SetUint64(params.InitialBaseFee),
10000000,
11000000,
new(big.Int).SetUint64(1012500000),
},
}
for i, test := range tests {
parent := &types.Header{
GasLimit: test.parentGasLimit,
GasUsed: test.parentGasUsed,
BaseFee: test.parentBaseFee,
}
baseFee := CalcBaseFee(parent)
if baseFee.Cmp(test.expectedBaseFee) != 0 {
t.Errorf("Test %d: expected %d, got %d", i+1, test.expectedBaseFee.Int64(), baseFee.Int64())
}
}
}