mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-04 00:37:28 +00:00 
			
		
		
		
	add evm min fee e2e tests (#1521)
* parse min gas price from app.toml * test eth_gasPrice returns min fee * use naming best practices for custom errors * add test that evm respects min gas price * update kvtool * increase ibc test wait time & update kvtool
This commit is contained in:
		
							parent
							
								
									0156b0e645
								
							
						
					
					
						commit
						6a1438fbe9
					
				
							
								
								
									
										73
									
								
								tests/e2e/e2e_min_fees_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								tests/e2e/e2e_min_fees_test.go
									
									
									
									
									
										Normal file
									
								
							@ -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, ";", ","))
 | 
			
		||||
}
 | 
			
		||||
@ -170,5 +170,5 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() {
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return found
 | 
			
		||||
	}, 10*time.Second, 1*time.Second)
 | 
			
		||||
	}, 15*time.Second, 1*time.Second)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1 +1 @@
 | 
			
		||||
Subproject commit 8adc0437e849f86bdcb2df3833abbfbd0980775e
 | 
			
		||||
Subproject commit 8153036b95a930c7830c6969d1653165afa65f2c
 | 
			
		||||
@ -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")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user