/
chain.go
152 lines (122 loc) · 2.96 KB
/
chain.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package e2e
import (
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
umeeapp "github.com/umee-network/umee/v4/app"
"github.com/umee-network/umee/v4/app/params"
)
const (
keyringPassphrase = "testpassphrase"
keyringAppName = "testnet"
)
var (
encodingConfig params.EncodingConfig
cdc codec.Codec
)
func init() {
encodingConfig = umeeapp.MakeEncodingConfig()
encodingConfig.InterfaceRegistry.RegisterImplementations(
(*sdk.Msg)(nil),
&stakingtypes.MsgCreateValidator{},
)
encodingConfig.InterfaceRegistry.RegisterImplementations(
(*cryptotypes.PubKey)(nil),
&secp256k1.PubKey{},
&ed25519.PubKey{},
)
cdc = encodingConfig.Codec
}
type chain struct {
dataDir string
id string
validators []*validator
orchestrators []*orchestrator
gaiaValidators []*gaiaValidator
}
func newChain() (*chain, error) {
tmpDir, err := os.MkdirTemp("", "umee-e2e-testnet-")
if err != nil {
return nil, err
}
return &chain{
id: "chain-" + tmrand.NewRand().Str(6),
dataDir: tmpDir,
}, nil
}
func (c *chain) configDir() string {
return fmt.Sprintf("%s/%s", c.dataDir, c.id)
}
func (c *chain) createAndInitValidators(count int) error {
for i := 0; i < count; i++ {
node := c.createValidator(i)
// generate genesis files
if err := node.init(); err != nil {
return err
}
c.validators = append(c.validators, node)
// create keys
if err := node.createKey("val"); err != nil {
return err
}
if err := node.createNodeKey(); err != nil {
return err
}
if err := node.createConsensusKey(); err != nil {
return err
}
}
return nil
}
func (c *chain) createAndInitGaiaValidator() error {
// create gaia validator
gaiaVal := c.createGaiaValidator(0)
// create keys
mnemonic, info, err := createMemoryKey()
if err != nil {
return err
}
gaiaVal.keyInfo = *info
gaiaVal.mnemonic = mnemonic
c.gaiaValidators = append(c.gaiaValidators, gaiaVal)
return nil
}
func (c *chain) createAndInitOrchestrators(count int) error {
for i := 0; i < count; i++ {
// create orchestrator
orchestrator := c.createOrchestrator(i)
err := orchestrator.createKey("orch")
if err != nil {
return err
}
err = orchestrator.generateEthereumKey()
if err != nil {
return err
}
c.orchestrators = append(c.orchestrators, orchestrator)
}
return nil
}
func (c *chain) createValidator(index int) *validator {
return &validator{
chain: c,
index: index,
moniker: "umee",
}
}
func (c *chain) createOrchestrator(index int) *orchestrator {
return &orchestrator{
index: index,
}
}
func (c *chain) createGaiaValidator(index int) *gaiaValidator {
return &gaiaValidator{
index: index,
}
}