mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 12:05:18 +00:00
646e376698
* update docker image to go 1.19 * update kvtool * add .tool-versions for automagic go version usage * update prtotonet genesis with missing params * update kvtool (fixes evm port exposure) * fix changed error message for insufficient fee * add error message on failed contract deployment * update kvtool (set consensus_params.block.max_gas) * temporarily disable ibc e2e tests * update kvtool to master
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
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 fee")
|
|
}
|
|
|
|
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, ";", ","))
|
|
}
|