mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
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>
This commit is contained in:
parent
84f84c4eec
commit
6998196461
@ -54,7 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
- (community) [#1729] Consolidate community funds from `x/distribution` and `x/kavadist` to `x/community`
|
||||
- (community) [#1752] Set `x/distribution` CommunityTax to zero on inflation disable upgrade
|
||||
- (community) [#1755] Keep funds in `x/community` in `CommunityPoolLendWithdrawProposal` handler
|
||||
|
||||
- (staking) [#1761] Set validator minimum commission to 5% for all validators under 5%
|
||||
|
||||
## [v0.24.1](https://github.com/Kava-Labs/kava/releases/tag/v0.24.1)
|
||||
|
||||
@ -303,6 +303,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
|
||||
large-scale simulations remotely using aws-batch
|
||||
|
||||
[#1755]: https://github.com/Kava-Labs/kava/pull/1755
|
||||
[#1761]: https://github.com/Kava-Labs/kava/pull/1761
|
||||
[#1752]: https://github.com/Kava-Labs/kava/pull/1752
|
||||
[#1751]: https://github.com/Kava-Labs/kava/pull/1751
|
||||
[#1745]: https://github.com/Kava-Labs/kava/pull/1745
|
||||
|
@ -20,4 +20,5 @@ E2E_INCLUDE_IBC_TESTS=false
|
||||
# - the evmutil params must support conversion & deposits to mint in eip712 messages
|
||||
#
|
||||
# These requirements are verified on test startup in ./testutil/init_evm.go
|
||||
E2E_KAVA_ERC20_ADDRESS=0xeA7100edA2f805356291B0E55DaD448599a72C6d
|
||||
# This address is a USDT contract
|
||||
E2E_KAVA_ERC20_ADDRESS=0x919c1c267bc06a7039e03fcc2ef738525769109c
|
||||
|
@ -72,15 +72,38 @@ func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() {
|
||||
gasLimit := int64(2e5)
|
||||
fee := ukava(200)
|
||||
|
||||
upgradeTime := time.Now().Add(24 * time.Hour).UTC()
|
||||
// Wait until switchover actually happens - When testing without the upgrade
|
||||
// handler that sets a relative switchover time, the switchover time in
|
||||
// genesis should be set in the past so it runs immediately.
|
||||
suite.Require().Eventually(
|
||||
func() bool {
|
||||
params, err := suite.Kava.Community.Params(
|
||||
context.Background(),
|
||||
&communitytypes.QueryParamsRequest{},
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
return params.Params.UpgradeTimeDisableInflation.Equal(time.Time{})
|
||||
},
|
||||
20*time.Second,
|
||||
1*time.Second,
|
||||
"switchover should happen",
|
||||
)
|
||||
|
||||
// Add 1 to the staking rewards per second
|
||||
newStakingRewardsPerSecond := communityParamsResInitial.Params.
|
||||
StakingRewardsPerSecond.
|
||||
Add(sdkmath.LegacyNewDec(1))
|
||||
|
||||
// 1. Proposal
|
||||
// Only modify stakingRewardsPerSecond, as to not re-run the switchover and
|
||||
// to not influence other tests
|
||||
updateParamsMsg := communitytypes.NewMsgUpdateParams(
|
||||
authtypes.NewModuleAddress(govtypes.ModuleName), // authority
|
||||
communitytypes.NewParams(
|
||||
upgradeTime,
|
||||
sdkmath.LegacyNewDec(1111), // stakingRewardsPerSecond
|
||||
sdkmath.LegacyNewDec(2222), // upgradeTimeSetstakingRewardsPerSecond
|
||||
time.Time{}, // after switchover, is empty
|
||||
newStakingRewardsPerSecond, // only modify stakingRewardsPerSecond
|
||||
communityParamsResInitial.Params.UpgradeTimeSetStakingRewardsPerSecond,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -198,8 +198,8 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
suite.NoError(err)
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Tx, res.TxResponse.TxHash, 12*time.Second)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// query for the deployed contract
|
||||
deployedContracts, err := suite.Kava.Evmutil.DeployedCosmosCoinContracts(
|
||||
@ -394,7 +394,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
Data: "bob transfers alice's funds, allowed because he's approved",
|
||||
}
|
||||
res = bob.SignAndBroadcastEvmTx(transferJustRightTx)
|
||||
suite.NoError(res.Err)
|
||||
suite.Require().NoError(res.Err)
|
||||
|
||||
// alice should have amount deducted
|
||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
|
@ -17,8 +17,10 @@ import (
|
||||
)
|
||||
|
||||
func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
|
||||
suite.SkipIfKvtoolDisabled()
|
||||
|
||||
// read expected min fee from app.toml
|
||||
minGasPrices, err := getMinFeeFromAppToml(suite.KavaHomePath())
|
||||
minGasPrices, err := getMinFeeFromAppToml(util.KavaHomePath())
|
||||
suite.NoError(err)
|
||||
|
||||
// evm uses akava, get akava min fee
|
||||
@ -32,12 +34,14 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
||||
suite.SkipIfKvtoolDisabled()
|
||||
|
||||
// setup sender & receiver
|
||||
sender := suite.Kava.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(ukava(1e3)))
|
||||
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
|
||||
|
||||
// get min gas price for evm (from app.toml)
|
||||
minFees, err := getMinFeeFromAppToml(suite.KavaHomePath())
|
||||
minFees, err := getMinFeeFromAppToml(util.KavaHomePath())
|
||||
suite.NoError(err)
|
||||
minGasPrice := minFees.AmountOf("akava").TruncateInt()
|
||||
|
||||
|
@ -41,7 +41,7 @@ func TestIntegrationTestSuite(t *testing.T) {
|
||||
|
||||
// example test that queries kava via SDK and EVM
|
||||
func (suite *IntegrationTestSuite) TestChainID() {
|
||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainId)
|
||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainID)
|
||||
suite.NoError(err)
|
||||
|
||||
// EVM query
|
||||
@ -52,7 +52,7 @@ func (suite *IntegrationTestSuite) TestChainID() {
|
||||
// SDK query
|
||||
nodeInfo, err := suite.Kava.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||
suite.NoError(err)
|
||||
suite.Equal(suite.Kava.ChainId, nodeInfo.DefaultNodeInfo.Network)
|
||||
suite.Equal(suite.Kava.ChainID, nodeInfo.DefaultNodeInfo.Network)
|
||||
}
|
||||
|
||||
// example test that funds a new account & queries its balance
|
||||
@ -99,7 +99,7 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||
Data: "any ol' data to track this through the system",
|
||||
}
|
||||
res := acc.SignAndBroadcastEvmTx(req)
|
||||
suite.NoError(res.Err)
|
||||
suite.Require().NoError(res.Err)
|
||||
suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)
|
||||
|
||||
// evm txs refund unused gas. so to know the expected balance we need to know how much gas was used.
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 6184dc56e9b8ee94a2fe9a1e0c165d6c1129fa42
|
||||
Subproject commit e1085562d203fd81c5dd8576170b29715b2de9ef
|
@ -27,12 +27,17 @@ The end-to-end tests support being run on a live network. The primary toggle for
|
||||
* `E2E_KAVA_RPC_URL`
|
||||
* `E2E_KAVA_GRPC_URL`
|
||||
* `E2E_KAVA_EVM_RPC_URL`
|
||||
* `E2E_KAVA_UPGRADE_HEIGHT` - the height at which an existing upgrade was run
|
||||
|
||||
See an example environment configuration with full description of all supported configurations in [`.env.live-network-example`](./.env.live-network-example). This example expects a local kvtool network to be running: `kvtool testnet bootstrap`.
|
||||
|
||||
When run against a live network, the suite will automatically return all the sdk funds sent to `SigningAccount`s on the chain, and will return any ERC20 balance from those accounts if the ERC20 is registered via `Chain.RegisterERC20`. The pre-deployed ERC20 that is required for the tests is registered on setup.
|
||||
|
||||
At this time, live-network tests do not support `E2E_INCLUDE_IBC_TESTS=true` and they do not support automated upgrades.
|
||||
At this time, live-network tests do not support `E2E_INCLUDE_IBC_TESTS=true`.
|
||||
|
||||
`E2E_KAVA_UPGRADE_HEIGHT` is supported for an existing upgrade height, and can
|
||||
be used to verify before / after upgrade state. This doesn't run automatically
|
||||
any upgrades.
|
||||
|
||||
## `Chain`s
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
rpchttpclient "github.com/tendermint/tendermint/rpc/client/http"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/kava-labs/kava/tests/util"
|
||||
@ -34,6 +35,11 @@ func (c ChainDetails) GrpcConn() (*grpc.ClientConn, error) {
|
||||
return util.NewGrpcConnection(c.GrpcUrl)
|
||||
}
|
||||
|
||||
// RpcConn creates a new connection to the underlying Rpc url.
|
||||
func (c ChainDetails) RpcConn() (*rpchttpclient.HTTP, error) {
|
||||
return rpchttpclient.New(c.RpcUrl, "/websocket")
|
||||
}
|
||||
|
||||
// Chains wraps a map of name -> details about how to connect to a chain.
|
||||
// It prevents registering multiple chains with the same name & encapsulates
|
||||
// panicking if attempting to access a chain that does not exist.
|
||||
|
@ -14,6 +14,8 @@ type LiveNodeRunnerConfig struct {
|
||||
KavaRpcUrl string
|
||||
KavaGrpcUrl string
|
||||
KavaEvmRpcUrl string
|
||||
|
||||
UpgradeHeight int64
|
||||
}
|
||||
|
||||
// LiveNodeRunner implements NodeRunner for an already-running chain.
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/go-bip39"
|
||||
@ -37,7 +38,7 @@ type SigningAccount struct {
|
||||
name string
|
||||
mnemonic string
|
||||
|
||||
evmPrivKey *ethsecp256k1.PrivKey
|
||||
evmPrivKey cryptotypes.PrivKey
|
||||
evmSigner *util.EvmSigner
|
||||
evmReqChan chan<- util.EvmTxRequest
|
||||
evmResChan <-chan util.EvmTxResponse
|
||||
@ -76,6 +77,27 @@ func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, ch
|
||||
require.NoErrorf(chain.t, err, "failed to derive private key from mnemonic for %s: %s", name, err)
|
||||
privKey := ðsecp256k1.PrivKey{Key: privKeyBytes}
|
||||
|
||||
return chain.AddNewSigningAccountFromPrivKey(
|
||||
name,
|
||||
privKey,
|
||||
mnemonic,
|
||||
chainId,
|
||||
)
|
||||
}
|
||||
|
||||
// AddNewSigningAccountFromPrivKey sets up a new account with a signer for SDK and EVM transactions,
|
||||
// using the given private key.
|
||||
func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
name string,
|
||||
privKey cryptotypes.PrivKey,
|
||||
mnemonic string, // optional
|
||||
chainId string,
|
||||
) *SigningAccount {
|
||||
if _, found := chain.accounts[name]; found {
|
||||
chain.t.Fatalf("account with name %s already exists", name)
|
||||
}
|
||||
|
||||
// Kava signing account for SDK side
|
||||
kavaSigner := util.NewKavaSigner(
|
||||
chainId,
|
||||
chain.EncodingConfig,
|
||||
@ -92,7 +114,7 @@ func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, ch
|
||||
// Kava signing account for EVM side
|
||||
evmChainId, err := emtypes.ParseChainID(chainId)
|
||||
require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId)
|
||||
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKeyBytes))
|
||||
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
|
||||
require.NoError(chain.t, err, "failed to generate ECDSA private key from bytes")
|
||||
|
||||
evmSigner, err := util.NewEvmSigner(
|
||||
@ -201,7 +223,7 @@ func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccou
|
||||
acc := chain.AddNewSigningAccount(
|
||||
name,
|
||||
hd.CreateHDPath(app.Bip44CoinType, 0, 0),
|
||||
chain.ChainId,
|
||||
chain.ChainID,
|
||||
mnemonic,
|
||||
)
|
||||
|
||||
|
@ -10,12 +10,19 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
evmhd "github.com/evmos/ethermint/crypto/hd"
|
||||
tmclient "github.com/tendermint/tendermint/rpc/client"
|
||||
coretypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@ -32,6 +39,7 @@ import (
|
||||
communitytypes "github.com/kava-labs/kava/x/community/types"
|
||||
earntypes "github.com/kava-labs/kava/x/earn/types"
|
||||
evmutiltypes "github.com/kava-labs/kava/x/evmutil/types"
|
||||
kavadisttypes "github.com/kava-labs/kava/x/kavadist/types"
|
||||
)
|
||||
|
||||
// Chain wraps query clients & accounts for a network
|
||||
@ -40,7 +48,8 @@ type Chain struct {
|
||||
t *testing.T
|
||||
|
||||
StakingDenom string
|
||||
ChainId string
|
||||
ChainID string
|
||||
Keyring keyring.Keyring
|
||||
|
||||
EvmClient *ethclient.Client
|
||||
ContractAddrs map[string]common.Address
|
||||
@ -53,13 +62,19 @@ type Chain struct {
|
||||
Cdp cdptypes.QueryClient
|
||||
Committee committeetypes.QueryClient
|
||||
Community communitytypes.QueryClient
|
||||
Distribution distrtypes.QueryClient
|
||||
Kavadist kavadisttypes.QueryClient
|
||||
Earn earntypes.QueryClient
|
||||
Evm evmtypes.QueryClient
|
||||
Evmutil evmutiltypes.QueryClient
|
||||
Gov govv1types.QueryClient
|
||||
Mint minttypes.QueryClient
|
||||
Staking stakingtypes.QueryClient
|
||||
Tm tmservice.ServiceClient
|
||||
Tx txtypes.ServiceClient
|
||||
Upgrade upgradetypes.QueryClient
|
||||
|
||||
TmSignClient tmclient.SignClient
|
||||
}
|
||||
|
||||
// NewChain creates the query clients & signing account management for a chain run on a set of ports.
|
||||
@ -69,12 +84,26 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
||||
chain := &Chain{
|
||||
t: t,
|
||||
StakingDenom: details.StakingDenom,
|
||||
ChainId: details.ChainId,
|
||||
ChainID: details.ChainId,
|
||||
ContractAddrs: make(map[string]common.Address),
|
||||
erc20s: make(map[common.Address]struct{}),
|
||||
}
|
||||
chain.EncodingConfig = app.MakeEncodingConfig()
|
||||
|
||||
// setup keyring
|
||||
kr, err := keyring.New(
|
||||
sdk.KeyringServiceName(),
|
||||
keyring.BackendTest,
|
||||
util.KavaHomePath(),
|
||||
nil,
|
||||
chain.EncodingConfig.Marshaler,
|
||||
evmhd.EthSecp256k1Option(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chain.Keyring = kr
|
||||
|
||||
grpcConn, err := details.GrpcConn()
|
||||
if err != nil {
|
||||
return chain, err
|
||||
@ -85,15 +114,24 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
||||
return chain, err
|
||||
}
|
||||
|
||||
chain.TmSignClient, err = details.RpcConn()
|
||||
if err != nil {
|
||||
return chain, err
|
||||
}
|
||||
|
||||
chain.Auth = authtypes.NewQueryClient(grpcConn)
|
||||
chain.Bank = banktypes.NewQueryClient(grpcConn)
|
||||
chain.Cdp = cdptypes.NewQueryClient(grpcConn)
|
||||
chain.Committee = committeetypes.NewQueryClient(grpcConn)
|
||||
chain.Community = communitytypes.NewQueryClient(grpcConn)
|
||||
chain.Distribution = distrtypes.NewQueryClient(grpcConn)
|
||||
chain.Kavadist = kavadisttypes.NewQueryClient(grpcConn)
|
||||
chain.Earn = earntypes.NewQueryClient(grpcConn)
|
||||
chain.Evm = evmtypes.NewQueryClient(grpcConn)
|
||||
chain.Evmutil = evmutiltypes.NewQueryClient(grpcConn)
|
||||
chain.Gov = govv1types.NewQueryClient(grpcConn)
|
||||
chain.Mint = minttypes.NewQueryClient(grpcConn)
|
||||
chain.Staking = stakingtypes.NewQueryClient(grpcConn)
|
||||
chain.Tm = tmservice.NewServiceClient(grpcConn)
|
||||
chain.Tx = txtypes.NewServiceClient(grpcConn)
|
||||
chain.Upgrade = upgradetypes.NewQueryClient(grpcConn)
|
||||
@ -104,12 +142,12 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
||||
whale := chain.AddNewSigningAccount(
|
||||
FundedAccountName,
|
||||
hd.CreateHDPath(Bip44CoinType, 0, 0),
|
||||
chain.ChainId,
|
||||
chain.ChainID,
|
||||
fundedAccountMnemonic,
|
||||
)
|
||||
|
||||
// check that funded account is actually funded.
|
||||
fmt.Printf("[%s] account used for funding (%s) address: %s\n", chain.ChainId, FundedAccountName, whale.SdkAddress)
|
||||
fmt.Printf("[%s] account used for funding (%s) address: %s\n", chain.ChainID, FundedAccountName, whale.SdkAddress)
|
||||
whaleFunds := chain.QuerySdkForBalances(whale.SdkAddress)
|
||||
if whaleFunds.IsZero() {
|
||||
chain.t.Fatal("funded account mnemonic is for account with no funds")
|
||||
@ -202,3 +240,64 @@ func (chain *Chain) GetErc20Balance(contract, address common.Address) *big.Int {
|
||||
|
||||
return new(big.Int).SetBytes(resData)
|
||||
}
|
||||
|
||||
func (chain *Chain) GetBeginBlockEventsFromQuery(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
) (sdk.StringEvents, int64, error) {
|
||||
// 1) Block search to find auction_start event and corresponding height
|
||||
// https://rpc.kava.io/block_search?query=%22auction_start.auction_id=16837%22
|
||||
|
||||
blocks, err := chain.QueryBlock(ctx, query)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if len(blocks) == 0 {
|
||||
return nil, 0, fmt.Errorf("no blocks found")
|
||||
}
|
||||
|
||||
// 2) Block results to query events from height
|
||||
// https://rpc.kava.io/block_results?height=3146803
|
||||
events, err := chain.GetBeginBlockEvents(ctx, blocks[0].Block.Height)
|
||||
return events, blocks[0].Block.Height, err
|
||||
}
|
||||
|
||||
func (chain *Chain) QueryBlock(ctx context.Context, query string) ([]*coretypes.ResultBlock, error) {
|
||||
page := 1
|
||||
perPage := 100
|
||||
|
||||
res, err := chain.TmSignClient.BlockSearch(
|
||||
ctx,
|
||||
query,
|
||||
&page,
|
||||
&perPage,
|
||||
"desc",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed BlockSearch: %w", err)
|
||||
}
|
||||
|
||||
return res.Blocks, nil
|
||||
}
|
||||
|
||||
func (chain *Chain) GetBeginBlockEvents(ctx context.Context, height int64) (sdk.StringEvents, error) {
|
||||
res, err := chain.TmSignClient.BlockResults(
|
||||
ctx,
|
||||
&height,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed BlockResults: %w", err)
|
||||
}
|
||||
|
||||
// Do not use sdk.StringifyEvents as it flattens events which makes it
|
||||
// more difficult to parse.
|
||||
strEvents := make(sdk.StringEvents, 0, len(res.BeginBlockEvents))
|
||||
for _, e := range res.BeginBlockEvents {
|
||||
strEvents = append(strEvents, sdk.StringifyEvent(e))
|
||||
}
|
||||
|
||||
return strEvents, nil
|
||||
}
|
||||
|
@ -56,6 +56,8 @@ type LiveNetworkConfig struct {
|
||||
KavaRpcUrl string
|
||||
KavaGrpcUrl string
|
||||
KavaEvmRpcUrl string
|
||||
|
||||
UpgradeHeight int64
|
||||
}
|
||||
|
||||
// ParseSuiteConfig builds a SuiteConfig from environment variables.
|
||||
@ -107,11 +109,23 @@ func ParseKvtoolConfig() KvtoolConfig {
|
||||
|
||||
// ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.
|
||||
func ParseLiveNetworkConfig() LiveNetworkConfig {
|
||||
return LiveNetworkConfig{
|
||||
config := LiveNetworkConfig{
|
||||
KavaRpcUrl: nonemptyStringEnv("E2E_KAVA_RPC_URL"),
|
||||
KavaGrpcUrl: nonemptyStringEnv("E2E_KAVA_GRPC_URL"),
|
||||
KavaEvmRpcUrl: nonemptyStringEnv("E2E_KAVA_EVM_RPC_URL"),
|
||||
}
|
||||
|
||||
upgradeHeight := os.Getenv("E2E_KAVA_UPGRADE_HEIGHT")
|
||||
if upgradeHeight != "" {
|
||||
parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
}
|
||||
|
||||
config.UpgradeHeight = parsedHeight
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
// mustParseBool is a helper method that panics if the env variable `name`
|
||||
|
@ -35,7 +35,7 @@ func (suite *E2eTestSuite) NewEip712TxBuilder(
|
||||
accNumber := accDetails.GetAccountNumber()
|
||||
|
||||
// get chain id
|
||||
pc, err := emtypes.ParseChainID(chain.ChainId)
|
||||
pc, err := emtypes.ParseChainID(chain.ChainID)
|
||||
suite.NoError(err)
|
||||
ethChainId := pc.Uint64()
|
||||
|
||||
@ -47,7 +47,7 @@ func (suite *E2eTestSuite) NewEip712TxBuilder(
|
||||
// build EIP712 tx
|
||||
// -- untyped data
|
||||
untypedData := eip712.ConstructUntypedEIP712Data(
|
||||
chain.ChainId,
|
||||
chain.ChainID,
|
||||
accNumber,
|
||||
nonce,
|
||||
0, // no timeout
|
||||
|
@ -20,7 +20,11 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
// ensure funded account has nonzero erc20 balance
|
||||
balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
if balance.Cmp(big.NewInt(0)) != 1 {
|
||||
panic(fmt.Sprintf("expected funded account (%s) to have erc20 balance", whale.EvmAddress.Hex()))
|
||||
panic(fmt.Sprintf(
|
||||
"expected funded account (%s) to have erc20 balance of token %s",
|
||||
whale.EvmAddress.Hex(),
|
||||
suite.DeployedErc20.Address.Hex(),
|
||||
))
|
||||
}
|
||||
|
||||
// expect the erc20 to be enabled for conversion to sdk.Coin
|
||||
|
@ -3,7 +3,6 @@ package testutil
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -194,12 +193,16 @@ func (suite *E2eTestSuite) SetupLiveNetworkNodeRunner() *runner.LiveNodeRunner {
|
||||
if suite.config.IncludeIbcTests {
|
||||
panic("ibc tests not supported for live network configuration")
|
||||
}
|
||||
|
||||
// Manually set upgrade height for live networks
|
||||
suite.UpgradeHeight = suite.config.LiveNetwork.UpgradeHeight
|
||||
suite.enableRefunds = true
|
||||
|
||||
runnerConfig := runner.LiveNodeRunnerConfig{
|
||||
KavaRpcUrl: suite.config.LiveNetwork.KavaRpcUrl,
|
||||
KavaGrpcUrl: suite.config.LiveNetwork.KavaGrpcUrl,
|
||||
KavaEvmRpcUrl: suite.config.LiveNetwork.KavaEvmRpcUrl,
|
||||
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
||||
}
|
||||
|
||||
return runner.NewLiveNodeRunner(runnerConfig)
|
||||
@ -217,15 +220,23 @@ func (suite *E2eTestSuite) SkipIfIbcDisabled() {
|
||||
// It gracefully skips the current test if upgrades are dissabled.
|
||||
// Note: automated upgrade tests are currently only enabled for Kvtool suite runs.
|
||||
func (suite *E2eTestSuite) SkipIfUpgradeDisabled() {
|
||||
if suite.config.Kvtool != nil && suite.config.Kvtool.IncludeAutomatedUpgrade {
|
||||
if suite.config.Kvtool != nil && !suite.config.Kvtool.IncludeAutomatedUpgrade {
|
||||
fmt.Println("skipping upgrade test, kvtool automated upgrade is disabled")
|
||||
suite.T().SkipNow()
|
||||
}
|
||||
|
||||
// If there isn't a manual upgrade height set in the config, skip the test
|
||||
if suite.config.LiveNetwork != nil && suite.config.LiveNetwork.UpgradeHeight == 0 {
|
||||
fmt.Println("skipping upgrade test, live network upgrade height is not set")
|
||||
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")
|
||||
// SkipIfKvtoolDisabled should be called at the start of tests that require kvtool.
|
||||
func (suite *E2eTestSuite) SkipIfKvtoolDisabled() {
|
||||
if suite.config.Kvtool == nil {
|
||||
suite.T().SkipNow()
|
||||
}
|
||||
}
|
||||
|
||||
// BigIntsEqual is a helper method for comparing the equality of two big ints
|
||||
|
31
tests/util/events.go
Normal file
31
tests/util/events.go
Normal file
@ -0,0 +1,31 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
// FilterEventsByType returns a slice of events that match the given type.
|
||||
func FilterEventsByType(events []abci.Event, eventType string) []abci.Event {
|
||||
filteredEvents := []abci.Event{}
|
||||
|
||||
for _, event := range events {
|
||||
if event.Type == eventType {
|
||||
filteredEvents = append(filteredEvents, event)
|
||||
}
|
||||
}
|
||||
|
||||
return filteredEvents
|
||||
}
|
||||
|
||||
// FilterTxEventsByType returns a slice of events that match the given type
|
||||
// from any and all txs in a slice of ResponseDeliverTx.
|
||||
func FilterTxEventsByType(txs []*abci.ResponseDeliverTx, eventType string) []abci.Event {
|
||||
filteredEvents := []abci.Event{}
|
||||
|
||||
for _, tx := range txs {
|
||||
events := FilterEventsByType(tx.Events, eventType)
|
||||
filteredEvents = append(filteredEvents, events...)
|
||||
}
|
||||
|
||||
return filteredEvents
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||
@ -21,17 +22,17 @@ func NewGrpcConnection(endpoint string) (*grpc.ClientConn, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var secureOpt grpc.DialOption
|
||||
var creds credentials.TransportCredentials
|
||||
switch grpcUrl.Scheme {
|
||||
case "http":
|
||||
secureOpt = grpc.WithInsecure()
|
||||
creds = insecure.NewCredentials()
|
||||
case "https":
|
||||
creds := credentials.NewTLS(&tls.Config{})
|
||||
secureOpt = grpc.WithTransportCredentials(creds)
|
||||
creds = credentials.NewTLS(&tls.Config{})
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown grpc url scheme: %s", grpcUrl.Scheme)
|
||||
}
|
||||
|
||||
secureOpt := grpc.WithTransportCredentials(creds)
|
||||
grpcConn, err := grpc.Dial(grpcUrl.Host, secureOpt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
11
tests/util/kvtool.go
Normal file
11
tests/util/kvtool.go
Normal file
@ -0,0 +1,11 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// 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 KavaHomePath() string {
|
||||
return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava")
|
||||
}
|
@ -28,18 +28,22 @@ func (k Keeper) CheckAndDisableMintAndKavaDistInflation(ctx sdk.Context) {
|
||||
|
||||
logger.Info("disable inflation upgrade finished successfully!")
|
||||
|
||||
ctx.EventManager().EmitEvent(
|
||||
sdk.NewEvent(
|
||||
types.EventTypeInflationStop,
|
||||
),
|
||||
)
|
||||
|
||||
// reset disable inflation time to ensure next call is a no-op
|
||||
params.UpgradeTimeDisableInflation = time.Time{}
|
||||
// set staking rewards to provided intial value
|
||||
params.StakingRewardsPerSecond = params.UpgradeTimeSetStakingRewardsPerSecond
|
||||
k.SetParams(ctx, params)
|
||||
|
||||
ctx.EventManager().EmitEvent(
|
||||
sdk.NewEvent(
|
||||
types.EventTypeInflationStop,
|
||||
sdk.NewAttribute(
|
||||
types.AttributeKeyInflationDisableTime,
|
||||
ctx.BlockTime().Format(time.RFC3339),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
if err := k.StartCommunityFundConsolidation(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -106,7 +106,17 @@ func (suite *disableInflationTestSuite) TestDisableInflation() {
|
||||
|
||||
msgSuffix = "after upgrade"
|
||||
|
||||
suite.Require().NoError(app.EventsContains(suite.Ctx.EventManager().Events(), sdk.NewEvent(types.EventTypeInflationStop)))
|
||||
suite.Require().NoError(
|
||||
app.EventsContains(
|
||||
suite.Ctx.EventManager().Events(),
|
||||
sdk.NewEvent(
|
||||
types.EventTypeInflationStop,
|
||||
sdk.NewAttribute(
|
||||
types.AttributeKeyInflationDisableTime,
|
||||
suite.Ctx.BlockTime().Format(time.RFC3339),
|
||||
),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
suite.Require().Equal(expectedMintState.Params.InflationMin, mintParams.InflationMin, msg+": expected mint inflation min to match state "+msgSuffix)
|
||||
|
@ -6,6 +6,7 @@ const (
|
||||
EventTypeStakingRewardsPaid = "staking_rewards_paid"
|
||||
|
||||
AttributeKeyStakingRewardAmount = "staking_reward_amount"
|
||||
AttributeKeyInflationDisableTime = "inflation_disable_time"
|
||||
|
||||
AttributeValueFundCommunityPool = "fund_community_pool"
|
||||
AttributeValueCategory = ModuleName
|
||||
|
Loading…
Reference in New Issue
Block a user