Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
blindchaser committed Oct 4, 2024
1 parent c5890f3 commit 598f2d9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions x/evm/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 42 additions & 0 deletions x/evm/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -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 := &ethtx.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)
}

0 comments on commit 598f2d9

Please sign in to comment.