@agoric/cosmos 0.35.0-upgrade-14-dev-0169c7e.0 → 0.35.0-upgrade-16-dev-07b0130.0

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 (169) hide show
  1. package/CHANGELOG.md +121 -77
  2. package/MAINTAINERS.md +3 -0
  3. package/Makefile +49 -26
  4. package/ante/ante.go +11 -11
  5. package/ante/inbound_test.go +3 -2
  6. package/ante/vm_admission.go +2 -1
  7. package/app/app.go +260 -175
  8. package/app/export.go +13 -6
  9. package/app/upgrade.go +76 -0
  10. package/cmd/agd/agvm.go +42 -0
  11. package/cmd/agd/main.go +132 -11
  12. package/cmd/libdaemon/main.go +67 -53
  13. package/cmd/libdaemon/main_test.go +2 -1
  14. package/daemon/cmd/genaccounts.go +13 -9
  15. package/daemon/cmd/root.go +186 -73
  16. package/daemon/cmd/root_test.go +190 -2
  17. package/daemon/cmd/testnet.go +17 -6
  18. package/daemon/main.go +6 -3
  19. package/e2e_test/Makefile +29 -0
  20. package/e2e_test/README.md +100 -0
  21. package/e2e_test/go.mod +217 -0
  22. package/e2e_test/go.sum +1323 -0
  23. package/e2e_test/ibc_conformance_test.go +56 -0
  24. package/e2e_test/pfm_test.go +613 -0
  25. package/e2e_test/util.go +271 -0
  26. package/git-revision.txt +1 -1
  27. package/go.mod +110 -68
  28. package/go.sum +601 -248
  29. package/package.json +9 -5
  30. package/proto/agoric/swingset/genesis.proto +4 -0
  31. package/proto/agoric/swingset/swingset.proto +1 -1
  32. package/proto/agoric/vlocalchain/.clang-format +7 -0
  33. package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
  34. package/proto/agoric/vstorage/query.proto +53 -1
  35. package/proto/agoric/vtransfer/genesis.proto +18 -0
  36. package/scripts/protocgen.sh +16 -6
  37. package/third_party/proto/buf.yaml +1 -0
  38. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  39. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  40. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  41. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  42. package/third_party/proto/google/api/annotations.proto +1 -1
  43. package/third_party/proto/google/api/http.proto +181 -120
  44. package/third_party/proto/google/api/httpbody.proto +9 -6
  45. package/third_party/proto/google/protobuf/any.proto +1 -7
  46. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  47. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  48. package/types/kv_entry_helpers.go +42 -0
  49. package/upgradegaia.sh +21 -12
  50. package/vm/action.go +28 -24
  51. package/vm/action_test.go +36 -16
  52. package/vm/client.go +113 -0
  53. package/vm/client_test.go +182 -0
  54. package/vm/controller.go +18 -42
  55. package/vm/core_proposals.go +22 -2
  56. package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
  57. package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
  58. package/vm/proto_json.go +38 -0
  59. package/vm/proto_json_test.go +103 -0
  60. package/vm/server.go +124 -0
  61. package/x/swingset/abci.go +10 -10
  62. package/x/swingset/alias.go +2 -0
  63. package/x/swingset/client/cli/query.go +2 -2
  64. package/x/swingset/client/cli/tx.go +52 -33
  65. package/x/swingset/client/proposal_handler.go +2 -17
  66. package/x/swingset/genesis.go +84 -24
  67. package/x/swingset/handler.go +2 -1
  68. package/x/swingset/keeper/extension_snapshotter.go +2 -2
  69. package/x/swingset/keeper/keeper.go +21 -36
  70. package/x/swingset/keeper/keeper_test.go +1 -1
  71. package/x/swingset/keeper/msg_server.go +20 -22
  72. package/x/swingset/keeper/proposal.go +13 -3
  73. package/x/swingset/keeper/querier.go +23 -14
  74. package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
  75. package/x/swingset/keeper/test_utils.go +16 -0
  76. package/x/swingset/module.go +7 -7
  77. package/x/swingset/proposal_handler.go +5 -4
  78. package/x/swingset/swingset.go +4 -2
  79. package/x/swingset/testing/queue.go +17 -0
  80. package/x/swingset/types/codec.go +2 -2
  81. package/x/swingset/types/default-params.go +1 -1
  82. package/x/swingset/types/expected_keepers.go +3 -2
  83. package/x/swingset/types/genesis.pb.go +78 -25
  84. package/x/swingset/types/msgs.go +44 -24
  85. package/x/swingset/types/msgs.pb.go +16 -16
  86. package/x/swingset/types/params.go +2 -1
  87. package/x/swingset/types/proposal.go +10 -9
  88. package/x/swingset/types/swingset.pb.go +1 -1
  89. package/x/swingset/types/types.go +30 -28
  90. package/x/vbank/genesis.go +0 -2
  91. package/x/vbank/handler.go +2 -1
  92. package/x/vbank/keeper/keeper.go +3 -2
  93. package/x/vbank/keeper/querier.go +9 -4
  94. package/x/vbank/keeper/rewards.go +1 -1
  95. package/x/vbank/module.go +0 -5
  96. package/x/vbank/types/msgs.go +0 -12
  97. package/x/vbank/vbank.go +20 -19
  98. package/x/vbank/vbank_test.go +10 -10
  99. package/x/vibc/alias.go +3 -0
  100. package/x/vibc/handler.go +16 -9
  101. package/x/vibc/keeper/keeper.go +112 -74
  102. package/x/vibc/keeper/triggers.go +101 -0
  103. package/x/vibc/module.go +5 -8
  104. package/x/vibc/types/expected_keepers.go +26 -5
  105. package/x/vibc/types/ibc_module.go +336 -0
  106. package/x/vibc/types/msgs.go +1 -1
  107. package/x/vibc/types/msgs.pb.go +1 -1
  108. package/x/vibc/types/receiver.go +170 -0
  109. package/x/vlocalchain/alias.go +19 -0
  110. package/x/vlocalchain/handler.go +21 -0
  111. package/x/vlocalchain/keeper/keeper.go +279 -0
  112. package/x/vlocalchain/keeper/keeper_test.go +97 -0
  113. package/x/vlocalchain/types/codec.go +34 -0
  114. package/x/vlocalchain/types/key.go +27 -0
  115. package/x/vlocalchain/types/msgs.go +16 -0
  116. package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
  117. package/x/vlocalchain/vlocalchain.go +114 -0
  118. package/x/vlocalchain/vlocalchain_test.go +434 -0
  119. package/x/vstorage/README.md +138 -0
  120. package/x/vstorage/capdata/capdata.go +298 -0
  121. package/x/vstorage/capdata/capdata_test.go +352 -0
  122. package/x/vstorage/client/cli/query.go +51 -4
  123. package/x/vstorage/handler.go +2 -1
  124. package/x/vstorage/keeper/grpc_query.go +220 -0
  125. package/x/vstorage/keeper/keeper.go +16 -22
  126. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  127. package/x/vstorage/keeper/keeper_test.go +1 -1
  128. package/x/vstorage/keeper/querier.go +11 -6
  129. package/x/vstorage/keeper/querier_test.go +4 -3
  130. package/x/vstorage/module.go +0 -5
  131. package/x/vstorage/testing/queue.go +27 -0
  132. package/x/vstorage/types/query.pb.go +646 -36
  133. package/x/vstorage/types/query.pb.gw.go +119 -0
  134. package/x/vstorage/vstorage.go +16 -15
  135. package/x/vstorage/vstorage_test.go +5 -5
  136. package/x/vtransfer/alias.go +13 -0
  137. package/x/vtransfer/genesis.go +39 -0
  138. package/x/vtransfer/genesis_test.go +12 -0
  139. package/x/vtransfer/handler.go +20 -0
  140. package/x/vtransfer/ibc_middleware.go +186 -0
  141. package/x/vtransfer/ibc_middleware_test.go +448 -0
  142. package/x/vtransfer/keeper/keeper.go +281 -0
  143. package/x/vtransfer/module.go +124 -0
  144. package/x/vtransfer/types/expected_keepers.go +38 -0
  145. package/x/vtransfer/types/genesis.pb.go +327 -0
  146. package/x/vtransfer/types/key.go +9 -0
  147. package/x/vtransfer/types/msgs.go +9 -0
  148. package/ante/fee.go +0 -96
  149. package/proto/agoric/lien/genesis.proto +0 -25
  150. package/proto/agoric/lien/lien.proto +0 -25
  151. package/x/lien/alias.go +0 -17
  152. package/x/lien/genesis.go +0 -58
  153. package/x/lien/genesis_test.go +0 -101
  154. package/x/lien/keeper/account.go +0 -290
  155. package/x/lien/keeper/keeper.go +0 -254
  156. package/x/lien/keeper/keeper_test.go +0 -623
  157. package/x/lien/lien.go +0 -203
  158. package/x/lien/lien_test.go +0 -529
  159. package/x/lien/module.go +0 -115
  160. package/x/lien/spec/01_concepts.md +0 -146
  161. package/x/lien/spec/02_messages.md +0 -96
  162. package/x/lien/types/accountkeeper.go +0 -81
  163. package/x/lien/types/accountstate.go +0 -27
  164. package/x/lien/types/expected_keepers.go +0 -18
  165. package/x/lien/types/genesis.pb.go +0 -567
  166. package/x/lien/types/key.go +0 -25
  167. package/x/lien/types/lien.pb.go +0 -403
  168. package/x/vibc/ibc.go +0 -393
  169. /package/{src/index.cjs → index.cjs} +0 -0
@@ -1,529 +0,0 @@
1
- package lien
2
-
3
- import (
4
- "encoding/json"
5
- "reflect"
6
- "testing"
7
-
8
- "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
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{}
118
- ctlCtx := &vm.ControllerContext{Context: 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{}
139
- ctlCtx := &vm.ControllerContext{Context: 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{}
181
- ctlCtx := &vm.ControllerContext{Context: ctx}
182
- keeper := mockLienKeeper{
183
- states: map[string]types.AccountState{},
184
- }
185
- ph := NewPortHandler(&keeper)
186
-
187
- msg := portMessage{
188
- Type: "LIEN_GET_ACCOUNT_STATE",
189
- Address: "foo",
190
- Denom: "ubld",
191
- }
192
- jsonMsg, err := json.Marshal(&msg)
193
- if err != nil {
194
- t.Fatalf("cannot marshal message: %v", err)
195
- }
196
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
197
- if err == nil {
198
- t.Errorf("bad address got %v, want error", reply)
199
- }
200
-
201
- msg = portMessage{
202
- Type: "LIEN_GET_ACCOUNT_STATE",
203
- Address: addr1,
204
- Denom: "x",
205
- }
206
- jsonMsg, err = json.Marshal(&msg)
207
- if err != nil {
208
- t.Fatalf("cannot marshal message: %v", err)
209
- }
210
- reply, err = ph.Receive(ctlCtx, string(jsonMsg))
211
- if err == nil {
212
- t.Errorf("bad denom got %v, want error", reply)
213
- }
214
- }
215
-
216
- func TestSetLiened_badAddr(t *testing.T) {
217
- ctx := sdk.Context{}
218
- ctlCtx := &vm.ControllerContext{Context: ctx}
219
- keeper := mockLienKeeper{}
220
- ph := NewPortHandler(&keeper)
221
- msg := portMessage{
222
- Type: "LIEN_CHANGE_LIENED",
223
- Address: "foo",
224
- Denom: "ubld",
225
- Delta: i(123),
226
- }
227
- jsonMsg, err := json.Marshal(&msg)
228
- if err != nil {
229
- t.Fatalf("cannot marshal message: %v", err)
230
- }
231
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
232
- if err == nil {
233
- t.Fatalf("got %v, want err", reply)
234
- }
235
- }
236
-
237
- func TestSetLiened_badDenom(t *testing.T) {
238
- ctx := sdk.Context{}
239
- ctlCtx := &vm.ControllerContext{Context: ctx}
240
- keeper := mockLienKeeper{}
241
- ph := NewPortHandler(&keeper)
242
- msg := portMessage{
243
- Type: "LIEN_CHANGE_LIENED",
244
- Address: addr1,
245
- Denom: "x",
246
- Delta: i(123),
247
- }
248
- jsonMsg, err := json.Marshal(&msg)
249
- if err != nil {
250
- t.Fatalf("cannot marshal message: %v", err)
251
- }
252
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
253
- if err == nil {
254
- t.Fatalf("got %v, want err", reply)
255
- }
256
- }
257
-
258
- func TestSetLiened(t *testing.T) {
259
- ctx := sdk.Context{}
260
- ctlCtx := &vm.ControllerContext{Context: ctx}
261
- keeper := mockLienKeeper{}
262
- ph := NewPortHandler(&keeper)
263
- msg := portMessage{
264
- Type: "LIEN_CHANGE_LIENED",
265
- Address: addr1,
266
- Denom: "ubld",
267
- Delta: i(123),
268
- }
269
- jsonMsg, err := json.Marshal(&msg)
270
- if err != nil {
271
- t.Fatalf("cannot marshal message: %v", err)
272
- }
273
- reply, err := ph.Receive(ctlCtx, string(jsonMsg))
274
- if err != nil {
275
- t.Fatalf("Receive error %v", err)
276
- }
277
- if reply != `"123"` {
278
- t.Fatalf(`Receive returned %s, want "123"`, reply)
279
- }
280
- if keeper.updateAddr.String() != addr1 {
281
- t.Errorf("lien update with address %s, want %s", keeper.updateAddr, addr1)
282
- }
283
- wantCoin := c("ubld", 123)
284
- if !keeper.updateCoin.IsEqual(wantCoin) {
285
- t.Errorf("lien update got %s, want %s", keeper.updateCoin, wantCoin)
286
- }
287
- }
288
-
289
- func TestGetStaking(t *testing.T) {
290
- val1, _ := makeValidator().AddTokensFromDel(i(12300))
291
- val2, _ := makeValidator().AddTokensFromDel(i(2345))
292
- val3, _ := makeValidator().AddTokensFromDel(i(34567))
293
- addr1 := makeAccAddress()
294
- addr2 := makeAccAddress()
295
- addr3 := makeAccAddress()
296
- addr4 := makeAccAddress()
297
-
298
- keeper := mockLienKeeper{
299
- validators: make(map[string]stakingTypes.Validator),
300
- delegations: make(map[string][]stakingTypes.Delegation),
301
- }
302
- keeper.validators[val1.OperatorAddress] = val1
303
- keeper.validators[val2.OperatorAddress] = val2
304
- keeper.validators[val3.OperatorAddress] = val3
305
- keeper.delegations[addr1.String()] = []stakingTypes.Delegation{
306
- {
307
- DelegatorAddress: addr1.String(),
308
- ValidatorAddress: val1.OperatorAddress,
309
- Shares: sdk.NewDec(456),
310
- },
311
- {
312
- DelegatorAddress: addr1.String(),
313
- ValidatorAddress: val2.OperatorAddress,
314
- Shares: sdk.NewDec(54),
315
- },
316
- }
317
- keeper.delegations[addr2.String()] = []stakingTypes.Delegation{
318
- {
319
- DelegatorAddress: addr2.String(),
320
- ValidatorAddress: val1.OperatorAddress,
321
- Shares: sdk.NewDec(101),
322
- },
323
- {
324
- DelegatorAddress: addr2.String(),
325
- ValidatorAddress: val3.OperatorAddress,
326
- Shares: sdk.NewDec(424),
327
- },
328
- }
329
- keeper.delegations[addr3.String()] = []stakingTypes.Delegation{
330
- {
331
- DelegatorAddress: addr3.String(),
332
- ValidatorAddress: val3.OperatorAddress,
333
- Shares: sdk.NewDec(1025),
334
- },
335
- }
336
- keeper.delegations[addr4.String()] = []stakingTypes.Delegation{}
337
-
338
- ph := NewPortHandler(&keeper)
339
- ctx := sdk.Context{}
340
- ctlCtx := &vm.ControllerContext{Context: ctx}
341
-
342
- pi := func(x int64) *sdk.Int {
343
- n := i(x)
344
- return &n
345
- }
346
-
347
- null := (*sdk.Int)(nil)
348
-
349
- for _, tt := range []struct {
350
- name string
351
- validators []string
352
- delegators []string
353
- wantVals []*sdk.Int
354
- wantStates []*delegatorState
355
- }{
356
- {
357
- name: "empty",
358
- validators: []string{},
359
- delegators: []string{},
360
- wantVals: []*sdk.Int{},
361
- wantStates: []*delegatorState{},
362
- },
363
- {
364
- name: "one_val",
365
- validators: []string{val1.OperatorAddress},
366
- delegators: []string{},
367
- wantVals: []*sdk.Int{pi(12300)},
368
- wantStates: []*delegatorState{},
369
- },
370
- {
371
- name: "one_del",
372
- validators: []string{},
373
- delegators: []string{addr1.String()},
374
- wantVals: []*sdk.Int{},
375
- wantStates: []*delegatorState{
376
- {
377
- ValidatorIdx: []int{},
378
- Values: []sdk.Int{},
379
- Other: i(510),
380
- },
381
- },
382
- },
383
- {
384
- name: "one_each",
385
- validators: []string{val1.OperatorAddress},
386
- delegators: []string{addr1.String()},
387
- wantVals: []*sdk.Int{pi(12300)},
388
- wantStates: []*delegatorState{
389
- {
390
- ValidatorIdx: []int{0},
391
- Values: []sdk.Int{i(456)},
392
- Other: i(54),
393
- },
394
- },
395
- },
396
- {
397
- name: "full",
398
- validators: []string{val1.OperatorAddress, val2.OperatorAddress, val3.OperatorAddress},
399
- delegators: []string{addr1.String(), addr2.String(), addr3.String(), addr4.String()},
400
- wantVals: []*sdk.Int{pi(12300), pi(2345), pi(34567)},
401
- wantStates: []*delegatorState{
402
- {
403
- ValidatorIdx: []int{0, 1},
404
- Values: []sdk.Int{i(456), i(54)},
405
- Other: zero,
406
- },
407
- {
408
- ValidatorIdx: []int{0, 2},
409
- Values: []sdk.Int{i(101), i(424)},
410
- Other: zero,
411
- },
412
- {
413
- ValidatorIdx: []int{2},
414
- Values: []sdk.Int{i(1025)},
415
- Other: zero,
416
- },
417
- {
418
- ValidatorIdx: []int{},
419
- Values: []sdk.Int{},
420
- Other: zero,
421
- },
422
- },
423
- },
424
- {
425
- name: "dup",
426
- validators: []string{val1.OperatorAddress, val1.OperatorAddress},
427
- delegators: []string{addr1.String(), addr1.String()},
428
- wantVals: []*sdk.Int{pi(12300), pi(12300)},
429
- wantStates: []*delegatorState{
430
- {
431
- ValidatorIdx: []int{1}, // selects last index
432
- Values: []sdk.Int{i(456)},
433
- Other: i(54),
434
- },
435
- {
436
- ValidatorIdx: []int{1}, // selects last index
437
- Values: []sdk.Int{i(456)},
438
- Other: i(54),
439
- },
440
- },
441
- },
442
- {
443
- name: "bad_addr",
444
- validators: []string{"foo", val1.OperatorAddress},
445
- delegators: []string{"bar", addr1.String()},
446
- wantVals: []*sdk.Int{null, pi(12300)},
447
- wantStates: []*delegatorState{
448
- nil,
449
- {
450
- ValidatorIdx: []int{1},
451
- Values: []sdk.Int{i(456)},
452
- Other: i(54),
453
- },
454
- },
455
- },
456
- } {
457
- t.Run(tt.name, func(t *testing.T) {
458
- msg := portMessage{
459
- Type: "LIEN_GET_STAKING",
460
- Validators: tt.validators,
461
- Delegators: tt.delegators,
462
- }
463
- j, err := json.Marshal(&msg)
464
- if err != nil {
465
- t.Fatalf("cannot marshal message: %v", err)
466
- }
467
- reply, err := ph.Receive(ctlCtx, string(j))
468
- if err != nil {
469
- t.Fatalf("Receive error: %v", err)
470
- }
471
- result := msgStaking{}
472
- err = json.Unmarshal([]byte(reply), &result)
473
- if err != nil {
474
- t.Fatalf("cannot unmarshal reply %s: %v", reply, err)
475
- }
476
- if result.Denom != "ubld" {
477
- t.Errorf("denom got %s, want ubld", result.Denom)
478
- }
479
- if len(result.ValidatorValues) != len(tt.wantVals) {
480
- t.Errorf("wrong # of vals returned - got %v, want %v", result.ValidatorValues, tt.wantVals)
481
- } else {
482
- for j, got := range result.ValidatorValues {
483
- want := tt.wantVals[j]
484
- if got == nil {
485
- if want != nil {
486
- t.Errorf("validator %d got null, want %v", j, want)
487
- }
488
- } else if want == nil {
489
- t.Errorf("validator %d got %v, want nil", j, *got)
490
- } else if !got.Equal(*want) {
491
- t.Errorf("validator %d got %v, want %v", j, got, want)
492
- }
493
- }
494
- }
495
- if len(result.DelegatorStates) != len(tt.wantStates) {
496
- t.Errorf("wrong # of states returned - got %v, want %v", result.DelegatorStates, tt.wantStates)
497
- } else {
498
- for s, got := range result.DelegatorStates {
499
- want := tt.wantStates[s]
500
- if got == nil {
501
- if want != nil {
502
- t.Errorf("delegator %d got nil, want %v", s, want)
503
- }
504
- continue
505
- }
506
- if want == nil {
507
- t.Errorf("delegator %d got %v, want nil", s, got)
508
- continue
509
- }
510
- if !reflect.DeepEqual(got.ValidatorIdx, want.ValidatorIdx) {
511
- t.Errorf("state %d bad validator indexes - got %v, want %v", s, got.ValidatorIdx, want.ValidatorIdx)
512
- }
513
- if len(got.Values) != len(want.Values) {
514
- t.Errorf("state %d wrong # values - got %v, want %v", s, got.Values, want.Values)
515
- } else {
516
- for v, gotVal := range got.Values {
517
- if !gotVal.Equal(want.Values[v]) {
518
- t.Errorf("state %d value %d got %v, want %v", s, v, gotVal, want.Values[v])
519
- }
520
- }
521
- }
522
- if !got.Other.Equal(want.Other) {
523
- t.Errorf("state %d wrong 'other' got %v, want %v", s, got.Other, want.Other)
524
- }
525
- }
526
- }
527
- })
528
- }
529
- }
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
- }