forked from noble-assets/noble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis_test.go
367 lines (328 loc) · 10.7 KB
/
genesis_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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
package interchaintest_test
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/types"
"github.com/icza/dyno"
"github.com/strangelove-ventures/interchaintest/v3"
"github.com/strangelove-ventures/interchaintest/v3/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v3/ibc"
tokenfactorytypes "github.com/strangelove-ventures/noble/x/tokenfactory/types"
proposaltypes "github.com/strangelove-ventures/paramauthority/x/params/types/proposal"
upgradetypes "github.com/strangelove-ventures/paramauthority/x/upgrade/types"
)
var (
DenomMetadata_rupee = DenomMetadata{
Display: "rupee",
Base: "urupee",
Name: "rupee",
Symbol: "RUPEE",
DenomUnits: []DenomUnit{
{
Denom: "urupee",
Aliases: []string{
"microrupee",
},
Exponent: "0",
},
{
Denom: "mrupee",
Aliases: []string{
"millirupee",
},
Exponent: "3",
},
{
Denom: "rupee",
Exponent: "6",
},
},
}
DenomMetadata_drachma = DenomMetadata{
Display: "drachma",
Base: "udrachma",
Name: "drachma",
Symbol: "DRACHMA",
DenomUnits: []DenomUnit{
{
Denom: "udrachma",
Aliases: []string{
"microdrachma",
},
Exponent: "0",
},
{
Denom: "mdrachma",
Aliases: []string{
"millidrachma",
},
Exponent: "3",
},
{
Denom: "drachma",
Exponent: "6",
},
},
}
)
type DenomMetadata struct {
Display string `json:"display"`
Base string `json:"base"`
Name string `json:"name"`
Symbol string `json:"symbol"`
DenomUnits []DenomUnit `json:"denom_units"`
}
type DenomUnit struct {
Denom string `json:"denom"`
Aliases []string `json:"aliases"`
Exponent string `json:"exponent"`
}
type TokenFactoryAddress struct {
Address string `json:"address"`
}
type ParamAuthAddress struct {
Address string `json:"address"`
}
type TokenFactoryPaused struct {
Paused bool `json:"paused"`
}
type TokenFactoryDenom struct {
Denom string `json:"denom"`
}
func NobleEncoding() *simappparams.EncodingConfig {
cfg := cosmos.DefaultEncoding()
// register custom types
tokenfactorytypes.RegisterInterfaces(cfg.InterfaceRegistry)
proposaltypes.RegisterInterfaces(cfg.InterfaceRegistry)
upgradetypes.RegisterInterfaces(cfg.InterfaceRegistry)
return &cfg
}
type Authority struct {
Authority ibc.Wallet
}
type ExtraWallets struct {
User ibc.Wallet
User2 ibc.Wallet
Alice ibc.Wallet
}
type NobleRoles struct {
Owner ibc.Wallet
Owner2 ibc.Wallet
MasterMinter ibc.Wallet
MinterController ibc.Wallet
MinterController2 ibc.Wallet
Minter ibc.Wallet
Blacklister ibc.Wallet
Pauser ibc.Wallet
}
// Creates tokenfactory wallets. Meant to run pre-genesis.
// It then recovers the key on the specified validator.
func createTokenfactoryRoles(ctx context.Context, nobleRoles *NobleRoles, denomMetadata DenomMetadata, val *cosmos.ChainNode, minSetup bool) error {
chainCfg := val.Chain.Config()
kr := keyring.NewInMemory()
nobleRoles.Owner = interchaintest.BuildWallet(kr, "owner-"+denomMetadata.Base, chainCfg)
err := val.RecoverKey(ctx, nobleRoles.Owner.KeyName, nobleRoles.Owner.Mnemonic)
if err != nil {
return err
}
genesisWallet := ibc.WalletAmount{
Address: nobleRoles.Owner.Address,
Denom: chainCfg.Denom,
Amount: 0,
}
err = val.AddGenesisAccount(ctx, genesisWallet.Address, []types.Coin{types.NewCoin(genesisWallet.Denom, types.NewIntFromUint64(uint64(genesisWallet.Amount)))})
if err != nil {
return err
}
if minSetup {
return nil
}
nobleRoles.Owner2 = interchaintest.BuildWallet(kr, "owner2-"+denomMetadata.Base, chainCfg)
nobleRoles.MasterMinter = interchaintest.BuildWallet(kr, "masterminter-"+denomMetadata.Base, chainCfg)
nobleRoles.MinterController = interchaintest.BuildWallet(kr, "mintercontroller-"+denomMetadata.Base, chainCfg)
nobleRoles.MinterController2 = interchaintest.BuildWallet(kr, "mintercontroller2-"+denomMetadata.Base, chainCfg)
nobleRoles.Minter = interchaintest.BuildWallet(kr, "minter-"+denomMetadata.Base, chainCfg)
nobleRoles.Blacklister = interchaintest.BuildWallet(kr, "blacklister-"+denomMetadata.Base, chainCfg)
nobleRoles.Pauser = interchaintest.BuildWallet(kr, "pauser-"+denomMetadata.Base, chainCfg)
err = val.RecoverKey(ctx, nobleRoles.Owner2.KeyName, nobleRoles.Owner2.Mnemonic)
if err != nil {
return err
}
err = val.RecoverKey(ctx, nobleRoles.MasterMinter.KeyName, nobleRoles.MasterMinter.Mnemonic)
if err != nil {
return err
}
err = val.RecoverKey(ctx, nobleRoles.MinterController.KeyName, nobleRoles.MinterController.Mnemonic)
if err != nil {
return err
}
err = val.RecoverKey(ctx, nobleRoles.MinterController2.KeyName, nobleRoles.MinterController2.Mnemonic)
if err != nil {
return err
}
err = val.RecoverKey(ctx, nobleRoles.Minter.KeyName, nobleRoles.Minter.Mnemonic)
if err != nil {
return err
}
err = val.RecoverKey(ctx, nobleRoles.Blacklister.KeyName, nobleRoles.Blacklister.Mnemonic)
if err != nil {
return err
}
err = val.RecoverKey(ctx, nobleRoles.Pauser.KeyName, nobleRoles.Pauser.Mnemonic)
if err != nil {
return err
}
genesisWallets := []ibc.WalletAmount{
{
Address: nobleRoles.Owner2.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.MasterMinter.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.MinterController.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.MinterController2.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.Minter.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.Blacklister.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: nobleRoles.Pauser.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
}
for _, wallet := range genesisWallets {
err = val.AddGenesisAccount(ctx, wallet.Address, []types.Coin{types.NewCoin(wallet.Denom, types.NewIntFromUint64(uint64(wallet.Amount)))})
if err != nil {
return err
}
}
return nil
}
// Creates extra wallets used for testing. Meant to run pre-genesis.
// It then recovers the key on the specified validator.
func createParamAuthAtGenesis(ctx context.Context, val *cosmos.ChainNode) (Authority, error) {
chainCfg := val.Chain.Config()
kr := keyring.NewInMemory()
authority := &Authority{}
authority.Authority = interchaintest.BuildWallet(kr, "authority", chainCfg)
err := val.RecoverKey(ctx, authority.Authority.KeyName, authority.Authority.Mnemonic)
if err != nil {
return Authority{}, err
}
genesisWallet := ibc.WalletAmount{
Address: authority.Authority.Address,
Denom: chainCfg.Denom,
Amount: 0,
}
err = val.AddGenesisAccount(ctx, genesisWallet.Address, []types.Coin{types.NewCoin(genesisWallet.Denom, types.NewIntFromUint64(uint64(genesisWallet.Amount)))})
if err != nil {
return Authority{}, err
}
return *authority, nil
}
// Creates extra wallets used for testing. Meant to run pre-genesis.
// It then recovers the key on the specified validator.
func createExtraWalletsAtGenesis(ctx context.Context, val *cosmos.ChainNode) (ExtraWallets, error) {
chainCfg := val.Chain.Config()
kr := keyring.NewInMemory()
extraWallets := &ExtraWallets{}
extraWallets.User = interchaintest.BuildWallet(kr, "user", chainCfg)
extraWallets.User2 = interchaintest.BuildWallet(kr, "user2", chainCfg)
extraWallets.Alice = interchaintest.BuildWallet(kr, "alice", chainCfg)
err := val.RecoverKey(ctx, extraWallets.User.KeyName, extraWallets.User.Mnemonic)
if err != nil {
return ExtraWallets{}, err
}
err = val.RecoverKey(ctx, extraWallets.User2.KeyName, extraWallets.User2.Mnemonic)
if err != nil {
return ExtraWallets{}, err
}
err = val.RecoverKey(ctx, extraWallets.Alice.KeyName, extraWallets.Alice.Mnemonic)
if err != nil {
return ExtraWallets{}, err
}
genesisWallets := []ibc.WalletAmount{
{
Address: extraWallets.User.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
{
Address: extraWallets.User2.Address,
Denom: chainCfg.Denom,
Amount: 10_000,
},
{
Address: extraWallets.Alice.Address,
Denom: chainCfg.Denom,
Amount: 0,
},
}
for _, wallet := range genesisWallets {
err = val.AddGenesisAccount(ctx, wallet.Address, []types.Coin{types.NewCoin(wallet.Denom, types.NewIntFromUint64(uint64(wallet.Amount)))})
if err != nil {
return ExtraWallets{}, err
}
}
return *extraWallets, nil
}
// Modifies tokenfactory genesis accounts.
// If minSetup = true, only the owner address, paused state, and denom is setup in genesis.
// These are minimum requirements to start the chain. Otherwise all tokenfactory accounts are created.
func modifyGenesisTokenfactory(g map[string]interface{}, tokenfactoryModName string, denomMetadata DenomMetadata, roles *NobleRoles, minSetup bool) error {
if err := dyno.Set(g, TokenFactoryAddress{roles.Owner.Address}, "app_state", tokenfactoryModName, "owner"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
if err := dyno.Set(g, TokenFactoryPaused{false}, "app_state", tokenfactoryModName, "paused"); err != nil {
return fmt.Errorf("failed to set paused in genesis json: %w", err)
}
if err := dyno.Set(g, TokenFactoryDenom{denomMetadata.Base}, "app_state", tokenfactoryModName, "mintingDenom"); err != nil {
return fmt.Errorf("failed to set minting denom in genesis json: %w", err)
}
if err := dyno.Append(g, denomMetadata, "app_state", "bank", "denom_metadata"); err != nil {
return fmt.Errorf("failed to set denom metadata in genesis json: %w", err)
}
if minSetup {
return nil
}
if err := dyno.Set(g, TokenFactoryAddress{roles.MasterMinter.Address}, "app_state", tokenfactoryModName, "masterMinter"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
if err := dyno.Set(g, TokenFactoryAddress{roles.Blacklister.Address}, "app_state", tokenfactoryModName, "blacklister"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
if err := dyno.Set(g, TokenFactoryAddress{roles.Pauser.Address}, "app_state", tokenfactoryModName, "pauser"); err != nil {
return fmt.Errorf("failed to set owner address in genesis json: %w", err)
}
return nil
}
func modifyGenesisParamAuthority(genbz map[string]interface{}, authorityAddress string) error {
if err := dyno.Set(genbz, authorityAddress, "app_state", "params", "params", "authority"); err != nil {
return fmt.Errorf("failed to set params authority in genesis json: %w", err)
}
if err := dyno.Set(genbz, authorityAddress, "app_state", "upgrade", "params", "authority"); err != nil {
return fmt.Errorf("failed to set upgrade authority address in genesis json: %w", err)
}
return nil
}