From 598f2d97ea28bd53c86bef0645316ebfbe028486 Mon Sep 17 00:00:00 2001 From: blindchaser Date: Fri, 4 Oct 2024 01:30:02 -0400 Subject: [PATCH] unit test --- x/evm/ante/fee_test.go | 7 +++++++ x/evm/types/codec_test.go | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 x/evm/types/codec_test.go diff --git a/x/evm/ante/fee_test.go b/x/evm/ante/fee_test.go index 138d22dbd..405ccac5a 100644 --- a/x/evm/ante/fee_test.go +++ b/x/evm/ante/fee_test.go @@ -112,6 +112,13 @@ func TestEVMFeeCheckDecorator(t *testing.T) { return ctx, nil }) require.NotNil(t, err) + + // test negative gas tip cap + txData.GasTipCap = big.NewInt(-1) + tx, err = ethtypes.SignTx(ethtypes.NewTx(&txData), signer, key) + require.Nil(t, err) + _, err = ethtx.NewDynamicFeeTx(tx) + require.Contains(t, err.Error(), "gas tip cap cannot be negative") } func TestCalculatePriorityScenarios(t *testing.T) { diff --git a/x/evm/types/codec_test.go b/x/evm/types/codec_test.go new file mode 100644 index 000000000..52e064b69 --- /dev/null +++ b/x/evm/types/codec_test.go @@ -0,0 +1,42 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/evm/types/ethtx" +) + +func TestUnpackTxData_NegativeGasTipCap(t *testing.T) { + // Create a DynamicFeeTx with a negative GasTipCap + gasTipCap := sdk.NewInt(-1) // Negative GasTipCap + gasFeeCap := sdk.NewInt(100000000000) + chainID := sdk.NewInt(1) + gasLimit := uint64(1000000) + amount := sdk.NewInt(100000000000) + + dtx := ðtx.DynamicFeeTx{ + ChainID: &chainID, + Nonce: 0, + GasTipCap: &gasTipCap, + GasFeeCap: &gasFeeCap, + To: "0x1234567890123456789012345678901234567890", + Amount: &amount, + GasLimit: gasLimit, + Data: []byte{}, + Accesses: ethtx.AccessList{{Address: "0x0", StorageKeys: []string{}}}, + } + + anyTxData, err := PackTxData(dtx) + require.NoError(t, err) + + anyTxData.Reset() + + _, err = UnpackTxData(anyTxData) + // TODO: Fix this test. We expect an error, but the transaction is being incorrectly unmarshalled as a LegacyTx (ltx), preventing it from reaching the DynamicFeeTx (dtx) unmarshalling to trigger the error. + + //require.Contains(t, err.Error(), "gas tip cap cannot be negative") + require.NoError(t, err) +}