forked from noble-assets/noble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoble_test.go
365 lines (294 loc) · 13.8 KB
/
noble_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
package interchaintest_test
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/strangelove-ventures/interchaintest/v3"
"github.com/strangelove-ventures/interchaintest/v3/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v3/ibc"
"github.com/strangelove-ventures/interchaintest/v3/testreporter"
integration "github.com/strangelove-ventures/noble/interchaintest"
"github.com/strangelove-ventures/noble/x/tokenfactory/types"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)
func TestNobleChain(t *testing.T) {
if testing.Short() {
t.Skip()
}
t.Parallel()
ctx := context.Background()
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(t)
repo, version := integration.GetDockerImageInfo()
var (
noble *cosmos.CosmosChain
roles NobleRoles
roles2 NobleRoles
extraWallets ExtraWallets
paramauthorityWallet Authority
)
chainCfg := ibc.ChainConfig{
Type: "cosmos",
Name: "noble",
ChainID: "noble-1",
Bin: "nobled",
Denom: "token",
Bech32Prefix: "noble",
CoinType: "118",
GasPrices: "0.0token",
GasAdjustment: 1.1,
TrustingPeriod: "504h",
NoHostMount: false,
Images: []ibc.DockerImage{
{
Repository: repo,
Version: version,
UidGid: "1025:1025",
},
},
EncodingConfig: NobleEncoding(),
PreGenesis: func(cc ibc.ChainConfig) (err error) {
val := noble.Validators[0]
err = createTokenfactoryRoles(ctx, &roles, DenomMetadata_rupee, val, false)
if err != nil {
return err
}
err = createTokenfactoryRoles(ctx, &roles2, DenomMetadata_drachma, val, false)
if err != nil {
return err
}
extraWallets, err = createExtraWalletsAtGenesis(ctx, val)
if err != nil {
return err
}
paramauthorityWallet, err = createParamAuthAtGenesis(ctx, val)
return err
},
ModifyGenesis: func(cc ibc.ChainConfig, b []byte) ([]byte, error) {
g := make(map[string]interface{})
if err := json.Unmarshal(b, &g); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err)
}
err := modifyGenesisTokenfactory(g, "tokenfactory", DenomMetadata_rupee, &roles, true)
if err != nil {
return nil, err
}
err = modifyGenesisTokenfactory(g, "fiat-tokenfactory", DenomMetadata_drachma, &roles2, true)
if err != nil {
return nil, err
}
err = modifyGenesisParamAuthority(g, paramauthorityWallet.Authority.Address)
if err != nil {
return nil, err
}
out, err := json.Marshal(&g)
if err != nil {
return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err)
}
return out, nil
},
}
nv := 2
nf := 1
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
ChainConfig: chainCfg,
NumValidators: &nv,
NumFullNodes: &nf,
},
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
noble = chains[0].(*cosmos.CosmosChain)
ic := interchaintest.NewInterchain().
AddChain(noble)
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: false,
}))
t.Cleanup(func() {
_ = ic.Close()
})
t.Run("tokenfactory", func(t *testing.T) {
t.Parallel()
nobleTokenfactory_e2e(t, ctx, "tokenfactory", DenomMetadata_rupee.Base, noble, roles, extraWallets)
})
t.Run("fiat-tokenfactory", func(t *testing.T) {
t.Parallel()
nobleTokenfactory_e2e(t, ctx, "fiat-tokenfactory", DenomMetadata_drachma.Base, noble, roles2, extraWallets)
})
}
func nobleTokenfactory_e2e(t *testing.T, ctx context.Context, tokenfactoryModName, mintingDenom string, noble *cosmos.CosmosChain, roles NobleRoles, extraWallets ExtraWallets) error {
nobleValidator := noble.Validators[0]
_, err := nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
tokenfactoryModName, "update-master-minter", roles.MasterMinter.Address, "-b", "block",
)
require.Error(t, err, "succeeded to execute update master minter tx by invalid owner")
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
tokenfactoryModName, "update-owner", roles.Owner2.Address, "-b", "block",
)
require.Error(t, err, "succeeded to execute update owner tx by invalid owner")
_, err = nobleValidator.ExecTx(ctx, roles.Owner.KeyName,
tokenfactoryModName, "update-owner", roles.Owner2.Address, "-b", "block",
)
require.NoError(t, err, "failed to execute update owner tx")
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
tokenfactoryModName, "update-master-minter", roles.MasterMinter.Address, "-b", "block",
)
require.Error(t, err, "succeeded to execute update master minter tx by pending owner")
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
tokenfactoryModName, "accept-owner", "-b", "block",
)
require.NoError(t, err, "failed to execute tx to accept ownership")
_, err = nobleValidator.ExecTx(ctx, roles.Owner.KeyName,
tokenfactoryModName, "update-master-minter", roles.MasterMinter.Address, "-b", "block",
)
require.Error(t, err, "succeeded to execute update master minter tx by prior owner")
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
tokenfactoryModName, "update-master-minter", roles.MasterMinter.Address, "-b", "block",
)
require.NoError(t, err, "failed to execute update master minter tx")
_, err = nobleValidator.ExecTx(ctx, roles.MasterMinter.KeyName,
tokenfactoryModName, "configure-minter-controller", roles.MinterController.Address, roles.Minter.Address, "-b", "block",
)
require.NoError(t, err, "failed to execute configure minter controller tx")
_, err = nobleValidator.ExecTx(ctx, roles.MinterController.KeyName,
tokenfactoryModName, "configure-minter", roles.Minter.Address, "1000"+mintingDenom, "-b", "block",
)
require.NoError(t, err, "failed to execute configure minter tx")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "mint", extraWallets.User.Address, "100"+mintingDenom, "-b", "block",
)
require.NoError(t, err, "failed to execute mint to user tx")
userBalance, err := noble.GetBalance(ctx, extraWallets.User.Address, mintingDenom)
require.NoError(t, err, "failed to get user balance")
require.Equalf(t, int64(100), userBalance, "failed to mint %s to user", mintingDenom)
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
tokenfactoryModName, "update-blacklister", roles.Blacklister.Address, "-b", "block",
)
require.NoError(t, err, "failed to set blacklister")
_, err = nobleValidator.ExecTx(ctx, roles.Blacklister.KeyName,
tokenfactoryModName, "blacklist", extraWallets.User.Address, "-b", "block",
)
require.NoError(t, err, "failed to blacklist user address")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "mint", extraWallets.User.Address, "100"+mintingDenom, "-b", "block",
)
require.Error(t, err, "successfully executed mint to blacklisted user tx")
userBalance, err = noble.GetBalance(ctx, extraWallets.User.Address, mintingDenom)
require.NoError(t, err, "failed to get user balance")
require.Equal(t, int64(100), userBalance, "user balance should not have incremented while blacklisted")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "mint", extraWallets.User2.Address, "100"+mintingDenom, "-b", "block",
)
require.NoError(t, err, "failed to execute mint to user2 tx")
err = nobleValidator.SendFunds(ctx, extraWallets.User2.KeyName, ibc.WalletAmount{
Address: extraWallets.User.Address,
Denom: mintingDenom,
Amount: 50,
})
require.Error(t, err, "The tx to a blacklisted user should not have been successful")
userBalance, err = noble.GetBalance(ctx, extraWallets.User.Address, mintingDenom)
require.NoError(t, err, "failed to get user balance")
require.Equal(t, int64(100), userBalance, "user balance should not have incremented while blacklisted")
err = nobleValidator.SendFunds(ctx, extraWallets.User2.KeyName, ibc.WalletAmount{
Address: extraWallets.User.Address,
Denom: "token",
Amount: 100,
})
require.NoError(t, err, "The tx should have been successfull as that is no the minting denom")
_, err = nobleValidator.ExecTx(ctx, roles.Blacklister.KeyName,
tokenfactoryModName, "unblacklist", extraWallets.User.Address, "-b", "block",
)
require.NoError(t, err, "failed to unblacklist user address")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "mint", extraWallets.User.Address, "100"+mintingDenom, "-b", "block",
)
require.NoError(t, err, "failed to execute mint to user tx")
userBalance, err = noble.GetBalance(ctx, extraWallets.User.Address, mintingDenom)
require.NoError(t, err, "failed to get user balance")
require.Equal(t, int64(200), userBalance, "user balance should have increased now that they are no longer blacklisted")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "mint", roles.Minter.Address, "100"+mintingDenom, "-b", "block",
)
require.NoError(t, err, "failed to execute mint to user tx")
minterBalance, err := noble.GetBalance(ctx, roles.Minter.Address, mintingDenom)
require.NoError(t, err, "failed to get minter balance")
require.Equal(t, int64(100), minterBalance, "minter balance should have increased")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "burn", "10"+mintingDenom, "-b", "block",
)
require.NoError(t, err, "failed to execute burn tx")
minterBalance, err = noble.GetBalance(ctx, roles.Minter.Address, mintingDenom)
require.NoError(t, err, "failed to get minter balance")
require.Equal(t, int64(90), minterBalance, "minter balance should have decreased because tokens were burned")
_, err = nobleValidator.ExecTx(ctx, roles.Owner2.KeyName,
tokenfactoryModName, "update-pauser", roles.Pauser.Address, "-b", "block",
)
require.NoError(t, err, "failed to update pauser")
// -- chain paused --
_, err = nobleValidator.ExecTx(ctx, roles.Pauser.KeyName,
tokenfactoryModName, "pause", "-b", "block",
)
require.NoError(t, err, "failed to pause mints")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "mint", extraWallets.User.Address, "100"+mintingDenom, "-b", "block",
)
require.Error(t, err, "successfully executed mint to user tx while chain is paused")
userBalance, err = noble.GetBalance(ctx, extraWallets.User.Address, mintingDenom)
require.NoError(t, err, "failed to get user balance")
require.Equal(t, int64(200), userBalance, "user balance should not have increased while chain is paused")
_, err = nobleValidator.ExecTx(ctx, extraWallets.User.KeyName,
"bank", "send", extraWallets.User.Address, extraWallets.Alice.Address, "100"+mintingDenom, "-b", "block",
)
require.Error(t, err, "transaction was successful while chain is paused")
userBalance, err = noble.GetBalance(ctx, extraWallets.User.Address, mintingDenom)
require.NoError(t, err, "failed to get user balance")
require.Equal(t, int64(200), userBalance, "user balance should not have changed while chain is paused")
aliceBalance, err := noble.GetBalance(ctx, extraWallets.Alice.Address, mintingDenom)
require.NoError(t, err, "failed to get alice balance")
require.Equal(t, int64(0), aliceBalance, "alice balance should not have increased while chain is paused")
_, err = nobleValidator.ExecTx(ctx, roles.Minter.KeyName,
tokenfactoryModName, "burn", "10"+mintingDenom, "-b", "block",
)
require.Error(t, err, "successfully executed burn tx while chain is paused")
require.Equal(t, int64(90), minterBalance, "this burn should not have been successful because the chain is paused")
_, err = nobleValidator.ExecTx(ctx, roles.MasterMinter.KeyName,
tokenfactoryModName, "configure-minter-controller", roles.MinterController2.Address, extraWallets.User.Address, "-b", "block")
require.NoError(t, err, "failed to execute configure minter controller tx")
_, err = nobleValidator.ExecTx(ctx, roles.MinterController2.KeyName,
tokenfactoryModName, "configure-minter", extraWallets.User.Address, "1000"+mintingDenom, "-b", "block")
require.NoError(t, err, "failed to execute configure minter tx")
res, _, err := nobleValidator.ExecQuery(ctx, tokenfactoryModName, "show-minter-controller", roles.MinterController2.Address, "-o", "json")
require.NoError(t, err, "failed to query minter controller")
var minterControllerType types.QueryGetMinterControllerResponse
json.Unmarshal(res, &minterControllerType)
// minter controller and minter should have been updated even while paused
require.Equal(t, roles.MinterController2.Address, minterControllerType.MinterController.Controller)
require.Equal(t, extraWallets.User.Address, minterControllerType.MinterController.Minter)
_, err = nobleValidator.ExecTx(ctx, roles.MinterController2.KeyName,
tokenfactoryModName, "remove-minter", extraWallets.User.Address, "-b", "block",
)
require.NoError(t, err, "minters should be able to be removed while in paused state")
_, err = nobleValidator.ExecTx(ctx, roles.Pauser.KeyName,
tokenfactoryModName, "unpause", "-b", "block",
)
require.NoError(t, err, "failed to unpause mints")
// -- chain unpaused --
_, err = nobleValidator.ExecTx(ctx, extraWallets.User.KeyName,
"bank", "send", extraWallets.User.Address, extraWallets.Alice.Address, "100"+mintingDenom, "-b", "block",
)
require.NoErrorf(t, err, "failed to send tx bank from user (%s) to alice (%s)", extraWallets.User.Address, extraWallets.Alice.Address)
userBalance, err = noble.GetBalance(ctx, extraWallets.User.Address, mintingDenom)
require.NoError(t, err, "failed to get user balance")
require.Equal(t, int64(100), userBalance, "user balance should not have changed while chain is paused")
aliceBalance, err = noble.GetBalance(ctx, extraWallets.Alice.Address, mintingDenom)
require.NoError(t, err, "failed to get alice balance")
require.Equal(t, int64(100), aliceBalance, "alice balance should not have increased while chain is paused")
return nil
}