0g-chain/tests/e2e/e2e_min_fees_test.go

78 lines
2.2 KiB
Go
Raw Normal View History

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"
2024-08-03 09:51:56 +00:00
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/tests/util"
)
func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
`x/community` events and e2e test improvements (#1766) * Initial e2e setup * Fix inflation disable tests * Add upgrade handler * Add param tests for after upgrade * Replace deprecated grpc creds * Remove upgrade for e2e test * Update upgrade handler to set x/community params * Remove params check in upgrade * Update tests for switchover time and params check * wip inflation * Add attribute to disable inflation event * Add before/after switchover mint and dist checks * Add missing attribute to disable inflation test check * Check mint events are 0 * Check total supply doesn't change * Check inflation and events before switchover * Check staking reward payouts from x/community * move events funcs to util * Add keyring to chain, fetch keys from kvtool and test withdrawal * Remove duplicate KavaHomePath * Update subtest names to specify before/after switchover Co-authored-by: Draco <draco@dracoli.com> * Use blocktime for InflationStop event DisableTime * Test 5 blocks for staking rewards payout * Remove logging and unused lines * Check val claimed balance with queried * Enable and update consolidation tests * Update test for modified EventTypeInflationStop time attr * Test x/distribution community tax * Fix test names * Update e2e tests for better live network test support (#1749) * Update e2e tests to support mirrornet * Skip claim rewards on live network, require no errors for existing tests * Update readme with upgrade height * Update .env example with usdt contract address * Restore .env file to original local e2e * Log community params when set * Make AttributeKeyInflationDisableTime more precise * Add mainnet and testnet community params (#1753) * Re-enable ibc tests * Remove duplicate types.EventTypeInflationStop emit * feat: set validator minimum commissions to at least 5% in upgrade handler (#1761) * Update validator min commission in upgrade * Add min commission upgrade test * Update changelog * Set validator MaxRate, call BeforeValidatorModified hook * Check max commission and update time in tests * Update e2e test for max rate * Test val update time * Use SdkBlock instead of Block * Remove upgrade related handlers and tests Preserve any module and test util changes * Update e2e x/community params proposal test to work without upgrade handler --------- Co-authored-by: Draco <draco@dracoli.com>
2023-10-31 23:37:40 +00:00
suite.SkipIfKvtoolDisabled()
// read expected min fee from app.toml
2024-08-03 13:44:37 +00:00
minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath())
suite.NoError(err)
2024-08-03 13:44:37 +00:00
// evm uses neuron, get neuron min fee
2024-08-03 14:17:29 +00:00
evmMinGas := minGasPrices.AmountOf("neuron").TruncateInt().BigInt()
2024-08-03 13:44:37 +00:00
// returns eth_gasPrice, units in a0gi
gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background())
suite.NoError(err)
suite.Equal(evmMinGas, gasPrice)
}
func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
`x/community` events and e2e test improvements (#1766) * Initial e2e setup * Fix inflation disable tests * Add upgrade handler * Add param tests for after upgrade * Replace deprecated grpc creds * Remove upgrade for e2e test * Update upgrade handler to set x/community params * Remove params check in upgrade * Update tests for switchover time and params check * wip inflation * Add attribute to disable inflation event * Add before/after switchover mint and dist checks * Add missing attribute to disable inflation test check * Check mint events are 0 * Check total supply doesn't change * Check inflation and events before switchover * Check staking reward payouts from x/community * move events funcs to util * Add keyring to chain, fetch keys from kvtool and test withdrawal * Remove duplicate KavaHomePath * Update subtest names to specify before/after switchover Co-authored-by: Draco <draco@dracoli.com> * Use blocktime for InflationStop event DisableTime * Test 5 blocks for staking rewards payout * Remove logging and unused lines * Check val claimed balance with queried * Enable and update consolidation tests * Update test for modified EventTypeInflationStop time attr * Test x/distribution community tax * Fix test names * Update e2e tests for better live network test support (#1749) * Update e2e tests to support mirrornet * Skip claim rewards on live network, require no errors for existing tests * Update readme with upgrade height * Update .env example with usdt contract address * Restore .env file to original local e2e * Log community params when set * Make AttributeKeyInflationDisableTime more precise * Add mainnet and testnet community params (#1753) * Re-enable ibc tests * Remove duplicate types.EventTypeInflationStop emit * feat: set validator minimum commissions to at least 5% in upgrade handler (#1761) * Update validator min commission in upgrade * Add min commission upgrade test * Update changelog * Set validator MaxRate, call BeforeValidatorModified hook * Check max commission and update time in tests * Update e2e test for max rate * Test val update time * Use SdkBlock instead of Block * Remove upgrade related handlers and tests Preserve any module and test util changes * Update e2e x/community params proposal test to work without upgrade handler --------- Co-authored-by: Draco <draco@dracoli.com>
2023-10-31 23:37:40 +00:00
suite.SkipIfKvtoolDisabled()
// setup sender & receiver
2024-08-03 13:44:37 +00:00
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(a0gi(big.NewInt(1e3))))
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
// get min gas price for evm (from app.toml)
2024-08-03 13:44:37 +00:00
minFees, err := getMinFeeFromAppToml(util.ZgChainHomePath())
suite.NoError(err)
2024-08-03 14:17:29 +00:00
minGasPrice := minFees.AmountOf("neuron").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(5e2), 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")
}
2024-08-03 13:44:37 +00:00
func getMinFeeFromAppToml(zgChainHome string) (sdk.DecCoins, error) {
// read the expected min gas price from app.toml
parsed := struct {
MinGasPrices string `toml:"minimum-gas-prices"`
}{}
2024-08-03 13:44:37 +00:00
appToml, err := os.ReadFile(filepath.Join(zgChainHome, "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, ";", ","))
}