-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathproposal_handler_test.go
365 lines (340 loc) · 12.9 KB
/
proposal_handler_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 keeper_test
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
provenance "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/internal/pioconfig"
markerkeeper "github.com/provenance-io/provenance/x/marker/keeper"
markertypes "github.com/provenance-io/provenance/x/marker/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)
type IntegrationTestSuite struct {
suite.Suite
app *provenance.App
ctx sdk.Context
k markerkeeper.Keeper
accountAddr sdk.AccAddress
}
func (s *IntegrationTestSuite) SetupSuite() {
s.app = provenance.Setup(s.T())
s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{})
s.k = markerkeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(markertypes.ModuleName), s.app.GetSubspace(markertypes.ModuleName), s.app.AccountKeeper, s.app.BankKeeper, s.app.AuthzKeeper, s.app.FeeGrantKeeper, s.app.GetKey(banktypes.StoreKey))
s.accountAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
}
func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
}
func (s *IntegrationTestSuite) TestMarkerProposals() {
testCases := []struct {
name string
prop govtypesv1beta1.Content
err error
}{
// ADD MARKER PROPOSALS
{
"add marker - valid",
markertypes.NewAddMarkerProposal("title", "description", "test1", sdk.NewInt(100), sdk.AccAddress{}, markertypes.StatusActive, markertypes.MarkerType_Coin, []markertypes.AccessGrant{}, true, true),
nil,
},
{
"add marker - valid",
markertypes.NewAddMarkerProposal("title", "description", "testrestricted", sdk.NewInt(100), sdk.AccAddress{}, markertypes.StatusActive, markertypes.MarkerType_RestrictedCoin, []markertypes.AccessGrant{}, true, true),
nil,
},
{
"add marker - valid no governance",
markertypes.NewAddMarkerProposal("title", "description", "testnogov", sdk.NewInt(100), sdk.AccAddress{}, markertypes.StatusActive, markertypes.MarkerType_Coin, []markertypes.AccessGrant{}, true, false),
nil,
},
{
"add marker - valid finalized",
markertypes.NewAddMarkerProposal("title", "description", "pending", sdk.NewInt(100), s.accountAddr, markertypes.StatusFinalized, markertypes.MarkerType_Coin, []markertypes.AccessGrant{}, true, true),
nil,
},
{
"add marker - already exists",
markertypes.NewAddMarkerProposal("title", "description", "test1", sdk.NewInt(0), sdk.AccAddress{}, markertypes.StatusActive, markertypes.MarkerType_Coin, []markertypes.AccessGrant{}, true, true),
fmt.Errorf("test1 marker already exists"),
},
{
"add marker - invalid status",
markertypes.NewAddMarkerProposal("title", "description", "test2", sdk.NewInt(100), sdk.AccAddress{}, markertypes.StatusUndefined, markertypes.MarkerType_Coin, []markertypes.AccessGrant{}, true, true),
fmt.Errorf("error invalid marker status undefined"),
},
// INCREASE SUPPLY PROPOSALS
{
"supply increase - valid",
markertypes.NewSupplyIncreaseProposal("title", "description", sdk.NewCoin("test1", sdk.NewInt(100)), s.accountAddr.String()),
nil,
},
{
"supply increase - on finalized marker",
markertypes.NewSupplyIncreaseProposal("title", "description", sdk.NewCoin("pending", sdk.NewInt(100)), s.accountAddr.String()),
nil,
},
{
"supply increase - marker doesn't exist",
markertypes.NewSupplyIncreaseProposal("title", "description", sdk.NewCoin("test", sdk.NewInt(100)), s.accountAddr.String()),
fmt.Errorf("test marker does not exist"),
},
{
"supply increase - no governance allowed",
markertypes.NewSupplyIncreaseProposal("title", "description", sdk.NewCoin("testnogov", sdk.NewInt(100)), s.accountAddr.String()),
fmt.Errorf("testnogov marker does not allow governance control"),
},
{
"supply increase - valid no target",
markertypes.NewSupplyIncreaseProposal("title", "description", sdk.NewCoin("test1", sdk.NewInt(100)), ""),
nil,
},
// DECREASE SUPPLY PROPOSALS
{
"supply decrease - valid",
markertypes.NewSupplyDecreaseProposal("title", "description", sdk.NewCoin("test1", sdk.NewInt(100))),
nil,
},
{
"supply decrease - no governance allowed",
markertypes.NewSupplyDecreaseProposal("title", "description", sdk.NewCoin("testnogov", sdk.NewInt(100))),
fmt.Errorf("testnogov marker does not allow governance control"),
},
{
"supply decrease - marker doesnot exist",
markertypes.NewSupplyDecreaseProposal("title", "description", sdk.NewCoin("test", sdk.NewInt(100))),
fmt.Errorf("test marker does not exist"),
},
// WITHDRAW PROPOSALS
{
"withdraw - valid",
markertypes.NewWithdrawEscrowProposal("title", "description", "test1", sdk.NewCoins(sdk.NewCoin("test1", sdk.NewInt(10))), s.accountAddr.String()),
nil,
},
{
"withdraw - no governance",
markertypes.NewWithdrawEscrowProposal("title", "description", "testnogov", sdk.NewCoins(sdk.NewCoin("testnogov", sdk.NewInt(1))), ""),
fmt.Errorf("testnogov marker does not allow governance control"),
},
{
"withdraw - marker doesnot exist",
markertypes.NewWithdrawEscrowProposal("title", "description", "test", sdk.NewCoins(sdk.NewCoin("test", sdk.NewInt(100))), ""),
fmt.Errorf("test marker does not exist"),
},
{
"withdraw - invalid recpient",
markertypes.NewWithdrawEscrowProposal("title", "description", "test1", sdk.NewCoins(sdk.NewCoin("test1", sdk.NewInt(100))), "bad1address"),
fmt.Errorf("decoding bech32 failed: invalid checksum (expected dpg8tu got ddress)"),
},
// STATUS CHANGE PROPOSALS
{
"status change - no governance",
markertypes.NewChangeStatusProposal("title", "description", "testnogov", markertypes.StatusActive),
fmt.Errorf("testnogov marker does not allow governance control"),
},
{
"status change - marker doesnot exist",
markertypes.NewChangeStatusProposal("title", "description", "test", markertypes.StatusActive),
fmt.Errorf("test marker does not exist"),
},
{
"status change - invalid status",
markertypes.NewChangeStatusProposal("title", "description", "pending", markertypes.StatusUndefined),
fmt.Errorf("error invalid marker status undefined"),
},
{
"status change - invalid status order",
markertypes.NewChangeStatusProposal("title", "description", "test1", markertypes.StatusProposed),
fmt.Errorf("invalid status transition proposed precedes existing status of active"),
},
{
"status change - valid",
markertypes.NewChangeStatusProposal("title", "description", "pending", markertypes.StatusActive),
nil,
},
{
"status change - invalid destroy",
markertypes.NewChangeStatusProposal("title", "description", "pending", markertypes.StatusDestroyed),
fmt.Errorf("only cancelled markers can be deleted"),
},
{
"status change - valid cancel",
markertypes.NewChangeStatusProposal("title", "description", "pending", markertypes.StatusCancelled),
nil,
},
{
"status change - valid destroy",
markertypes.NewChangeStatusProposal("title", "description", "pending", markertypes.StatusDestroyed),
nil,
},
// ADD ACCESS
{
"add access - no governance",
markertypes.NewSetAdministratorProposal("title", "description", "testnogov", []markertypes.AccessGrant{{Address: s.accountAddr.String(), Permissions: markertypes.AccessListByNames("mint, burn")}}),
fmt.Errorf("testnogov marker does not allow governance control"),
},
{
"add access - marker doesnot exist",
markertypes.NewSetAdministratorProposal("title", "description", "test", []markertypes.AccessGrant{{Address: s.accountAddr.String(), Permissions: markertypes.AccessListByNames("mint, burn")}}),
fmt.Errorf("test marker does not exist"),
},
{
"add access - transfer only on restricted",
markertypes.NewSetAdministratorProposal("title", "description", "test1", []markertypes.AccessGrant{{Address: s.accountAddr.String(), Permissions: markertypes.AccessListByNames("mint, burn, transfer")}}),
fmt.Errorf("invalid access privileges granted: ACCESS_TRANSFER is not supported for marker type MARKER_TYPE_COIN"),
},
{
"add access - valid",
markertypes.NewSetAdministratorProposal("title", "description", "test1", []markertypes.AccessGrant{{Address: s.accountAddr.String(), Permissions: markertypes.AccessListByNames("mint, burn")}}),
nil,
},
{
"add access - valid restricted",
markertypes.NewSetAdministratorProposal("title", "description", "testrestricted", []markertypes.AccessGrant{{Address: s.accountAddr.String(), Permissions: markertypes.AccessListByNames("mint, burn, transfer")}}),
nil,
},
// REMOVE ACCESS
{
"remove access - no governance",
markertypes.NewRemoveAdministratorProposal("title", "description", "testnogov", []string{s.accountAddr.String()}),
fmt.Errorf("testnogov marker does not allow governance control"),
},
{
"remove access - marker doesnot exist",
markertypes.NewRemoveAdministratorProposal("title", "description", "test", []string{s.accountAddr.String()}),
fmt.Errorf("test marker does not exist"),
},
{
"remove access - marker doesnot exist",
markertypes.NewRemoveAdministratorProposal("title", "description", "test1", []string{"bad1address"}),
fmt.Errorf("decoding bech32 failed: invalid checksum (expected dpg8tu got ddress)"),
},
{
"remove access - valid",
markertypes.NewRemoveAdministratorProposal("title", "description", "test1", []string{s.accountAddr.String()}),
nil,
},
// SET DENOM METADATA PROPOSALS
{
"set denom metadata - bad denom",
markertypes.NewSetDenomMetadataProposal("title", "description",
banktypes.Metadata{
Description: "some denom description",
Base: "bad$char",
Display: "badchar",
Name: "Bad Char",
Symbol: "BC",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "bad$char",
Exponent: 0,
Aliases: nil,
},
},
},
),
errors.New("invalid denom: bad$char"),
},
{
"set denom metadata - marker does not exist",
markertypes.NewSetDenomMetadataProposal("title", "description",
banktypes.Metadata{
Description: "another denom description",
Base: "doesnotexist",
Display: "doesnotexist",
Name: "Does Not Exist",
Symbol: "DNE",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "doesnotexist",
Exponent: 0,
Aliases: nil,
},
},
},
),
errors.New("doesnotexist marker does not exist"),
},
{
"set denom metadata - no governance",
markertypes.NewSetDenomMetadataProposal("title", "description",
banktypes.Metadata{
Description: "the best denom description",
Base: "testnogov",
Display: "testnogov",
Name: "Test No Governance",
Symbol: "TNG",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "testnogov",
Exponent: 0,
Aliases: []string{"thenextgeneration"},
},
},
},
),
errors.New("testnogov marker does not allow governance control"),
},
{
"set denom metadata - valid",
markertypes.NewSetDenomMetadataProposal("title", "description",
banktypes.Metadata{
Description: "the best denom description",
Base: "test1",
Display: "test1",
Name: "Test One",
Symbol: "TONE",
DenomUnits: []*banktypes.DenomUnit{
{
Denom: "test1",
Exponent: 0,
Aliases: []string{"tone"},
},
},
},
),
nil,
},
}
for _, tc := range testCases {
tc := tc
s.T().Run(tc.name, func(t *testing.T) {
var err error
switch c := tc.prop.(type) {
case *markertypes.AddMarkerProposal:
err = markerkeeper.HandleAddMarkerProposal(s.ctx, s.k, c)
case *markertypes.SupplyIncreaseProposal:
err = markerkeeper.HandleSupplyIncreaseProposal(s.ctx, s.k, c)
case *markertypes.SupplyDecreaseProposal:
err = markerkeeper.HandleSupplyDecreaseProposal(s.ctx, s.k, c)
case *markertypes.SetAdministratorProposal:
err = markerkeeper.HandleSetAdministratorProposal(s.ctx, s.k, c)
case *markertypes.RemoveAdministratorProposal:
err = markerkeeper.HandleRemoveAdministratorProposal(s.ctx, s.k, c)
case *markertypes.ChangeStatusProposal:
err = markerkeeper.HandleChangeStatusProposal(s.ctx, s.k, c)
case *markertypes.WithdrawEscrowProposal:
err = markerkeeper.HandleWithdrawEscrowProposal(s.ctx, s.k, c)
case *markertypes.SetDenomMetadataProposal:
err = markerkeeper.HandleSetDenomMetadataProposal(s.ctx, s.k, c)
default:
panic("invalid proposal type")
}
if tc.err != nil {
require.Error(t, err)
require.Equal(t, tc.err.Error(), err.Error())
} else {
require.NoError(t, err)
}
})
}
}
func TestIntegrationTestSuite(t *testing.T) {
pioconfig.SetProvenanceConfig("", 0)
suite.Run(t, new(IntegrationTestSuite))
}