mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
core/types: fix test
This commit is contained in:
parent
8bd1d31872
commit
456a941e40
1 changed files with 21 additions and 7 deletions
|
|
@ -635,9 +635,6 @@ func BenchmarkEffectiveGasTip(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEffectiveGasTipInto(t *testing.T) {
|
func TestEffectiveGasTipInto(t *testing.T) {
|
||||||
signer := LatestSigner(params.TestChainConfig)
|
|
||||||
key, _ := crypto.GenerateKey()
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
tipCap int64
|
tipCap int64
|
||||||
feeCap int64
|
feeCap int64
|
||||||
|
|
@ -653,8 +650,26 @@ func TestEffectiveGasTipInto(t *testing.T) {
|
||||||
{tipCap: 50, feeCap: 100, baseFee: nil}, // nil base fee
|
{tipCap: 50, feeCap: 100, baseFee: nil}, // nil base fee
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// original, non-allocation golfed version
|
||||||
|
orig := func(tx *Transaction, baseFee *big.Int) (*big.Int, error) {
|
||||||
|
if baseFee == nil {
|
||||||
|
return tx.GasTipCap(), nil
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
gasFeeCap := tx.GasFeeCap()
|
||||||
|
if gasFeeCap.Cmp(baseFee) < 0 {
|
||||||
|
err = ErrGasFeeCapTooLow
|
||||||
|
}
|
||||||
|
gasFeeCap = gasFeeCap.Sub(gasFeeCap, baseFee)
|
||||||
|
gasTipCap := tx.GasTipCap()
|
||||||
|
if gasTipCap.Cmp(gasFeeCap) < 0 {
|
||||||
|
return gasTipCap, err
|
||||||
|
}
|
||||||
|
return gasFeeCap, err
|
||||||
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
txdata := &DynamicFeeTx{
|
tx := NewTx(&DynamicFeeTx{
|
||||||
ChainID: big.NewInt(1),
|
ChainID: big.NewInt(1),
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
GasTipCap: big.NewInt(tc.tipCap),
|
GasTipCap: big.NewInt(tc.tipCap),
|
||||||
|
|
@ -663,8 +678,7 @@ func TestEffectiveGasTipInto(t *testing.T) {
|
||||||
To: &common.Address{},
|
To: &common.Address{},
|
||||||
Value: big.NewInt(0),
|
Value: big.NewInt(0),
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
})
|
||||||
tx, _ := SignNewTx(key, signer, txdata)
|
|
||||||
|
|
||||||
var baseFee *big.Int
|
var baseFee *big.Int
|
||||||
var baseFee2 *uint256.Int
|
var baseFee2 *uint256.Int
|
||||||
|
|
@ -674,7 +688,7 @@ func TestEffectiveGasTipInto(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get result from original method
|
// Get result from original method
|
||||||
orig, origErr := tx.EffectiveGasTip(baseFee)
|
orig, origErr := orig(tx, baseFee)
|
||||||
|
|
||||||
// Get result from new method
|
// Get result from new method
|
||||||
dst := new(uint256.Int)
|
dst := new(uint256.Int)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue