-
Notifications
You must be signed in to change notification settings - Fork 0
/
live.go
80 lines (65 loc) · 2.36 KB
/
live.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package runner
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
// LiveNodeRunnerConfig implements NodeRunner.
// It connects to a running network via the RPC, GRPC, and EVM urls.
type LiveNodeRunnerConfig struct {
FuryRpcUrl string
FuryGrpcUrl string
FuryEvmRpcUrl string
}
// 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 fury network")
chains := NewChains()
furyChain := ChainDetails{
RpcUrl: r.config.FuryRpcUrl,
GrpcUrl: r.config.FuryGrpcUrl,
EvmRpcUrl: r.config.FuryEvmRpcUrl,
}
if err := waitForChainStart(furyChain); err != nil {
panic(fmt.Sprintf("failed to ping chain: %s", err))
}
// determine chain id
grpc, err := furyChain.GrpcConn()
if err != nil {
panic(fmt.Sprintf("failed to establish grpc conn to %s: %s", r.config.FuryGrpcUrl, err))
}
tm := tmservice.NewServiceClient(grpc)
nodeInfo, err := tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
if err != nil {
panic(fmt.Sprintf("failed to fetch fury node info: %s", err))
}
furyChain.ChainId = nodeInfo.DefaultNodeInfo.Network
// determine staking denom
staking := stakingtypes.NewQueryClient(grpc)
stakingParams, err := staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
if err != nil {
panic(fmt.Sprintf("failed to fetch fury staking params: %s", err))
}
furyChain.StakingDenom = stakingParams.Params.BondDenom
chains.Register("fury", &furyChain)
fmt.Printf("successfully connected to live network %+v\n", furyChain)
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.")
}