From 10ed18ba1299f60fa2bd9e4d9b28762f1a273da1 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 11 Apr 2023 09:10:55 -0400 Subject: [PATCH] test: messagepool: gas rewards are negative if GasFeeCap too low --- chain/messagepool/messagepool_test.go | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/chain/messagepool/messagepool_test.go b/chain/messagepool/messagepool_test.go index a781b5074..3c6800d7b 100644 --- a/chain/messagepool/messagepool_test.go +++ b/chain/messagepool/messagepool_test.go @@ -11,9 +11,11 @@ import ( "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + big2 "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/network" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" @@ -524,6 +526,36 @@ func TestPruningSimple(t *testing.T) { } } +func TestGasRewardNegative(t *testing.T) { + var mp MessagePool + + msg := types.SignedMessage{ + Message: types.Message{ + GasLimit: 1000, + GasFeeCap: big2.NewInt(20000), + GasPremium: big2.NewInt(15000), + }, + } + baseFee := big2.NewInt(30000) + // Over the GasPremium, but under the BaseFee + gr1 := mp.getGasReward(&msg, baseFee) + + msg.Message.GasFeeCap = big2.NewInt(15000) + // Equal to GasPremium, under the BaseFee + gr2 := mp.getGasReward(&msg, baseFee) + + msg.Message.GasFeeCap = big2.NewInt(10000) + // Under both GasPremium and BaseFee + gr3 := mp.getGasReward(&msg, baseFee) + + require.True(t, gr1.Sign() < 0) + require.True(t, gr2.Sign() < 0) + require.True(t, gr3.Sign() < 0) + + require.True(t, gr1.Cmp(gr2) > 0) + require.True(t, gr2.Cmp(gr3) > 0) +} + func TestLoadLocal(t *testing.T) { tma := newTestMpoolAPI() ds := datastore.NewMapDatastore()