-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexport_test.go
83 lines (71 loc) · 1.7 KB
/
export_test.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
81
82
83
package gosdk
import (
"testing"
"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/x/common/testutil/cli"
"github.com/NibiruChain/nibiru/x/common/testutil/genesis"
"google.golang.org/grpc"
tmconfig "github.com/cometbft/cometbft/config"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
)
type Blockchain struct {
GrpcConn *grpc.ClientConn
Cfg *cli.Config
Network *cli.Network
Val *cli.Validator
}
func CreateBlockchain(t *testing.T) (nibiru Blockchain, err error) {
EnsureNibiruPrefix()
encConfig := app.MakeEncodingConfig()
genState := genesis.NewTestGenesisState(encConfig)
cliCfg := cli.BuildNetworkConfig(genState)
cfg := &cliCfg
cfg.NumValidators = 1
network, err := cli.New(
t,
t.TempDir(),
*cfg,
)
if err != nil {
return nibiru, err
}
err = network.WaitForNextBlock()
if err != nil {
return nibiru, err
}
val := network.Validators[0]
AbsorbServerConfig(cfg, val.AppConfig)
AbsorbTmConfig(cfg, val.Ctx.Config)
grpcConn, err := ConnectGrpcToVal(val)
if err != nil {
return nibiru, err
}
return Blockchain{
GrpcConn: grpcConn,
Cfg: cfg,
Network: network,
Val: val,
}, err
}
func ConnectGrpcToVal(val *cli.Validator) (*grpc.ClientConn, error) {
grpcUrl := val.AppConfig.GRPC.Address
return GetGRPCConnection(
grpcUrl, true, 5,
)
}
func AbsorbServerConfig(
cfg *cli.Config, srvCfg *serverconfig.Config,
) *cli.Config {
cfg.GRPCAddress = srvCfg.GRPC.Address
cfg.APIAddress = srvCfg.API.Address
return cfg
}
func AbsorbTmConfig(
cfg *cli.Config, tmCfg *tmconfig.Config,
) *cli.Config {
cfg.RPCAddress = tmCfg.RPC.ListenAddress
return cfg
}
func (chain *Blockchain) TmRpcEndpoint() string {
return chain.Val.RPCAddress
}