2023-06-26 22:03:51 +00:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
|
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
2023-12-13 17:17:37 +00:00
|
|
|
|
2024-04-24 07:10:22 +00:00
|
|
|
"github.com/0glabs/0g-chain/client/grpc"
|
2023-06-26 22:03:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// LiveNodeRunnerConfig implements NodeRunner.
|
|
|
|
// It connects to a running network via the RPC, GRPC, and EVM urls.
|
|
|
|
type LiveNodeRunnerConfig struct {
|
|
|
|
KavaRpcUrl string
|
|
|
|
KavaGrpcUrl string
|
|
|
|
KavaEvmRpcUrl string
|
2023-10-31 23:37:40 +00:00
|
|
|
|
|
|
|
UpgradeHeight int64
|
2023-06-26 22:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
fmt.Println("establishing connection to live kava network")
|
|
|
|
chains := NewChains()
|
|
|
|
|
|
|
|
kavaChain := ChainDetails{
|
|
|
|
RpcUrl: r.config.KavaRpcUrl,
|
|
|
|
GrpcUrl: r.config.KavaGrpcUrl,
|
|
|
|
EvmRpcUrl: r.config.KavaEvmRpcUrl,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := waitForChainStart(kavaChain); err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to ping chain: %s", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine chain id
|
2023-12-13 17:17:37 +00:00
|
|
|
client, err := grpc.NewClient(kavaChain.GrpcUrl)
|
2023-06-26 22:03:51 +00:00
|
|
|
if err != nil {
|
2023-12-13 17:17:37 +00:00
|
|
|
panic(fmt.Sprintf("failed to create kava grpc client: %s", err))
|
2023-06-26 22:03:51 +00:00
|
|
|
}
|
2023-12-13 17:17:37 +00:00
|
|
|
|
|
|
|
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
2023-06-26 22:03:51 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to fetch kava node info: %s", err))
|
|
|
|
}
|
|
|
|
kavaChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
|
|
|
|
|
|
|
// determine staking denom
|
2023-12-13 17:17:37 +00:00
|
|
|
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
|
2023-06-26 22:03:51 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to fetch kava staking params: %s", err))
|
|
|
|
}
|
|
|
|
kavaChain.StakingDenom = stakingParams.Params.BondDenom
|
|
|
|
|
|
|
|
chains.Register("kava", &kavaChain)
|
|
|
|
|
|
|
|
fmt.Printf("successfully connected to live network %+v\n", kavaChain)
|
|
|
|
|
|
|
|
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.")
|
|
|
|
}
|