@agoric/cosmos 0.35.0-u15.0 → 0.35.0-u16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.md +123 -143
  2. package/MAINTAINERS.md +3 -0
  3. package/Makefile +36 -26
  4. package/ante/ante.go +6 -5
  5. package/ante/inbound_test.go +3 -2
  6. package/ante/vm_admission.go +2 -1
  7. package/app/app.go +206 -147
  8. package/app/upgrade.go +77 -0
  9. package/cmd/agd/agvm.go +42 -0
  10. package/cmd/agd/main.go +130 -11
  11. package/cmd/libdaemon/main.go +64 -53
  12. package/cmd/libdaemon/main_test.go +2 -1
  13. package/daemon/cmd/root.go +164 -74
  14. package/daemon/cmd/root_test.go +189 -1
  15. package/daemon/main.go +4 -2
  16. package/e2e_test/Makefile +29 -0
  17. package/e2e_test/README.md +100 -0
  18. package/e2e_test/go.mod +217 -0
  19. package/e2e_test/go.sum +1323 -0
  20. package/e2e_test/ibc_conformance_test.go +56 -0
  21. package/e2e_test/pfm_test.go +613 -0
  22. package/e2e_test/util.go +271 -0
  23. package/git-revision.txt +1 -1
  24. package/go.mod +12 -7
  25. package/go.sum +13 -9
  26. package/package.json +8 -4
  27. package/proto/agoric/swingset/genesis.proto +4 -0
  28. package/proto/agoric/swingset/swingset.proto +1 -1
  29. package/proto/agoric/vlocalchain/.clang-format +7 -0
  30. package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
  31. package/proto/agoric/vtransfer/genesis.proto +18 -0
  32. package/scripts/protocgen.sh +7 -8
  33. package/types/kv_entry_helpers.go +42 -0
  34. package/upgradegaia.sh +8 -8
  35. package/vm/action.go +5 -4
  36. package/vm/action_test.go +31 -11
  37. package/vm/client.go +113 -0
  38. package/vm/client_test.go +182 -0
  39. package/vm/controller.go +17 -40
  40. package/vm/core_proposals.go +22 -2
  41. package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
  42. package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
  43. package/vm/proto_json.go +38 -0
  44. package/vm/proto_json_test.go +103 -0
  45. package/vm/server.go +124 -0
  46. package/x/swingset/abci.go +10 -10
  47. package/x/swingset/alias.go +2 -0
  48. package/x/swingset/client/cli/tx.go +4 -0
  49. package/x/swingset/genesis.go +84 -24
  50. package/x/swingset/handler.go +2 -1
  51. package/x/swingset/keeper/extension_snapshotter.go +2 -2
  52. package/x/swingset/keeper/keeper.go +13 -25
  53. package/x/swingset/keeper/msg_server.go +18 -18
  54. package/x/swingset/keeper/proposal.go +3 -3
  55. package/x/swingset/keeper/querier.go +12 -11
  56. package/x/swingset/keeper/swing_store_exports_handler.go +16 -5
  57. package/x/swingset/keeper/test_utils.go +16 -0
  58. package/x/swingset/module.go +7 -7
  59. package/x/swingset/proposal_handler.go +2 -1
  60. package/x/swingset/testing/queue.go +17 -0
  61. package/x/swingset/types/default-params.go +1 -1
  62. package/x/swingset/types/expected_keepers.go +3 -2
  63. package/x/swingset/types/genesis.pb.go +78 -25
  64. package/x/swingset/types/msgs.go +44 -24
  65. package/x/swingset/types/params.go +2 -1
  66. package/x/swingset/types/proposal.go +5 -4
  67. package/x/swingset/types/swingset.pb.go +1 -1
  68. package/x/vbank/genesis.go +0 -2
  69. package/x/vbank/handler.go +2 -1
  70. package/x/vbank/keeper/querier.go +4 -3
  71. package/x/vbank/module.go +0 -5
  72. package/x/vbank/types/msgs.go +0 -12
  73. package/x/vbank/vbank.go +9 -9
  74. package/x/vbank/vbank_test.go +2 -2
  75. package/x/vibc/alias.go +3 -0
  76. package/x/vibc/handler.go +16 -9
  77. package/x/vibc/keeper/keeper.go +102 -65
  78. package/x/vibc/keeper/triggers.go +101 -0
  79. package/x/vibc/module.go +5 -8
  80. package/x/vibc/types/expected_keepers.go +13 -0
  81. package/x/vibc/types/ibc_module.go +336 -0
  82. package/x/vibc/types/receiver.go +170 -0
  83. package/x/vlocalchain/alias.go +19 -0
  84. package/x/vlocalchain/handler.go +21 -0
  85. package/x/vlocalchain/keeper/keeper.go +279 -0
  86. package/x/vlocalchain/keeper/keeper_test.go +97 -0
  87. package/x/vlocalchain/types/codec.go +34 -0
  88. package/x/vlocalchain/types/key.go +27 -0
  89. package/x/vlocalchain/types/msgs.go +16 -0
  90. package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
  91. package/x/vlocalchain/vlocalchain.go +114 -0
  92. package/x/vlocalchain/vlocalchain_test.go +434 -0
  93. package/x/vstorage/handler.go +2 -1
  94. package/x/vstorage/keeper/grpc_query.go +0 -1
  95. package/x/vstorage/keeper/keeper.go +13 -20
  96. package/x/vstorage/keeper/querier.go +6 -5
  97. package/x/vstorage/keeper/querier_test.go +4 -3
  98. package/x/vstorage/module.go +0 -5
  99. package/x/vstorage/testing/queue.go +27 -0
  100. package/x/vtransfer/alias.go +13 -0
  101. package/x/vtransfer/genesis.go +39 -0
  102. package/x/vtransfer/genesis_test.go +12 -0
  103. package/x/vtransfer/handler.go +20 -0
  104. package/x/vtransfer/ibc_middleware.go +186 -0
  105. package/x/vtransfer/ibc_middleware_test.go +448 -0
  106. package/x/vtransfer/keeper/keeper.go +281 -0
  107. package/x/vtransfer/module.go +124 -0
  108. package/x/vtransfer/types/expected_keepers.go +38 -0
  109. package/x/vtransfer/types/genesis.pb.go +327 -0
  110. package/x/vtransfer/types/key.go +9 -0
  111. package/x/vtransfer/types/msgs.go +9 -0
  112. package/proto/agoric/lien/genesis.proto +0 -25
  113. package/proto/agoric/lien/lien.proto +0 -25
  114. package/x/lien/alias.go +0 -17
  115. package/x/lien/genesis.go +0 -58
  116. package/x/lien/genesis_test.go +0 -101
  117. package/x/lien/keeper/account.go +0 -290
  118. package/x/lien/keeper/keeper.go +0 -255
  119. package/x/lien/keeper/keeper_test.go +0 -623
  120. package/x/lien/lien.go +0 -205
  121. package/x/lien/lien_test.go +0 -533
  122. package/x/lien/module.go +0 -115
  123. package/x/lien/spec/01_concepts.md +0 -146
  124. package/x/lien/spec/02_messages.md +0 -96
  125. package/x/lien/types/accountkeeper.go +0 -81
  126. package/x/lien/types/accountstate.go +0 -27
  127. package/x/lien/types/expected_keepers.go +0 -18
  128. package/x/lien/types/genesis.pb.go +0 -567
  129. package/x/lien/types/key.go +0 -25
  130. package/x/lien/types/lien.pb.go +0 -403
  131. package/x/vibc/ibc.go +0 -394
@@ -1,533 +0,0 @@
1
- package lien
2
-
3
- import (
4
- "context"
5
- "encoding/json"
6
- "reflect"
7
- "testing"
8
-
9
- "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
10
-
11
- "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
12
- sdk "github.com/cosmos/cosmos-sdk/types"
13
- stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
14
- "github.com/tendermint/tendermint/crypto/secp256k1"
15
- )
16
-
17
- func makeAccAddress() sdk.AccAddress {
18
- priv := secp256k1.GenPrivKey()
19
- return sdk.AccAddress(priv.PubKey().Address())
20
- }
21
-
22
- func makeValidator() stakingTypes.Validator {
23
- valPriv := ed25519.GenPrivKey()
24
- valPub := valPriv.PubKey()
25
- vaddr := sdk.ValAddress(valPub.Address().Bytes())
26
- validator, err := stakingTypes.NewValidator(vaddr, valPub, stakingTypes.Description{})
27
- if err != nil {
28
- panic(err)
29
- }
30
- return validator
31
- }
32
-
33
- var (
34
- addr1 = makeAccAddress().String()
35
- i = sdk.NewInt
36
- zero = i(0)
37
- zeroCoins = sdk.NewCoins()
38
- c = sdk.NewInt64Coin
39
- emptyState = types.AccountState{
40
- Total: zeroCoins,
41
- Bonded: zeroCoins,
42
- Unbonding: zeroCoins,
43
- Locked: zeroCoins,
44
- Liened: zeroCoins,
45
- }
46
- )
47
-
48
- type mockLienKeeper struct {
49
- states map[string]types.AccountState
50
- validators map[string]stakingTypes.Validator
51
- delegations map[string][]stakingTypes.Delegation
52
- updateAddr sdk.AccAddress
53
- updateCoin sdk.Coin
54
- }
55
-
56
- var _ Keeper = &mockLienKeeper{}
57
-
58
- func (m *mockLienKeeper) GetAccountWrapper() types.AccountWrapper {
59
- return types.DefaultAccountWrapper
60
- }
61
-
62
- func (m *mockLienKeeper) GetLien(ctx sdk.Context, addr sdk.AccAddress) types.Lien {
63
- state := m.GetAccountState(ctx, addr)
64
- return types.Lien{Coins: state.Liened}
65
- }
66
-
67
- func (m *mockLienKeeper) SetLien(ctx sdk.Context, addr sdk.AccAddress, lien types.Lien) {
68
- state := m.GetAccountState(ctx, addr)
69
- state.Liened = lien.Coins
70
- m.states[addr.String()] = state
71
- }
72
-
73
- func (m *mockLienKeeper) IterateLiens(ctx sdk.Context, cb func(addr sdk.AccAddress, lien types.Lien) bool) {
74
- }
75
-
76
- func (m *mockLienKeeper) ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom string, delta sdk.Int) (sdk.Int, error) {
77
- state := m.GetAccountState(ctx, addr)
78
- oldLiened := state.Liened.AmountOf(denom)
79
- newLiened := oldLiened.Add(delta)
80
- m.updateAddr = addr
81
- m.updateCoin = sdk.NewCoin(denom, newLiened)
82
- return newLiened, nil
83
- }
84
-
85
- func (m *mockLienKeeper) GetAccountState(ctx sdk.Context, addr sdk.AccAddress) types.AccountState {
86
- state, found := m.states[addr.String()]
87
- if !found {
88
- return emptyState
89
- }
90
- return state
91
- }
92
-
93
- func (m *mockLienKeeper) BondDenom(ctx sdk.Context) string {
94
- return "ubld"
95
- }
96
-
97
- func (m *mockLienKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
98
- state := m.GetAccountState(ctx, addr)
99
- delegated := state.Bonded.Add(state.Unbonding...)
100
- bank := state.Total.Sub(state.Total.Min(delegated)...)
101
- return bank
102
- }
103
-
104
- func (m *mockLienKeeper) GetValidator(ctx sdk.Context, valAddr sdk.ValAddress) (stakingTypes.Validator, bool) {
105
- v, found := m.validators[valAddr.String()]
106
- return v, found
107
- }
108
-
109
- func (m *mockLienKeeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) []stakingTypes.Delegation {
110
- if d, found := m.delegations[delegator.String()]; found {
111
- return d
112
- }
113
- return []stakingTypes.Delegation{}
114
- }
115
-
116
- func TestBadType(t *testing.T) {
117
- ctx := sdk.Context{}.WithContext(context.Background())
118
- ctlCtx := sdk.WrapSDKContext(ctx)
119
- keeper := mockLienKeeper{
120
- states: map[string]types.AccountState{},
121
- }
122
- ph := NewPortHandler(&keeper)
123
-
124
- msg := portMessage{
125
- Type: "LIEN_BAD_TYPE",
126
- }
127
- jsonMsg, err := json.Marshal(&msg)
128
- if err != nil {
129
- t.Fatalf("cannot marshal message: %v", err)
130
- }
131
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
132
- if err == nil {
133
- t.Errorf("bad type got %v, want error", reply)
134
- }
135
- }
136
-
137
- func TestGetAccountState(t *testing.T) {
138
- ctx := sdk.Context{}.WithContext(context.Background())
139
- ctlCtx := sdk.WrapSDKContext(ctx)
140
-
141
- keeper := mockLienKeeper{
142
- states: map[string]types.AccountState{
143
- addr1: {Total: sdk.NewCoins(c("ubld", 123), c("urun", 456))},
144
- },
145
- }
146
- ph := NewPortHandler(&keeper)
147
- msg := portMessage{
148
- Type: "LIEN_GET_ACCOUNT_STATE",
149
- Address: addr1,
150
- Denom: "ubld",
151
- }
152
- jsonMsg, err := json.Marshal(&msg)
153
- if err != nil {
154
- t.Fatalf("cannot marshal message: %v", err)
155
- }
156
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
157
- if err != nil {
158
- t.Fatalf("receive error: %v", err)
159
- }
160
- var acctState msgAccountState
161
- err = json.Unmarshal([]byte(reply), &acctState)
162
- if err != nil {
163
- t.Fatalf("cannot unmarshal reply %s: %v", reply, err)
164
- }
165
- acctState.CurrentTime = int64(123456789)
166
- want := msgAccountState{
167
- CurrentTime: acctState.CurrentTime,
168
- Total: i(123),
169
- Bonded: zero,
170
- Unbonding: zero,
171
- Locked: zero,
172
- Liened: zero,
173
- }
174
- if !reflect.DeepEqual(acctState, want) {
175
- t.Errorf("got account state %v, want %v", acctState, want)
176
- }
177
- }
178
-
179
- func TestGetAccountState_badRequest(t *testing.T) {
180
- ctx := sdk.Context{}.WithContext(context.Background())
181
- ctlCtx := sdk.WrapSDKContext(ctx)
182
-
183
- keeper := mockLienKeeper{
184
- states: map[string]types.AccountState{},
185
- }
186
- ph := NewPortHandler(&keeper)
187
-
188
- msg := portMessage{
189
- Type: "LIEN_GET_ACCOUNT_STATE",
190
- Address: "foo",
191
- Denom: "ubld",
192
- }
193
- jsonMsg, err := json.Marshal(&msg)
194
- if err != nil {
195
- t.Fatalf("cannot marshal message: %v", err)
196
- }
197
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
198
- if err == nil {
199
- t.Errorf("bad address got %v, want error", reply)
200
- }
201
-
202
- msg = portMessage{
203
- Type: "LIEN_GET_ACCOUNT_STATE",
204
- Address: addr1,
205
- Denom: "x",
206
- }
207
- jsonMsg, err = json.Marshal(&msg)
208
- if err != nil {
209
- t.Fatalf("cannot marshal message: %v", err)
210
- }
211
- reply, err = ph.Receive(ctlCtx, string(jsonMsg))
212
- if err == nil {
213
- t.Errorf("bad denom got %v, want error", reply)
214
- }
215
- }
216
-
217
- func TestSetLiened_badAddr(t *testing.T) {
218
- ctx := sdk.Context{}.WithContext(context.Background())
219
- ctlCtx := sdk.WrapSDKContext(ctx)
220
-
221
- keeper := mockLienKeeper{}
222
- ph := NewPortHandler(&keeper)
223
- msg := portMessage{
224
- Type: "LIEN_CHANGE_LIENED",
225
- Address: "foo",
226
- Denom: "ubld",
227
- Delta: i(123),
228
- }
229
- jsonMsg, err := json.Marshal(&msg)
230
- if err != nil {
231
- t.Fatalf("cannot marshal message: %v", err)
232
- }
233
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
234
- if err == nil {
235
- t.Fatalf("got %v, want err", reply)
236
- }
237
- }
238
-
239
- func TestSetLiened_badDenom(t *testing.T) {
240
- ctx := sdk.Context{}.WithContext(context.Background())
241
- ctlCtx := sdk.WrapSDKContext(ctx)
242
-
243
- keeper := mockLienKeeper{}
244
- ph := NewPortHandler(&keeper)
245
- msg := portMessage{
246
- Type: "LIEN_CHANGE_LIENED",
247
- Address: addr1,
248
- Denom: "x",
249
- Delta: i(123),
250
- }
251
- jsonMsg, err := json.Marshal(&msg)
252
- if err != nil {
253
- t.Fatalf("cannot marshal message: %v", err)
254
- }
255
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
256
- if err == nil {
257
- t.Fatalf("got %v, want err", reply)
258
- }
259
- }
260
-
261
- func TestSetLiened(t *testing.T) {
262
- ctx := sdk.Context{}.WithContext(context.Background())
263
- ctlCtx := sdk.WrapSDKContext(ctx)
264
-
265
- keeper := mockLienKeeper{}
266
- ph := NewPortHandler(&keeper)
267
- msg := portMessage{
268
- Type: "LIEN_CHANGE_LIENED",
269
- Address: addr1,
270
- Denom: "ubld",
271
- Delta: i(123),
272
- }
273
- jsonMsg, err := json.Marshal(&msg)
274
- if err != nil {
275
- t.Fatalf("cannot marshal message: %v", err)
276
- }
277
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
278
- if err != nil {
279
- t.Fatalf("Receive error %v", err)
280
- }
281
- if reply != `"123"` {
282
- t.Fatalf(`Receive returned %s, want "123"`, reply)
283
- }
284
- if keeper.updateAddr.String() != addr1 {
285
- t.Errorf("lien update with address %s, want %s", keeper.updateAddr, addr1)
286
- }
287
- wantCoin := c("ubld", 123)
288
- if !keeper.updateCoin.IsEqual(wantCoin) {
289
- t.Errorf("lien update got %s, want %s", keeper.updateCoin, wantCoin)
290
- }
291
- }
292
-
293
- func TestGetStaking(t *testing.T) {
294
- val1, _ := makeValidator().AddTokensFromDel(i(12300))
295
- val2, _ := makeValidator().AddTokensFromDel(i(2345))
296
- val3, _ := makeValidator().AddTokensFromDel(i(34567))
297
- addr1 := makeAccAddress()
298
- addr2 := makeAccAddress()
299
- addr3 := makeAccAddress()
300
- addr4 := makeAccAddress()
301
-
302
- keeper := mockLienKeeper{
303
- validators: make(map[string]stakingTypes.Validator),
304
- delegations: make(map[string][]stakingTypes.Delegation),
305
- }
306
- keeper.validators[val1.OperatorAddress] = val1
307
- keeper.validators[val2.OperatorAddress] = val2
308
- keeper.validators[val3.OperatorAddress] = val3
309
- keeper.delegations[addr1.String()] = []stakingTypes.Delegation{
310
- {
311
- DelegatorAddress: addr1.String(),
312
- ValidatorAddress: val1.OperatorAddress,
313
- Shares: sdk.NewDec(456),
314
- },
315
- {
316
- DelegatorAddress: addr1.String(),
317
- ValidatorAddress: val2.OperatorAddress,
318
- Shares: sdk.NewDec(54),
319
- },
320
- }
321
- keeper.delegations[addr2.String()] = []stakingTypes.Delegation{
322
- {
323
- DelegatorAddress: addr2.String(),
324
- ValidatorAddress: val1.OperatorAddress,
325
- Shares: sdk.NewDec(101),
326
- },
327
- {
328
- DelegatorAddress: addr2.String(),
329
- ValidatorAddress: val3.OperatorAddress,
330
- Shares: sdk.NewDec(424),
331
- },
332
- }
333
- keeper.delegations[addr3.String()] = []stakingTypes.Delegation{
334
- {
335
- DelegatorAddress: addr3.String(),
336
- ValidatorAddress: val3.OperatorAddress,
337
- Shares: sdk.NewDec(1025),
338
- },
339
- }
340
- keeper.delegations[addr4.String()] = []stakingTypes.Delegation{}
341
-
342
- ph := NewPortHandler(&keeper)
343
- ctx := sdk.Context{}.WithContext(context.Background())
344
- ctlCtx := sdk.WrapSDKContext(ctx)
345
-
346
- pi := func(x int64) *sdk.Int {
347
- n := i(x)
348
- return &n
349
- }
350
-
351
- null := (*sdk.Int)(nil)
352
-
353
- for _, tt := range []struct {
354
- name string
355
- validators []string
356
- delegators []string
357
- wantVals []*sdk.Int
358
- wantStates []*delegatorState
359
- }{
360
- {
361
- name: "empty",
362
- validators: []string{},
363
- delegators: []string{},
364
- wantVals: []*sdk.Int{},
365
- wantStates: []*delegatorState{},
366
- },
367
- {
368
- name: "one_val",
369
- validators: []string{val1.OperatorAddress},
370
- delegators: []string{},
371
- wantVals: []*sdk.Int{pi(12300)},
372
- wantStates: []*delegatorState{},
373
- },
374
- {
375
- name: "one_del",
376
- validators: []string{},
377
- delegators: []string{addr1.String()},
378
- wantVals: []*sdk.Int{},
379
- wantStates: []*delegatorState{
380
- {
381
- ValidatorIdx: []int{},
382
- Values: []sdk.Int{},
383
- Other: i(510),
384
- },
385
- },
386
- },
387
- {
388
- name: "one_each",
389
- validators: []string{val1.OperatorAddress},
390
- delegators: []string{addr1.String()},
391
- wantVals: []*sdk.Int{pi(12300)},
392
- wantStates: []*delegatorState{
393
- {
394
- ValidatorIdx: []int{0},
395
- Values: []sdk.Int{i(456)},
396
- Other: i(54),
397
- },
398
- },
399
- },
400
- {
401
- name: "full",
402
- validators: []string{val1.OperatorAddress, val2.OperatorAddress, val3.OperatorAddress},
403
- delegators: []string{addr1.String(), addr2.String(), addr3.String(), addr4.String()},
404
- wantVals: []*sdk.Int{pi(12300), pi(2345), pi(34567)},
405
- wantStates: []*delegatorState{
406
- {
407
- ValidatorIdx: []int{0, 1},
408
- Values: []sdk.Int{i(456), i(54)},
409
- Other: zero,
410
- },
411
- {
412
- ValidatorIdx: []int{0, 2},
413
- Values: []sdk.Int{i(101), i(424)},
414
- Other: zero,
415
- },
416
- {
417
- ValidatorIdx: []int{2},
418
- Values: []sdk.Int{i(1025)},
419
- Other: zero,
420
- },
421
- {
422
- ValidatorIdx: []int{},
423
- Values: []sdk.Int{},
424
- Other: zero,
425
- },
426
- },
427
- },
428
- {
429
- name: "dup",
430
- validators: []string{val1.OperatorAddress, val1.OperatorAddress},
431
- delegators: []string{addr1.String(), addr1.String()},
432
- wantVals: []*sdk.Int{pi(12300), pi(12300)},
433
- wantStates: []*delegatorState{
434
- {
435
- ValidatorIdx: []int{1}, // selects last index
436
- Values: []sdk.Int{i(456)},
437
- Other: i(54),
438
- },
439
- {
440
- ValidatorIdx: []int{1}, // selects last index
441
- Values: []sdk.Int{i(456)},
442
- Other: i(54),
443
- },
444
- },
445
- },
446
- {
447
- name: "bad_addr",
448
- validators: []string{"foo", val1.OperatorAddress},
449
- delegators: []string{"bar", addr1.String()},
450
- wantVals: []*sdk.Int{null, pi(12300)},
451
- wantStates: []*delegatorState{
452
- nil,
453
- {
454
- ValidatorIdx: []int{1},
455
- Values: []sdk.Int{i(456)},
456
- Other: i(54),
457
- },
458
- },
459
- },
460
- } {
461
- t.Run(tt.name, func(t *testing.T) {
462
- msg := portMessage{
463
- Type: "LIEN_GET_STAKING",
464
- Validators: tt.validators,
465
- Delegators: tt.delegators,
466
- }
467
- j, err := json.Marshal(&msg)
468
- if err != nil {
469
- t.Fatalf("cannot marshal message: %v", err)
470
- }
471
- reply, err := ph.Receive(ctlCtx, string(j))
472
- if err != nil {
473
- t.Fatalf("Receive error: %v", err)
474
- }
475
- result := msgStaking{}
476
- err = json.Unmarshal([]byte(reply), &result)
477
- if err != nil {
478
- t.Fatalf("cannot unmarshal reply %s: %v", reply, err)
479
- }
480
- if result.Denom != "ubld" {
481
- t.Errorf("denom got %s, want ubld", result.Denom)
482
- }
483
- if len(result.ValidatorValues) != len(tt.wantVals) {
484
- t.Errorf("wrong # of vals returned - got %v, want %v", result.ValidatorValues, tt.wantVals)
485
- } else {
486
- for j, got := range result.ValidatorValues {
487
- want := tt.wantVals[j]
488
- if got == nil {
489
- if want != nil {
490
- t.Errorf("validator %d got null, want %v", j, want)
491
- }
492
- } else if want == nil {
493
- t.Errorf("validator %d got %v, want nil", j, *got)
494
- } else if !got.Equal(*want) {
495
- t.Errorf("validator %d got %v, want %v", j, got, want)
496
- }
497
- }
498
- }
499
- if len(result.DelegatorStates) != len(tt.wantStates) {
500
- t.Errorf("wrong # of states returned - got %v, want %v", result.DelegatorStates, tt.wantStates)
501
- } else {
502
- for s, got := range result.DelegatorStates {
503
- want := tt.wantStates[s]
504
- if got == nil {
505
- if want != nil {
506
- t.Errorf("delegator %d got nil, want %v", s, want)
507
- }
508
- continue
509
- }
510
- if want == nil {
511
- t.Errorf("delegator %d got %v, want nil", s, got)
512
- continue
513
- }
514
- if !reflect.DeepEqual(got.ValidatorIdx, want.ValidatorIdx) {
515
- t.Errorf("state %d bad validator indexes - got %v, want %v", s, got.ValidatorIdx, want.ValidatorIdx)
516
- }
517
- if len(got.Values) != len(want.Values) {
518
- t.Errorf("state %d wrong # values - got %v, want %v", s, got.Values, want.Values)
519
- } else {
520
- for v, gotVal := range got.Values {
521
- if !gotVal.Equal(want.Values[v]) {
522
- t.Errorf("state %d value %d got %v, want %v", s, v, gotVal, want.Values[v])
523
- }
524
- }
525
- }
526
- if !got.Other.Equal(want.Other) {
527
- t.Errorf("state %d wrong 'other' got %v, want %v", s, got.Other, want.Other)
528
- }
529
- }
530
- }
531
- })
532
- }
533
- }
package/x/lien/module.go DELETED
@@ -1,115 +0,0 @@
1
- package lien
2
-
3
- import (
4
- "encoding/json"
5
- "fmt"
6
-
7
- "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
8
- "github.com/gorilla/mux"
9
- "github.com/grpc-ecosystem/grpc-gateway/runtime"
10
- "github.com/spf13/cobra"
11
- abci "github.com/tendermint/tendermint/abci/types"
12
-
13
- "github.com/cosmos/cosmos-sdk/client"
14
- "github.com/cosmos/cosmos-sdk/codec"
15
- codectypes "github.com/cosmos/cosmos-sdk/codec/types"
16
- sdk "github.com/cosmos/cosmos-sdk/types"
17
- "github.com/cosmos/cosmos-sdk/types/module"
18
- )
19
-
20
- var (
21
- _ module.AppModuleBasic = AppModuleBasic{}
22
- _ module.AppModule = AppModule{}
23
- )
24
-
25
- // AppModuleBasic is the concrete type implementing module.AppModuleBasic.
26
- type AppModuleBasic struct {
27
- }
28
-
29
- // Name implements the module.AppModuleBasic interface.
30
- func (AppModuleBasic) Name() string {
31
- return types.ModuleName
32
- }
33
-
34
- func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
35
- }
36
-
37
- func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {
38
- }
39
-
40
- func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
41
- genesisState := DefaultGenesisState()
42
- return cdc.MustMarshalJSON(&genesisState)
43
- }
44
-
45
- func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, data json.RawMessage) error {
46
- var genesisState types.GenesisState
47
- if err := cdc.UnmarshalJSON(data, &genesisState); err != nil {
48
- return fmt.Errorf("failed to unmarshal %s genesis state: %s", types.ModuleName, err)
49
- }
50
- return ValidateGenesis(genesisState)
51
- }
52
-
53
- func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {
54
- }
55
-
56
- func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {
57
- }
58
-
59
- func (AppModuleBasic) GetTxCmd() *cobra.Command {
60
- return nil
61
- }
62
-
63
- func (AppModuleBasic) GetQueryCmd() *cobra.Command {
64
- return nil
65
- }
66
-
67
- type AppModule struct {
68
- AppModuleBasic
69
- keeper Keeper
70
- }
71
-
72
- func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
73
- var genesisState types.GenesisState
74
- cdc.MustUnmarshalJSON(data, &genesisState)
75
- InitGenesis(ctx, am.keeper, genesisState)
76
- return []abci.ValidatorUpdate{}
77
- }
78
-
79
- func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
80
- genesisState := ExportGenesis(ctx, am.keeper)
81
- return cdc.MustMarshalJSON(&genesisState)
82
- }
83
-
84
- func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {
85
- }
86
-
87
- func (am AppModule) Route() sdk.Route {
88
- return sdk.Route{}
89
- }
90
-
91
- func (am AppModule) QuerierRoute() string {
92
- return ""
93
- }
94
-
95
- func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier {
96
- return nil
97
- }
98
-
99
- func (am AppModule) RegisterServices(module.Configurator) {
100
- }
101
-
102
- func (am AppModule) ConsensusVersion() uint64 {
103
- return 1
104
- }
105
-
106
- func (am AppModule) BeginBlock(sdk.Context, abci.RequestBeginBlock) {
107
- }
108
-
109
- func (am AppModule) EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate {
110
- return []abci.ValidatorUpdate{}
111
- }
112
-
113
- func NewAppModule(k Keeper) module.AppModule {
114
- return AppModule{keeper: k}
115
- }