0g-chain/tests/e2e/runner/live.go

84 lines
2.4 KiB
Go
Raw Permalink Normal View History

package runner
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
2024-08-04 05:56:43 +00:00
"github.com/0glabs/0g-chain/client/grpc"
)
// LiveNodeRunnerConfig implements NodeRunner.
// It connects to a running network via the RPC, GRPC, and EVM urls.
type LiveNodeRunnerConfig struct {
2024-05-01 05:53:58 +00:00
ZgChainRpcUrl string
ZgChainGrpcUrl string
ZgChainEvmRpcUrl string
`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
UpgradeHeight int64
}
// LiveNodeRunner implements NodeRunner for an already-running chain.
// If a LiveNodeRunner is used, end-to-end tests are run against a live chain.
type LiveNodeRunner struct {
config LiveNodeRunnerConfig
}
var _ NodeRunner = LiveNodeRunner{}
// NewLiveNodeRunner creates a new LiveNodeRunner.
func NewLiveNodeRunner(config LiveNodeRunnerConfig) *LiveNodeRunner {
return &LiveNodeRunner{config}
}
// StartChains implements NodeRunner.
// It initializes connections to the chain based on parameters.
// It attempts to ping the necessary endpoints and panics if they cannot be reached.
func (r LiveNodeRunner) StartChains() Chains {
2024-05-01 05:53:58 +00:00
fmt.Println("establishing connection to live 0g-chain network")
chains := NewChains()
2024-05-01 05:53:58 +00:00
zgChain := ChainDetails{
RpcUrl: r.config.ZgChainRpcUrl,
GrpcUrl: r.config.ZgChainGrpcUrl,
EvmRpcUrl: r.config.ZgChainEvmRpcUrl,
}
2024-05-01 05:53:58 +00:00
if err := waitForChainStart(zgChain); err != nil {
panic(fmt.Sprintf("failed to ping chain: %s", err))
}
// determine chain id
2024-08-04 05:56:43 +00:00
client, err := grpc.NewClient(zgChain.GrpcUrl)
if err != nil {
2024-08-04 05:56:43 +00:00
panic(fmt.Sprintf("failed to create 0g-chain grpc client: %s", err))
}
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
if err != nil {
2024-08-04 05:56:43 +00:00
panic(fmt.Sprintf("failed to fetch 0g-chain node info: %s", err))
}
2024-05-01 05:53:58 +00:00
zgChain.ChainId = nodeInfo.DefaultNodeInfo.Network
// determine staking denom
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
if err != nil {
2024-08-04 05:56:43 +00:00
panic(fmt.Sprintf("failed to fetch 0g-chain staking params: %s", err))
}
2024-05-01 05:53:58 +00:00
zgChain.StakingDenom = stakingParams.Params.BondDenom
2024-05-01 05:53:58 +00:00
chains.Register("0gchain", &zgChain)
2024-05-01 05:53:58 +00:00
fmt.Printf("successfully connected to live network %+v\n", zgChain)
return chains
}
// Shutdown implements NodeRunner.
// As the chains are externally operated, this is a no-op.
func (LiveNodeRunner) Shutdown() {
fmt.Println("shutting down e2e test connections.")
}