diff --git a/tests/e2e/e2e_min_fees_test.go b/tests/e2e/e2e_min_fees_test.go new file mode 100644 index 00000000..1e25d769 --- /dev/null +++ b/tests/e2e/e2e_min_fees_test.go @@ -0,0 +1,73 @@ +package e2e_test + +import ( + "context" + "math/big" + "os" + "path/filepath" + "strings" + + "github.com/pelletier/go-toml/v2" + + sdk "github.com/cosmos/cosmos-sdk/types" + ethtypes "github.com/ethereum/go-ethereum/core/types" + + "github.com/kava-labs/kava/app" + "github.com/kava-labs/kava/tests/util" +) + +func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() { + // read expected min fee from app.toml + minGasPrices, err := getMinFeeFromAppToml(suite.KavaHomePath()) + suite.NoError(err) + + // evm uses akava, get akava min fee + evmMinGas := minGasPrices.AmountOf("akava").TruncateInt().BigInt() + + // returns eth_gasPrice, units in kava + gasPrice, err := suite.Kava.EvmClient.SuggestGasPrice(context.Background()) + suite.NoError(err) + + suite.Equal(evmMinGas, gasPrice) +} + +func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() { + // setup sender & receiver + sender := suite.Kava.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(ukava(2e6))) + randoReceiver := util.SdkToEvmAddress(app.RandomAddress()) + + // get min gas price for evm (from app.toml) + minFees, err := getMinFeeFromAppToml(suite.KavaHomePath()) + suite.NoError(err) + minGasPrice := minFees.AmountOf("akava").TruncateInt() + + // attempt tx with less than min gas price (min fee - 1) + tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt() + req := util.EvmTxRequest{ + Tx: ethtypes.NewTransaction(0, randoReceiver, big.NewInt(1e6), 1e5, tooLowGasPrice, nil), + Data: "this tx should fail because it's gas price is too low", + } + res := sender.SignAndBroadcastEvmTx(req) + + // expect the tx to fail! + suite.ErrorAs(res.Err, &util.ErrEvmFailedToBroadcast{}) + suite.ErrorContains(res.Err, "insufficient fees") +} + +func getMinFeeFromAppToml(kavaHome string) (sdk.DecCoins, error) { + // read the expected min gas price from app.toml + parsed := struct { + MinGasPrices string `toml:"minimum-gas-prices"` + }{} + appToml, err := os.ReadFile(filepath.Join(kavaHome, "config", "app.toml")) + if err != nil { + return nil, err + } + err = toml.Unmarshal(appToml, &parsed) + if err != nil { + return nil, err + } + + // convert to dec coins + return sdk.ParseDecCoins(strings.ReplaceAll(parsed.MinGasPrices, ";", ",")) +} diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 2021d006..4c534b52 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -170,5 +170,5 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() { } } return found - }, 10*time.Second, 1*time.Second) + }, 15*time.Second, 1*time.Second) } diff --git a/tests/e2e/kvtool b/tests/e2e/kvtool index 8adc0437..8153036b 160000 --- a/tests/e2e/kvtool +++ b/tests/e2e/kvtool @@ -1 +1 @@ -Subproject commit 8adc0437e849f86bdcb2df3833abbfbd0980775e +Subproject commit 8153036b95a930c7830c6969d1653165afa65f2c diff --git a/tests/e2e/testutil/suite.go b/tests/e2e/testutil/suite.go index 594d7aa3..47a5c8cd 100644 --- a/tests/e2e/testutil/suite.go +++ b/tests/e2e/testutil/suite.go @@ -2,6 +2,7 @@ package testutil import ( "fmt" + "path/filepath" "github.com/stretchr/testify/suite" @@ -96,3 +97,9 @@ func (suite *E2eTestSuite) SkipIfUpgradeDisabled() { suite.T().SkipNow() } } + +// KavaHomePath returns the OS-specific filepath for the kava home directory +// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool +func (suite *E2eTestSuite) KavaHomePath() string { + return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava") +} diff --git a/tests/util/evmsigner.go b/tests/util/evmsigner.go index 484ae560..aeb421be 100644 --- a/tests/util/evmsigner.go +++ b/tests/util/evmsigner.go @@ -23,15 +23,15 @@ type EvmTxResponse struct { Err error } -type EvmFailedToSignError struct{ Err error } +type ErrEvmFailedToSign struct{ Err error } -func (e EvmFailedToSignError) Error() string { +func (e ErrEvmFailedToSign) Error() string { return fmt.Sprintf("failed to sign tx: %s", e.Err) } -type EvmFailedToBroadcastError struct{ Err error } +type ErrEvmFailedToBroadcast struct{ Err error } -func (e EvmFailedToBroadcastError) Error() string { +func (e ErrEvmFailedToBroadcast) Error() string { return fmt.Sprintf("failed to broadcast tx: %s", e.Err) } @@ -79,11 +79,11 @@ func (s *EvmSigner) Run(requests <-chan EvmTxRequest) <-chan EvmTxResponse { signedTx, err := s.auth.Signer(s.signerAddress, req.Tx) if err != nil { - err = EvmFailedToSignError{Err: err} + err = ErrEvmFailedToSign{Err: err} } else { err = s.EvmClient.SendTransaction(context.Background(), signedTx) if err != nil { - err = EvmFailedToBroadcastError{Err: err} + err = ErrEvmFailedToBroadcast{Err: err} } }