@agoric/cosmos 0.35.0-upgrade-14-dev-c8f9e7b.0 → 0.35.0-upgrade-16a-dev-fb592e4.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 (133) hide show
  1. package/CHANGELOG.md +121 -77
  2. package/MAINTAINERS.md +3 -0
  3. package/Makefile +36 -26
  4. package/ante/ante.go +7 -9
  5. package/ante/inbound_test.go +3 -2
  6. package/ante/vm_admission.go +2 -1
  7. package/app/app.go +212 -140
  8. package/app/upgrade.go +76 -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 +171 -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 +22 -11
  25. package/go.sum +17 -13
  26. package/package.json +9 -5
  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 +21 -6
  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/ante/fee.go +0 -96
  113. package/proto/agoric/lien/genesis.proto +0 -25
  114. package/proto/agoric/lien/lien.proto +0 -25
  115. package/x/lien/alias.go +0 -17
  116. package/x/lien/genesis.go +0 -58
  117. package/x/lien/genesis_test.go +0 -101
  118. package/x/lien/keeper/account.go +0 -290
  119. package/x/lien/keeper/keeper.go +0 -255
  120. package/x/lien/keeper/keeper_test.go +0 -623
  121. package/x/lien/lien.go +0 -205
  122. package/x/lien/lien_test.go +0 -533
  123. package/x/lien/module.go +0 -115
  124. package/x/lien/spec/01_concepts.md +0 -146
  125. package/x/lien/spec/02_messages.md +0 -96
  126. package/x/lien/types/accountkeeper.go +0 -81
  127. package/x/lien/types/accountstate.go +0 -27
  128. package/x/lien/types/expected_keepers.go +0 -18
  129. package/x/lien/types/genesis.pb.go +0 -567
  130. package/x/lien/types/key.go +0 -25
  131. package/x/lien/types/lien.pb.go +0 -403
  132. package/x/vibc/ibc.go +0 -394
  133. /package/{src/index.cjs → index.cjs} +0 -0
@@ -1,623 +0,0 @@
1
- package keeper
2
-
3
- import (
4
- "math"
5
- "reflect"
6
- "testing"
7
-
8
- "github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
9
- "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
10
- "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
11
-
12
- "github.com/cosmos/cosmos-sdk/crypto/codec"
13
- "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
14
- "github.com/cosmos/cosmos-sdk/store"
15
- storetypes "github.com/cosmos/cosmos-sdk/store/types"
16
- sdk "github.com/cosmos/cosmos-sdk/types"
17
- authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
18
- authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
19
- "github.com/cosmos/cosmos-sdk/x/auth/vesting"
20
- vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
21
- bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
22
- banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
23
- paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
24
- paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
25
- stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
26
- stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
27
-
28
- "github.com/tendermint/tendermint/crypto/secp256k1"
29
- "github.com/tendermint/tendermint/libs/log"
30
- tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
31
- dbm "github.com/tendermint/tm-db"
32
- )
33
-
34
- var (
35
- lienStoreKey = storetypes.NewKVStoreKey(types.StoreKey)
36
- authStoreKey = storetypes.NewKVStoreKey(authtypes.StoreKey)
37
- bankStoreKey = storetypes.NewKVStoreKey(banktypes.StoreKey)
38
- paramsStoreKey = storetypes.NewKVStoreKey(paramstypes.StoreKey)
39
- paramsTKey = storetypes.NewTransientStoreKey(paramstypes.TStoreKey)
40
- stakingStoreKey = storetypes.NewKVStoreKey(stakingtypes.StoreKey)
41
- )
42
-
43
- var (
44
- priv1 = secp256k1.GenPrivKey()
45
- priv2 = secp256k1.GenPrivKey()
46
- priv3 = secp256k1.GenPrivKey()
47
- addr1 = sdk.AccAddress(priv1.PubKey().Address())
48
- addr2 = sdk.AccAddress(priv2.PubKey().Address())
49
- addr3 = sdk.AccAddress(priv3.PubKey().Address())
50
- valPriv1 = ed25519.GenPrivKey()
51
- zeroCoins = sdk.NewCoins()
52
- emptyState = types.AccountState{
53
- Total: zeroCoins,
54
- Bonded: zeroCoins,
55
- Unbonding: zeroCoins,
56
- Locked: zeroCoins,
57
- Liened: zeroCoins,
58
- }
59
- )
60
-
61
- var (
62
- minterAcc = authtypes.NewEmptyModuleAccount(authtypes.Minter, authtypes.Minter)
63
- )
64
-
65
- func ubld(n int64) sdk.Coins {
66
- return sdk.NewCoins(sdk.NewInt64Coin("ubld", n))
67
- }
68
-
69
- type testKit struct {
70
- ctx sdk.Context
71
- accountKeeper authkeeper.AccountKeeper
72
- bankKeeper bankkeeper.Keeper
73
- stakingKeeper stakingkeeper.Keeper
74
- lienKeeper Keeper
75
- }
76
-
77
- func (tk testKit) expand() (sdk.Context, authkeeper.AccountKeeper, bankkeeper.Keeper, stakingkeeper.Keeper, Keeper) {
78
- return tk.ctx, tk.accountKeeper, tk.bankKeeper, tk.stakingKeeper, tk.lienKeeper
79
- }
80
-
81
- func makeTestKit() testKit {
82
- encodingConfig := params.MakeEncodingConfig()
83
- codec.RegisterInterfaces(encodingConfig.InterfaceRegistry)
84
- authtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
85
- vestingtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
86
- banktypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
87
- stakingtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
88
- cdc := encodingConfig.Marshaler
89
-
90
- // params keeper
91
- pk := paramskeeper.NewKeeper(cdc, encodingConfig.Amino, paramsStoreKey, paramsTKey)
92
- authSpace := pk.Subspace(authtypes.ModuleName)
93
- bankSpace := pk.Subspace(banktypes.ModuleName)
94
- stakingSpace := pk.Subspace(stakingtypes.ModuleName)
95
-
96
- // auth keeper
97
- maccPerms := map[string][]string{
98
- stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
99
- stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
100
- authtypes.Minter: {authtypes.Minter},
101
- }
102
- innerAk := authkeeper.NewAccountKeeper(cdc, authStoreKey, authSpace, authtypes.ProtoBaseAccount, maccPerms, "agoric")
103
- wak := types.NewWrappedAccountKeeper(innerAk)
104
-
105
- // bank keeper
106
- blockedAddrs := make(map[string]bool)
107
- blockedAddrs[authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String()] = true
108
- blockedAddrs[authtypes.NewModuleAddress(stakingtypes.NotBondedPoolName).String()] = true
109
- bk := bankkeeper.NewBaseKeeper(cdc, bankStoreKey, wak, bankSpace, blockedAddrs)
110
-
111
- // staking keeper
112
- sk := stakingkeeper.NewKeeper(cdc, stakingStoreKey, wak, bk, stakingSpace)
113
-
114
- // lien keeper
115
- pushAction := func(sdk.Context, vm.Action) error {
116
- return nil
117
- }
118
- keeper := NewKeeper(cdc, lienStoreKey, wak, bk, sk, pushAction)
119
- wak.SetWrapper(keeper.GetAccountWrapper())
120
-
121
- db := dbm.NewMemDB()
122
- ms := store.NewCommitMultiStore(db)
123
- ms.MountStoreWithDB(paramsTKey, storetypes.StoreTypeTransient, nil)
124
- ms.MountStoreWithDB(paramsStoreKey, storetypes.StoreTypeIAVL, db)
125
- ms.MountStoreWithDB(authStoreKey, storetypes.StoreTypeIAVL, db)
126
- ms.MountStoreWithDB(bankStoreKey, storetypes.StoreTypeIAVL, db)
127
- ms.MountStoreWithDB(stakingStoreKey, storetypes.StoreTypeIAVL, db)
128
- ms.MountStoreWithDB(lienStoreKey, storetypes.StoreTypeIAVL, db)
129
- err := ms.LoadLatestVersion()
130
- if err != nil {
131
- panic(err)
132
- }
133
- ctx := sdk.NewContext(ms, tmproto.Header{}, false, log.NewNopLogger())
134
-
135
- wak.SetParams(ctx, authtypes.DefaultParams())
136
- bk.SetParams(ctx, banktypes.DefaultParams())
137
- stakingParams := stakingtypes.DefaultParams()
138
- stakingParams.BondDenom = "ubld"
139
- sk.SetParams(ctx, stakingParams)
140
- wak.SetModuleAccount(ctx, minterAcc)
141
-
142
- return testKit{ctx, wak, bk, sk, keeper}
143
- }
144
-
145
- func (tk testKit) initAccount(t *testing.T, funder, addr sdk.AccAddress, state types.AccountState) {
146
- // Locked
147
- if !state.Locked.IsZero() {
148
- if err := tk.bankKeeper.MintCoins(tk.ctx, authtypes.Minter, state.Locked); err != nil {
149
- t.Fatalf("cannot mint coins: %v", err)
150
- }
151
- if err := tk.bankKeeper.SendCoinsFromModuleToAccount(tk.ctx, authtypes.Minter, funder, state.Locked); err != nil {
152
- t.Fatalf("cannot send coins: %v", err)
153
- }
154
- vestingMsgServer := vesting.NewMsgServerImpl(tk.accountKeeper, tk.bankKeeper, tk.stakingKeeper)
155
- _, err := vestingMsgServer.CreateVestingAccount(sdk.WrapSDKContext(tk.ctx), &vestingtypes.MsgCreateVestingAccount{
156
- FromAddress: funder.String(),
157
- ToAddress: addr.String(),
158
- Amount: state.Locked,
159
- EndTime: math.MaxInt64,
160
- Delayed: true,
161
- })
162
- if err != nil {
163
- t.Fatalf("cannot create vesting account: %v", err)
164
- }
165
- }
166
-
167
- // Total
168
- toMint := state.Total.Sub(state.Locked...)
169
- if !toMint.IsZero() {
170
- err := tk.bankKeeper.MintCoins(tk.ctx, authtypes.Minter, toMint)
171
- if err != nil {
172
- t.Fatalf("cannot mint coins: %v", err)
173
- }
174
- err = tk.bankKeeper.SendCoinsFromModuleToAccount(tk.ctx, authtypes.Minter, addr, toMint)
175
- if err != nil {
176
- t.Fatalf("cannot send coins: %v", err)
177
- }
178
- }
179
-
180
- // Bonded
181
- bondDenom := tk.stakingKeeper.BondDenom(tk.ctx)
182
- initialStaking := state.Bonded.Add(state.Unbonding...).AmountOf(bondDenom)
183
- if !initialStaking.IsZero() {
184
- pubKey := valPriv1.PubKey()
185
- vaddr := sdk.ValAddress(pubKey.Address().Bytes())
186
- validator, err := stakingtypes.NewValidator(vaddr, pubKey, stakingtypes.Description{})
187
- if err != nil {
188
- t.Fatalf("cannot create validator: %v", err)
189
- }
190
- validator, _ = validator.AddTokensFromDel(sdk.NewInt(100))
191
- validator = stakingkeeper.TestingUpdateValidator(tk.stakingKeeper, tk.ctx, validator, true)
192
-
193
- shares, err := tk.stakingKeeper.Delegate(tk.ctx, addr, initialStaking, stakingtypes.Unbonded, validator, true)
194
- if err != nil {
195
- t.Fatalf("cannot delegate: %v", err)
196
- }
197
-
198
- // Unbonding
199
- unbondShares := shares.MulInt(state.Unbonding.AmountOf(bondDenom)).QuoInt(initialStaking)
200
- if !unbondShares.IsZero() {
201
- _, err = tk.stakingKeeper.Undelegate(tk.ctx, addr, vaddr, unbondShares)
202
- if err != nil {
203
- t.Fatalf("cannot undelegate: %v", err)
204
- }
205
- }
206
- }
207
-
208
- // Liened
209
- tk.lienKeeper.SetLien(tk.ctx, addr, types.Lien{Coins: state.Liened})
210
- }
211
-
212
- func TestGetSetLien(t *testing.T) {
213
- ctx, _, _, _, keeper := makeTestKit().expand()
214
-
215
- // Empty
216
- l1 := keeper.GetLien(ctx, addr1)
217
- if !l1.GetCoins().IsZero() {
218
- t.Errorf("empty lien has %v, want empty", l1)
219
- }
220
-
221
- // Initialize
222
- amt := ubld(123)
223
- lien := types.Lien{Coins: amt}
224
- keeper.SetLien(ctx, addr1, lien)
225
- l2 := keeper.GetLien(ctx, addr1)
226
- if !l2.Coins.IsEqual(amt) {
227
- t.Errorf("initial lien has %v, want %s", l2, amt)
228
- }
229
-
230
- // Delete
231
- keeper.SetLien(ctx, addr1, types.Lien{})
232
- l3 := keeper.GetLien(ctx, addr1)
233
- if !l3.Coins.IsZero() {
234
- t.Errorf("zeroed lien has %v, want empty", l3)
235
- }
236
- }
237
-
238
- func TestIterateLiens(t *testing.T) {
239
- ctx, _, _, _, keeper := makeTestKit().expand()
240
-
241
- var liens map[string]types.Lien
242
- cb := func(a sdk.AccAddress, l types.Lien) bool {
243
- liens[a.String()] = l
244
- return false
245
- }
246
- reset := func() {
247
- liens = make(map[string]types.Lien)
248
- }
249
-
250
- // Empty
251
- reset()
252
- keeper.IterateLiens(ctx, cb)
253
- if len(liens) > 0 {
254
- t.Errorf("empty lien store has %v", liens)
255
- }
256
-
257
- // One
258
- reset()
259
- amt1 := ubld(123)
260
- keeper.SetLien(ctx, addr1, types.Lien{Coins: amt1})
261
- keeper.IterateLiens(ctx, cb)
262
- wantLiens := map[string]types.Lien{
263
- addr1.String(): {Coins: amt1},
264
- }
265
- if !reflect.DeepEqual(liens, wantLiens) {
266
- t.Errorf("singleton lien store has liens %v, want %v", liens, wantLiens)
267
- }
268
-
269
- // Several (including zero)
270
- reset()
271
- amt2 := ubld(456)
272
- keeper.SetLien(ctx, addr2, types.Lien{Coins: amt2})
273
- keeper.SetLien(ctx, addr3, types.Lien{})
274
- keeper.IterateLiens(ctx, cb)
275
- wantLiens[addr2.String()] = types.Lien{Coins: amt2}
276
- if !reflect.DeepEqual(liens, wantLiens) {
277
- t.Errorf("multiple lien store has liens %v, want %v", liens, wantLiens)
278
- }
279
-
280
- // Early termination
281
- reset()
282
- keeper.IterateLiens(ctx, func(a sdk.AccAddress, l types.Lien) bool {
283
- liens[a.String()] = l
284
- return true
285
- })
286
- // map iteration is non-deterministic, so just check number of results
287
- if len(liens) != 1 {
288
- t.Errorf("early termination has liens %v, want just one", liens)
289
- }
290
- }
291
-
292
- func TestAccountState(t *testing.T) {
293
- ctx, _, bk, sk, keeper := makeTestKit().expand()
294
-
295
- // empty
296
- state := keeper.GetAccountState(ctx, addr1)
297
- wantState := types.AccountState{}
298
- if !state.IsEqual(wantState) {
299
- t.Errorf("GetAccountState() of empty got %v, want %v", state, wantState)
300
- }
301
-
302
- // lien only
303
- amt1 := ubld(123)
304
- keeper.SetLien(ctx, addr1, types.Lien{Coins: amt1})
305
- state = keeper.GetAccountState(ctx, addr1)
306
- wantState = types.AccountState{Liened: amt1}
307
- if !state.IsEqual(wantState) {
308
- t.Errorf("GetAccountState() of lien only got %v, want %v", state, wantState)
309
- }
310
-
311
- // total and lien
312
- amt2 := sdk.NewCoins(sdk.NewInt64Coin("ubld", 1000), sdk.NewInt64Coin("urun", 5000), sdk.NewInt64Coin("moola", 22))
313
- err := bk.MintCoins(ctx, authtypes.Minter, amt2)
314
- if err != nil {
315
- t.Fatalf("cannot mint coins: %v", err)
316
- }
317
- err = bk.SendCoinsFromModuleToAccount(ctx, authtypes.Minter, addr1, amt2)
318
- if err != nil {
319
- t.Fatalf("cannot send coins: %v", err)
320
- }
321
- state = keeper.GetAccountState(ctx, addr1)
322
- wantState = types.AccountState{
323
- Total: amt2,
324
- Liened: amt1,
325
- }
326
- if !state.IsEqual(wantState) {
327
- t.Errorf("GetAccountState() ver 3 got %v, want %v", state, wantState)
328
- }
329
-
330
- // bonded
331
- pubKey := valPriv1.PubKey()
332
- vaddr := sdk.ValAddress(pubKey.Address().Bytes())
333
- validator, err := stakingtypes.NewValidator(vaddr, pubKey, stakingtypes.Description{})
334
- if err != nil {
335
- t.Fatalf("cannot create validator: %v", err)
336
- }
337
- validator, _ = validator.AddTokensFromDel(sdk.NewInt(100))
338
- validator = stakingkeeper.TestingUpdateValidator(sk, ctx, validator, true)
339
-
340
- shares, err := sk.Delegate(ctx, addr1, sdk.NewInt(10), stakingtypes.Unbonded, validator, true)
341
- if err != nil {
342
- t.Fatalf("cannot delegate: %v", err)
343
- }
344
-
345
- state = keeper.GetAccountState(ctx, addr1)
346
- wantState = types.AccountState{
347
- Total: amt2,
348
- Bonded: ubld(10),
349
- Liened: amt1,
350
- }
351
- if !state.IsEqual(wantState) {
352
- t.Errorf("GetAccountState() ver 4 got %v, want %v", state, wantState)
353
- }
354
-
355
- // unbonding
356
- _, err = sk.Undelegate(ctx, addr1, vaddr, shares.QuoInt(sdk.NewInt(10)))
357
- if err != nil {
358
- t.Fatalf("cannot undelegate: %v", err)
359
- }
360
-
361
- state = keeper.GetAccountState(ctx, addr1)
362
- wantState = types.AccountState{
363
- Total: amt2,
364
- Bonded: ubld(9),
365
- Unbonding: ubld(1),
366
- Liened: amt1,
367
- }
368
- if !state.IsEqual(wantState) {
369
- t.Errorf("GetAccountState() ver 5 got %v, want %v", state, wantState)
370
- }
371
- }
372
-
373
- func TestVesting(t *testing.T) {
374
- ctx, ak, bk, sk, keeper := makeTestKit().expand()
375
-
376
- amt := ubld(1000)
377
- err := bk.MintCoins(ctx, authtypes.Minter, amt)
378
- if err != nil {
379
- t.Fatalf("cannot mint coins: %v", err)
380
- }
381
- err = bk.SendCoinsFromModuleToAccount(ctx, authtypes.Minter, addr1, amt)
382
- if err != nil {
383
- t.Fatalf("cannot send coins: %v", err)
384
- }
385
-
386
- vestingMsgServer := vesting.NewMsgServerImpl(ak, bk, sk)
387
- _, err = vestingMsgServer.CreateVestingAccount(sdk.WrapSDKContext(ctx), &vestingtypes.MsgCreateVestingAccount{
388
- FromAddress: addr1.String(),
389
- ToAddress: addr2.String(),
390
- Amount: amt,
391
- EndTime: math.MaxInt64,
392
- Delayed: true,
393
- })
394
- if err != nil {
395
- t.Fatalf("cannot create vesting account: %v", err)
396
- }
397
-
398
- state := keeper.GetAccountState(ctx, addr2)
399
- wantState := types.AccountState{
400
- Total: amt,
401
- Locked: amt,
402
- }
403
- if !state.IsEqual(wantState) {
404
- t.Errorf("GetAccountState(1) got %v, want %v", state, wantState)
405
- }
406
-
407
- err = bk.SendCoins(ctx, addr2, addr1, ubld(5))
408
- if err == nil {
409
- t.Fatalf("transferred coins out of fully locked account!")
410
- }
411
-
412
- amt2 := ubld(300)
413
- err = bk.MintCoins(ctx, authtypes.Minter, amt2)
414
- if err != nil {
415
- t.Fatalf("cannot mint more coins: %v", err)
416
- }
417
- err = bk.SendCoinsFromModuleToAccount(ctx, authtypes.Minter, addr2, amt2)
418
- if err != nil {
419
- t.Fatalf("cannot transfer to vesting account: %v", err)
420
- }
421
- state = keeper.GetAccountState(ctx, addr2)
422
- wantState = types.AccountState{
423
- Total: ubld(1300),
424
- Locked: ubld(1000),
425
- }
426
- if !state.IsEqual(wantState) {
427
- t.Errorf("GetAccountState(2) got %v, want %v", state, wantState)
428
- }
429
- err = bk.SendCoins(ctx, addr2, addr2, ubld(5))
430
- if err != nil {
431
- t.Errorf("cannot transfer free coins(1): %v", err)
432
- }
433
-
434
- keeper.SetLien(ctx, addr2, types.Lien{Coins: ubld(1200)})
435
- err = bk.SendCoins(ctx, addr2, addr1, ubld(95))
436
- if err != nil {
437
- t.Errorf("cannot transfer free coins(2): %v", err)
438
- }
439
- err = bk.SendCoins(ctx, addr2, addr1, ubld(7))
440
- if err == nil {
441
- t.Errorf("transferred liened coins!")
442
- }
443
-
444
- keeper.SetLien(ctx, addr2, types.Lien{Coins: ubld(3000)}) // deep underwater
445
- err = bk.SendCoins(ctx, addr2, addr1, ubld(7))
446
- if err == nil {
447
- t.Errorf("transferred liened coins!")
448
- }
449
- }
450
-
451
- func TestChangeLien(t *testing.T) {
452
- for _, tt := range []struct {
453
- name string
454
- state types.AccountState
455
- newLien int64
456
- wantFail bool
457
- }{
458
- {
459
- name: "empty zero",
460
- state: emptyState,
461
- newLien: 0,
462
- },
463
- {
464
- name: "empty some",
465
- state: emptyState,
466
- newLien: 123,
467
- wantFail: true,
468
- },
469
- {
470
- name: "same",
471
- state: types.AccountState{
472
- Total: ubld(15),
473
- Bonded: ubld(1),
474
- Unbonding: ubld(2),
475
- Locked: ubld(4),
476
- Liened: ubld(8),
477
- },
478
- newLien: 8,
479
- },
480
- {
481
- name: "reduce",
482
- state: types.AccountState{
483
- Total: ubld(15),
484
- Bonded: ubld(1),
485
- Unbonding: ubld(2),
486
- Locked: ubld(4),
487
- Liened: ubld(8),
488
- },
489
- newLien: 7,
490
- },
491
- {
492
- name: "insufficient bonded",
493
- state: types.AccountState{
494
- Total: ubld(15),
495
- Bonded: ubld(1),
496
- Unbonding: ubld(2),
497
- Locked: ubld(4),
498
- Liened: ubld(8),
499
- },
500
- newLien: 9,
501
- wantFail: true,
502
- },
503
- {
504
- name: "unbonding not good enough",
505
- state: types.AccountState{
506
- Total: ubld(15),
507
- Bonded: ubld(0),
508
- Unbonding: ubld(15),
509
- Locked: ubld(0),
510
- Liened: ubld(8),
511
- },
512
- newLien: 9,
513
- wantFail: true,
514
- },
515
- {
516
- name: "locked ok",
517
- state: types.AccountState{
518
- Total: ubld(15),
519
- Bonded: ubld(15),
520
- Unbonding: ubld(0),
521
- Locked: ubld(15),
522
- Liened: ubld(0),
523
- },
524
- newLien: 1,
525
- },
526
- } {
527
- t.Run(tt.name, func(t *testing.T) {
528
- tk := makeTestKit()
529
- ctx, _, _, sk, lk := tk.expand()
530
- tk.initAccount(t, addr1, addr2, tt.state)
531
- gotState := lk.GetAccountState(ctx, addr2)
532
- if !gotState.IsEqual(tt.state) {
533
- t.Fatalf("account state want %+v, got %+v", tt.state, gotState)
534
- }
535
- bondDenom := sk.BondDenom(ctx)
536
- delta := tt.newLien - tt.state.Liened.AmountOf(bondDenom).Int64()
537
- gotInt, err := lk.ChangeLien(ctx, addr2, bondDenom, sdk.NewInt(delta))
538
- if err != nil {
539
- if !tt.wantFail {
540
- t.Errorf("Update lien failed: %v", err)
541
- }
542
- } else if tt.wantFail {
543
- t.Errorf("Update lien succeeded, but wanted failure")
544
- } else {
545
- if !gotInt.Equal(sdk.NewInt(tt.newLien)) {
546
- t.Errorf("want new lien balance %s, got %d", gotInt, tt.newLien)
547
- }
548
- }
549
-
550
- })
551
- }
552
- }
553
-
554
- func TestWrap(t *testing.T) {
555
- tk := makeTestKit()
556
- ctx, wak, _, _, keeper := tk.expand()
557
- outerAk := wak.(*types.WrappedAccountKeeper)
558
- innerAk := outerAk.AccountKeeper
559
-
560
- tk.initAccount(t, addr1, addr2, types.AccountState{Total: ubld(33)})
561
- acc := innerAk.GetAccount(ctx, addr2)
562
- err := acc.SetAccountNumber(8)
563
- if err != nil {
564
- t.Error(err.Error())
565
- }
566
-
567
- wrapper := NewAccountWrapper(keeper)
568
- wrapped := wrapper.Wrap(ctx, acc)
569
- if wrapped != acc {
570
- t.Fatalf("wrapper changed lien-less account from %v to %v", acc, wrapped)
571
- }
572
-
573
- tk.initAccount(t, addr1, addr3, types.AccountState{Total: ubld(10), Liened: ubld(8)})
574
- acc = innerAk.GetAccount(ctx, addr3)
575
- err = acc.SetAccountNumber(17)
576
- if err != nil {
577
- t.Error(err.Error())
578
- }
579
-
580
- wrapped = wrapper.Wrap(ctx, acc)
581
- lienAcc, ok := wrapped.(*LienAccount)
582
- if !ok {
583
- t.Fatalf("wrapper did not create a lien account: %+v", wrapped)
584
- }
585
-
586
- if lienAcc.lienKeeper.(keeperImpl).accountKeeper != wak {
587
- t.Errorf("wrong lien keeper %+v, want %+v", lienAcc.lienKeeper, keeper)
588
- }
589
- unwrapped := wrapper.Unwrap(ctx, lienAcc)
590
- baseAccount, ok := unwrapped.(*authtypes.BaseAccount)
591
- if !ok {
592
- t.Fatalf("unwrapper did not produce a base account: %+v", unwrapped)
593
- }
594
- if baseAccount.AccountNumber != 17 {
595
- t.Errorf("wrong account number %d, want 17", baseAccount.AccountNumber)
596
- }
597
- unwrap2 := wrapper.Unwrap(ctx, baseAccount)
598
- _, ok = unwrap2.(*authtypes.BaseAccount)
599
- if !ok {
600
- t.Errorf("unwrapping unwrapped account gives %+v, want base account", unwrap2)
601
- }
602
- if unwrap2.GetAccountNumber() != 17 {
603
- t.Errorf("doubly unwrapped account has wrong account number %d, want 17", unwrap2.GetAccountNumber())
604
- }
605
- wrapped2 := wrapper.Wrap(ctx, nil)
606
- if wrapped2 != nil {
607
- t.Errorf("wrapped nil is %v, want nil", wrapped2)
608
- }
609
-
610
- modAcc := authtypes.NewEmptyModuleAccount("modname")
611
- wrapped = wrapper.Wrap(ctx, modAcc)
612
- _, ok = wrapped.(*LienAccount)
613
- if ok {
614
- t.Fatalf("should not wrap module accounts")
615
- }
616
- modAcc2, ok := wrapped.(*authtypes.ModuleAccount)
617
- if !ok {
618
- t.Fatalf("wrapped module account should be a module account")
619
- }
620
- if !reflect.DeepEqual(modAcc, modAcc2) {
621
- t.Errorf("wrapped module account should not change")
622
- }
623
- }