@agoric/cosmos 0.35.0-u21.0 → 0.35.0-u22.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.
- package/CHANGELOG.md +11 -187
- package/Makefile +2 -2
- package/ante/ante.go +2 -2
- package/ante/inbound.go +1 -2
- package/ante/inbound_test.go +3 -1
- package/ante/vm_admission.go +1 -2
- package/app/app.go +255 -174
- package/app/encoding.go +6 -3
- package/app/export.go +50 -21
- package/app/genesis.go +7 -5
- package/app/params/encoding.go +1 -1
- package/app/params/proto.go +6 -4
- package/app/sim_test.go +11 -13
- package/app/txconfig/tx_config.go +169 -0
- package/app/upgrade.go +52 -97
- package/app/upgrade_test.go +1 -1
- package/cmd/agd/agvm.go +1 -1
- package/cmd/agd/main.go +1 -1
- package/cmd/libdaemon/main.go +2 -2
- package/daemon/cmd/root.go +99 -30
- package/daemon/cmd/root_test.go +12 -27
- package/daemon/main.go +2 -9
- package/git-revision.txt +1 -1
- package/go.mod +129 -109
- package/go.sum +228 -469
- package/package.json +2 -2
- package/proto/agoric/swingset/msgs.proto +46 -9
- package/proto/agoric/swingset/swingset.proto +7 -2
- package/proto/agoric/vbank/vbank.proto +1 -1
- package/proto/agoric/vibc/msgs.proto +4 -0
- package/tests/e2e/vbank/vbank_test.go +172 -0
- package/tests/integrations/types/aminojson_test.go +214 -0
- package/tests/integrations/vbank/vbank_test.go +348 -0
- package/third_party/proto/amino/amino.proto +6 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +18 -5
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +4 -8
- package/third_party/proto/ibc/core/channel/v1/channel.proto +42 -17
- package/third_party/proto/ibc/core/client/v1/client.proto +48 -40
- package/types/address_hooks.go +2 -2
- package/types/address_hooks_test.go +3 -3
- package/types/ibc_packet.go +3 -3
- package/types/ibc_packet_test.go +3 -3
- package/types/kv_entry_helpers.go +3 -3
- package/types/kv_entry_helpers_test.go +2 -2
- package/types/legacy_address_encoder.go +58 -0
- package/vm/proto_json_test.go +1 -1
- package/vm/server.go +2 -1
- package/x/swingset/abci.go +2 -2
- package/x/swingset/client/cli/tx.go +16 -14
- package/x/swingset/config.go +1 -1
- package/x/swingset/genesis.go +2 -1
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +14 -5
- package/x/swingset/keeper/extension_snapshotter_test.go +1 -1
- package/x/swingset/keeper/keeper.go +21 -17
- package/x/swingset/keeper/keeper_test.go +10 -7
- package/x/swingset/keeper/msg_server.go +26 -5
- package/x/swingset/keeper/swing_store_exports_handler.go +1 -1
- package/x/swingset/keeper/swing_store_exports_handler_test.go +1 -1
- package/x/swingset/module.go +20 -22
- package/x/swingset/types/codec.go +10 -5
- package/x/swingset/types/default-params.go +13 -12
- package/x/swingset/types/expected_keepers.go +5 -4
- package/x/swingset/types/msgs.go +50 -36
- package/x/swingset/types/msgs.pb.go +60 -51
- package/x/swingset/types/params_test.go +21 -20
- package/x/swingset/types/swingset.pb.go +67 -61
- package/x/vbank/genesis.go +12 -8
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/grpc_query.go +4 -1
- package/x/vbank/keeper/keeper.go +108 -23
- package/x/vbank/keeper/querier.go +4 -1
- package/x/vbank/keeper/rewards.go +6 -2
- package/x/vbank/module.go +47 -75
- package/x/vbank/types/expected_keepers.go +15 -10
- package/x/vbank/types/key.go +3 -0
- package/x/vbank/types/params.go +4 -3
- package/x/vbank/types/vbank.pb.go +41 -40
- package/x/vbank/vbank.go +25 -10
- package/x/vbank/vbank_test.go +213 -154
- package/x/vibc/handler.go +2 -1
- package/x/vibc/keeper/keeper.go +10 -10
- package/x/vibc/keeper/migrations.go +1 -1
- package/x/vibc/keeper/triggers.go +1 -1
- package/x/vibc/module.go +5 -22
- package/x/vibc/types/codec.go +2 -1
- package/x/vibc/types/expected_keepers.go +7 -5
- package/x/vibc/types/ibc_module.go +5 -5
- package/x/vibc/types/msgs.go +30 -7
- package/x/vibc/types/msgs.pb.go +29 -25
- package/x/vibc/types/receiver.go +2 -2
- package/x/vlocalchain/handler.go +2 -1
- package/x/vlocalchain/keeper/keeper.go +17 -5
- package/x/vlocalchain/keeper/keeper_test.go +3 -2
- package/x/vlocalchain/types/expected_keepers.go +7 -4
- package/x/vlocalchain/vlocalchain_test.go +38 -26
- package/x/vstorage/genesis.go +10 -10
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/keeper.go +68 -46
- package/x/vstorage/keeper/keeper_test.go +35 -19
- package/x/vstorage/module.go +27 -13
- package/x/vstorage/testing/queue.go +5 -3
- package/x/vstorage/vstorage.go +2 -1
- package/x/vstorage/vstorage_test.go +21 -17
- package/x/vtransfer/genesis.go +1 -3
- package/x/vtransfer/handler.go +3 -2
- package/x/vtransfer/ibc_middleware.go +5 -5
- package/x/vtransfer/ibc_middleware_test.go +43 -29
- package/x/vtransfer/keeper/keeper.go +35 -33
- package/x/vtransfer/module.go +8 -11
- package/x/vtransfer/types/expected_keepers.go +3 -3
- package/x/vtransfer/utils_test.go +26 -11
- package/daemon/cmd/testnet.go +0 -539
package/x/vbank/vbank_test.go
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
package vbank
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"encoding/json"
|
|
5
6
|
"fmt"
|
|
6
7
|
"reflect"
|
|
7
|
-
"sort"
|
|
8
8
|
"testing"
|
|
9
9
|
|
|
10
|
+
"cosmossdk.io/core/address"
|
|
11
|
+
errorsmod "cosmossdk.io/errors"
|
|
12
|
+
"github.com/cosmos/cosmos-sdk/runtime"
|
|
13
|
+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
14
|
+
"github.com/stretchr/testify/require"
|
|
15
|
+
|
|
16
|
+
"cosmossdk.io/log"
|
|
17
|
+
sdkmath "cosmossdk.io/math"
|
|
18
|
+
"cosmossdk.io/store"
|
|
19
|
+
storemetrics "cosmossdk.io/store/metrics"
|
|
20
|
+
storetypes "cosmossdk.io/store/types"
|
|
10
21
|
"github.com/Agoric/agoric-sdk/golang/cosmos/app/params"
|
|
11
22
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
12
23
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank/types"
|
|
13
|
-
dbm "github.com/cometbft/cometbft-db"
|
|
14
|
-
abci "github.com/cometbft/cometbft/abci/types"
|
|
15
24
|
"github.com/cometbft/cometbft/crypto/secp256k1"
|
|
16
|
-
"github.com/cometbft/cometbft/libs/log"
|
|
17
25
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
18
|
-
"github.com/cosmos/cosmos-
|
|
19
|
-
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
26
|
+
dbm "github.com/cosmos/cosmos-db"
|
|
20
27
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
21
28
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
22
29
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
@@ -171,7 +178,11 @@ func Test_marshalBalanceUpdate(t *testing.T) {
|
|
|
171
178
|
}
|
|
172
179
|
for i, tt := range tests {
|
|
173
180
|
t.Run(tt.name, func(t *testing.T) {
|
|
174
|
-
|
|
181
|
+
balanceUpdate, err := getBalanceUpdate(ctx, keeper, tt.addressToBalance)
|
|
182
|
+
if err != nil {
|
|
183
|
+
t.Errorf("getBalanceUpdate() error = %v, wantErr %v", err, tt.wantErr)
|
|
184
|
+
}
|
|
185
|
+
encoded, err := marshal(balanceUpdate)
|
|
175
186
|
if (err != nil) != tt.wantErr {
|
|
176
187
|
t.Errorf("marshalBalanceUpdate() error = %v, wantErr %v", err, tt.wantErr)
|
|
177
188
|
return
|
|
@@ -204,12 +215,16 @@ func (b *mockBank) record(s string) {
|
|
|
204
215
|
b.calls = append(b.calls, s)
|
|
205
216
|
}
|
|
206
217
|
|
|
207
|
-
func (b *mockBank)
|
|
218
|
+
func (b *mockBank) AppendSendRestriction(restriction banktypes.SendRestrictionFn) {
|
|
219
|
+
b.record("AppendSendRestriction")
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
func (b *mockBank) BurnCoins(_ context.Context, moduleName string, amt sdk.Coins) error {
|
|
208
223
|
b.record(fmt.Sprintf("BurnCoins %s %v", moduleName, amt))
|
|
209
224
|
return nil
|
|
210
225
|
}
|
|
211
226
|
|
|
212
|
-
func (b *mockBank) GetAllBalances(
|
|
227
|
+
func (b *mockBank) GetAllBalances(_ context.Context, addr sdk.AccAddress) sdk.Coins {
|
|
213
228
|
b.record(fmt.Sprintf("GetAllBalances %s", addr))
|
|
214
229
|
balances, ok := b.balances[addr.String()]
|
|
215
230
|
if !ok {
|
|
@@ -218,21 +233,21 @@ func (b *mockBank) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coin
|
|
|
218
233
|
return balances
|
|
219
234
|
}
|
|
220
235
|
|
|
221
|
-
func (b *mockBank) GetBalance(
|
|
236
|
+
func (b *mockBank) GetBalance(_ context.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
|
222
237
|
b.record(fmt.Sprintf("GetBalance %s %s", addr, denom))
|
|
223
|
-
amount :=
|
|
238
|
+
amount := sdkmath.ZeroInt()
|
|
224
239
|
if balances, ok := b.balances[addr.String()]; ok {
|
|
225
240
|
amount = balances.AmountOf(denom)
|
|
226
241
|
}
|
|
227
242
|
return sdk.NewCoin(denom, amount)
|
|
228
243
|
}
|
|
229
244
|
|
|
230
|
-
func (b *mockBank) MintCoins(
|
|
245
|
+
func (b *mockBank) MintCoins(_ context.Context, moduleName string, amt sdk.Coins) error {
|
|
231
246
|
b.record(fmt.Sprintf("MintCoins %s %s", moduleName, amt))
|
|
232
247
|
return nil
|
|
233
248
|
}
|
|
234
249
|
|
|
235
|
-
func (b *mockBank) SendCoinsFromAccountToModule(
|
|
250
|
+
func (b *mockBank) SendCoinsFromAccountToModule(_ context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
|
|
236
251
|
b.record(fmt.Sprintf("SendCoinsFromAccountToModule %s %s %s", senderAddr, recipientModule, amt))
|
|
237
252
|
|
|
238
253
|
// for each coin in the request, check spendable vs. requested
|
|
@@ -244,7 +259,7 @@ func (b *mockBank) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.
|
|
|
244
259
|
if spendable.IsLT(coin) {
|
|
245
260
|
// wrap exactly like the real x/bank keeper
|
|
246
261
|
// https://github.com/agoric-labs/cosmos-sdk/blob/8b2b975304291c51991278734daa2ff5e57fcb83/x/bank/keeper/send.go#L252-L256
|
|
247
|
-
return
|
|
262
|
+
return errorsmod.Wrapf(
|
|
248
263
|
sdkerrors.ErrInsufficientFunds,
|
|
249
264
|
"spendable balance %s is smaller than %s",
|
|
250
265
|
spendable, coin,
|
|
@@ -255,12 +270,12 @@ func (b *mockBank) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.
|
|
|
255
270
|
return nil
|
|
256
271
|
}
|
|
257
272
|
|
|
258
|
-
func (b *mockBank) SendCoinsFromModuleToAccount(
|
|
273
|
+
func (b *mockBank) SendCoinsFromModuleToAccount(_ context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
|
259
274
|
b.record(fmt.Sprintf("SendCoinsFromModuleToAccount %s %s %s", senderModule, recipientAddr, amt))
|
|
260
275
|
return nil
|
|
261
276
|
}
|
|
262
277
|
|
|
263
|
-
func (b *mockBank) SendCoinsFromModuleToModule(
|
|
278
|
+
func (b *mockBank) SendCoinsFromModuleToModule(_ context.Context, senderModule, recipientModule string, amt sdk.Coins) error {
|
|
264
279
|
b.record(fmt.Sprintf("SendCoinsFromModuleToModule %s %s %s", senderModule, recipientModule, amt))
|
|
265
280
|
return nil
|
|
266
281
|
}
|
|
@@ -268,20 +283,36 @@ func (b *mockBank) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, re
|
|
|
268
283
|
// makeTestKit creates a minimal Keeper and Context for use in testing.
|
|
269
284
|
func makeTestKit(account types.AccountKeeper, bank types.BankKeeper) (Keeper, sdk.Context) {
|
|
270
285
|
encodingConfig := params.MakeEncodingConfig()
|
|
271
|
-
cdc := encodingConfig.
|
|
286
|
+
cdc := encodingConfig.Codec
|
|
272
287
|
pushAction := func(ctx sdk.Context, action vm.Action) error {
|
|
273
288
|
return nil
|
|
274
289
|
}
|
|
275
290
|
|
|
276
|
-
|
|
277
|
-
|
|
291
|
+
// Provide default mock implementations if nil is passed
|
|
292
|
+
if account == nil {
|
|
293
|
+
account = &mockAuthKeeper{
|
|
294
|
+
accounts: make(map[string]authtypes.AccountI),
|
|
295
|
+
modAddrs: make(map[string]string),
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if bank == nil {
|
|
299
|
+
bank = &mockBank{
|
|
300
|
+
balances: make(map[string]sdk.Coins),
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
paramsTStoreKey := storetypes.NewTransientStoreKey(paramstypes.TStoreKey)
|
|
305
|
+
paramsStoreKey := storetypes.NewKVStoreKey(paramstypes.StoreKey)
|
|
278
306
|
pk := paramskeeper.NewKeeper(cdc, encodingConfig.Amino, paramsStoreKey, paramsTStoreKey)
|
|
279
307
|
|
|
280
308
|
subspace := pk.Subspace(types.ModuleName)
|
|
281
|
-
|
|
309
|
+
vbankStore := runtime.NewKVStoreService(vbankStoreKey)
|
|
310
|
+
transientStore := runtime.NewTransientStoreService(paramsTStoreKey)
|
|
311
|
+
keeper := NewKeeper(cdc, vbankStore, transientStore, subspace, account, bank, "feeCollectorName", pushAction)
|
|
282
312
|
|
|
283
313
|
db := dbm.NewMemDB()
|
|
284
|
-
|
|
314
|
+
logger := log.NewNopLogger()
|
|
315
|
+
ms := store.NewCommitMultiStore(db, logger, storemetrics.NewNoOpMetrics())
|
|
285
316
|
ms.MountStoreWithDB(vbankStoreKey, storetypes.StoreTypeIAVL, db)
|
|
286
317
|
ms.MountStoreWithDB(paramsStoreKey, storetypes.StoreTypeIAVL, db)
|
|
287
318
|
ms.MountStoreWithDB(paramsTStoreKey, storetypes.StoreTypeTransient, db)
|
|
@@ -318,11 +349,14 @@ func Test_Receive_GetBalance(t *testing.T) {
|
|
|
318
349
|
t.Errorf("got %v, want %s", ret, want)
|
|
319
350
|
}
|
|
320
351
|
wantCalls := []string{
|
|
352
|
+
"AppendSendRestriction",
|
|
321
353
|
"GetBalance " + addr1 + " quatloos",
|
|
322
354
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
355
|
+
|
|
356
|
+
//if !reflect.DeepEqual(bank.calls, wantCalls) {
|
|
357
|
+
require.Equal(t, wantCalls, bank.calls)
|
|
358
|
+
//t.Errorf("got calls %v, want {%s}", bank.calls, wantCalls)
|
|
359
|
+
//}
|
|
326
360
|
}
|
|
327
361
|
|
|
328
362
|
func Test_Receive_Give(t *testing.T) {
|
|
@@ -355,6 +389,7 @@ func Test_Receive_Give(t *testing.T) {
|
|
|
355
389
|
t.Errorf("got nonce %+v, want %+v", gotNonce, nonce)
|
|
356
390
|
}
|
|
357
391
|
wantCalls := []string{
|
|
392
|
+
"AppendSendRestriction",
|
|
358
393
|
"MintCoins vbank 1000urun",
|
|
359
394
|
"SendCoinsFromModuleToAccount vbank " + addr1 + " 1000urun",
|
|
360
395
|
"GetBalance " + addr1 + " urun",
|
|
@@ -435,7 +470,7 @@ func Test_Receive_GiveToRewardDistributor(t *testing.T) {
|
|
|
435
470
|
feeDenom: "yoctoquatloos",
|
|
436
471
|
wantMintCoins: "123456789123456789123456789yoctoquatloos",
|
|
437
472
|
wantRate: sdk.NewCoins(
|
|
438
|
-
sdk.NewCoin("yoctoquatloos",
|
|
473
|
+
sdk.NewCoin("yoctoquatloos", sdkmath.NewInt(123456789123456789).MulRaw(1000).AddRaw(124)),
|
|
439
474
|
),
|
|
440
475
|
},
|
|
441
476
|
{
|
|
@@ -446,7 +481,7 @@ func Test_Receive_GiveToRewardDistributor(t *testing.T) {
|
|
|
446
481
|
feeDenom: "yoctoquatloos",
|
|
447
482
|
wantMintCoins: "123456789123456789123456789yoctoquatloos",
|
|
448
483
|
wantRate: sdk.NewCoins(
|
|
449
|
-
sdk.NewCoin("yoctoquatloos",
|
|
484
|
+
sdk.NewCoin("yoctoquatloos", sdkmath.NewInt(123456789123456789).MulRaw(1000).AddRaw(124)),
|
|
450
485
|
),
|
|
451
486
|
},
|
|
452
487
|
}
|
|
@@ -480,8 +515,11 @@ func Test_Receive_GiveToRewardDistributor(t *testing.T) {
|
|
|
480
515
|
if err := keeper.DistributeRewards(ctx); err != nil {
|
|
481
516
|
t.Errorf("got error = %v", err)
|
|
482
517
|
}
|
|
483
|
-
state := keeper.GetState(ctx)
|
|
484
|
-
if
|
|
518
|
+
state, err := keeper.GetState(ctx)
|
|
519
|
+
if err != nil {
|
|
520
|
+
t.Errorf("got error = %v", err)
|
|
521
|
+
}
|
|
522
|
+
if !state.RewardBlockAmount.Equal(tt.wantRate) {
|
|
485
523
|
t.Errorf("got rate %v, want %v", state.RewardBlockAmount, tt.wantRate)
|
|
486
524
|
}
|
|
487
525
|
})
|
|
@@ -518,6 +556,7 @@ func Test_Receive_Grab(t *testing.T) {
|
|
|
518
556
|
t.Errorf("invalid nonce = %+v, want %+v", gotNonce, nonce)
|
|
519
557
|
}
|
|
520
558
|
wantCalls := []string{
|
|
559
|
+
"AppendSendRestriction",
|
|
521
560
|
"SendCoinsFromAccountToModule " + addr1 + " vbank 500ubld",
|
|
522
561
|
"BurnCoins vbank 500ubld",
|
|
523
562
|
"GetBalance " + addr1 + " ubld",
|
|
@@ -527,116 +566,122 @@ func Test_Receive_Grab(t *testing.T) {
|
|
|
527
566
|
}
|
|
528
567
|
}
|
|
529
568
|
|
|
530
|
-
func Test_EndBlock_Events(t *testing.T) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
},
|
|
566
|
-
},
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
},
|
|
574
|
-
},
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
},
|
|
582
|
-
},
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
},
|
|
590
|
-
},
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
569
|
+
// func Test_EndBlock_Events(t *testing.T) {
|
|
570
|
+
// bank := &mockBank{balances: map[string]sdk.Coins{
|
|
571
|
+
// addr1: sdk.NewCoins(sdk.NewInt64Coin("ubld", 1000)),
|
|
572
|
+
// addr2: sdk.NewCoins(
|
|
573
|
+
// sdk.NewInt64Coin("urun", 4000),
|
|
574
|
+
// sdk.NewInt64Coin("arcadeTokens", 7),
|
|
575
|
+
// ),
|
|
576
|
+
// }}
|
|
577
|
+
// acct := &mockAuthKeeper{
|
|
578
|
+
// accounts: map[string]authtypes.AccountI{
|
|
579
|
+
// addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr1}},
|
|
580
|
+
// addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr2}},
|
|
581
|
+
// addr3: &authtypes.BaseAccount{Address: addr3},
|
|
582
|
+
// },
|
|
583
|
+
// }
|
|
584
|
+
// keeper, ctx := makeTestKit(acct, bank)
|
|
585
|
+
// // Turn off rewards.
|
|
586
|
+
// keeper.SetParams(ctx, types.Params{PerEpochRewardFraction: sdkmath.LegacyZeroDec(), AllowedMonitoringAccounts: []string{"*"}})
|
|
587
|
+
// msgsSent := []string{}
|
|
588
|
+
// keeper.PushAction = func(ctx sdk.Context, action vm.Action) error {
|
|
589
|
+
// fmt.Println("PushAction!!!!!")
|
|
590
|
+
// bz, err := json.Marshal(action)
|
|
591
|
+
// if err != nil {
|
|
592
|
+
// return err
|
|
593
|
+
// }
|
|
594
|
+
// msgsSent = append(msgsSent, string(bz))
|
|
595
|
+
// return nil
|
|
596
|
+
// }
|
|
597
|
+
// am := NewAppModule(keeper)
|
|
598
|
+
|
|
599
|
+
// //events := []abci.Event{
|
|
600
|
+
// // {
|
|
601
|
+
// // Type: "coin_received",
|
|
602
|
+
// // Attributes: []abci.EventAttribute{
|
|
603
|
+
// // {Key: "receiver", Value: addr1},
|
|
604
|
+
// // {Key: "amount", Value: "500ubld,600urun,700ushmoo"},
|
|
605
|
+
// // },
|
|
606
|
+
// // },
|
|
607
|
+
// // {
|
|
608
|
+
// // Type: "coin_spent",
|
|
609
|
+
// // Attributes: []abci.EventAttribute{
|
|
610
|
+
// // {Key: "spender", Value: addr2},
|
|
611
|
+
// // {Key: "amount", Value: "500ubld,600urun,700ushmoo"},
|
|
612
|
+
// // {Key: "other", Value: addr3},
|
|
613
|
+
// // },
|
|
614
|
+
// // },
|
|
615
|
+
// // {
|
|
616
|
+
// // Type: "something_else",
|
|
617
|
+
// // Attributes: []abci.EventAttribute{
|
|
618
|
+
// // {Key: "receiver", Value: addr4},
|
|
619
|
+
// // {Key: "spender", Value: addr4},
|
|
620
|
+
// // {Key: "amount", Value: "500ubld,600urun,700ushmoo"},
|
|
621
|
+
// // },
|
|
622
|
+
// // },
|
|
623
|
+
// // {
|
|
624
|
+
// // Type: "non_modaccount",
|
|
625
|
+
// // Attributes: []abci.EventAttribute{
|
|
626
|
+
// // {Key: "receiver", Value: addr3},
|
|
627
|
+
// // {Key: "spender", Value: addr4},
|
|
628
|
+
// // {Key: "amount", Value: "100ubld"},
|
|
629
|
+
// // },
|
|
630
|
+
// // },
|
|
631
|
+
// //}
|
|
632
|
+
// //sdkEvents := make(sdk.Events, len(events))
|
|
633
|
+
// //for i, e := range events {
|
|
634
|
+
// // sdkEvents[i] = sdk.Event(e)
|
|
635
|
+
// //}
|
|
636
|
+
// //em := sdk.NewEventManagerWithHistory(sdkEvents)
|
|
637
|
+
// //ctx = ctx.WithEventManager(em)
|
|
638
|
+
|
|
639
|
+
// err := am.EndBlock(ctx)
|
|
640
|
+
// if err != nil {
|
|
641
|
+
// t.Fatalf("got error = %v", err)
|
|
642
|
+
// }
|
|
643
|
+
|
|
644
|
+
// wantCalls := []string{
|
|
645
|
+
// "AppendSendRestriction",
|
|
646
|
+
// //"GetBalance " + addr1 + " ubld",
|
|
647
|
+
// //"GetBalance " + addr1 + " urun",
|
|
648
|
+
// //"GetBalance " + addr1 + " ushmoo",
|
|
649
|
+
// //"GetBalance " + addr2 + " ubld",
|
|
650
|
+
// //"GetBalance " + addr2 + " urun",
|
|
651
|
+
// //"GetBalance " + addr2 + " ushmoo",
|
|
652
|
+
// }
|
|
653
|
+
// sort.Strings(wantCalls)
|
|
654
|
+
// sort.Strings(bank.calls)
|
|
655
|
+
|
|
656
|
+
// if !reflect.DeepEqual(bank.calls, wantCalls) {
|
|
657
|
+
// t.Errorf("got calls %v, want {%s}", bank.calls, wantCalls)
|
|
658
|
+
// }
|
|
659
|
+
|
|
660
|
+
// wantMsg := newBalances(
|
|
661
|
+
// account(addr1, coin("ubld", "1000")),
|
|
662
|
+
// account(addr1, coin("urun", "0")),
|
|
663
|
+
// account(addr1, coin("ushmoo", "0")),
|
|
664
|
+
// account(addr2, coin("ubld", "0")),
|
|
665
|
+
// account(addr2, coin("urun", "4000")),
|
|
666
|
+
// account(addr2, coin("ushmoo", "0")),
|
|
667
|
+
// )
|
|
668
|
+
// if len(msgsSent) != 1 {
|
|
669
|
+
// t.Errorf("got msgs = %v, want one message", msgsSent)
|
|
670
|
+
// }
|
|
671
|
+
// gotMsg, gotNonce, err := decodeBalances([]byte(msgsSent[0]))
|
|
672
|
+
// if err != nil {
|
|
673
|
+
// t.Fatalf("decode balances error = %v", err)
|
|
674
|
+
// }
|
|
675
|
+
|
|
676
|
+
// nonce := uint64(1)
|
|
677
|
+
// if gotNonce != nonce {
|
|
678
|
+
// t.Errorf("invalid nonce = %+v, want %+v", gotNonce, nonce)
|
|
679
|
+
// }
|
|
680
|
+
|
|
681
|
+
// if !reflect.DeepEqual(gotMsg, wantMsg) {
|
|
682
|
+
// t.Errorf("got sent message %v, want %v", gotMsg, wantMsg)
|
|
683
|
+
// }
|
|
684
|
+
// }
|
|
640
685
|
|
|
641
686
|
func Test_EndBlock_Rewards(t *testing.T) {
|
|
642
687
|
bank := &mockBank{
|
|
@@ -733,20 +778,23 @@ func Test_EndBlock_Rewards(t *testing.T) {
|
|
|
733
778
|
keeper.SetParams(ctx, types.Params{
|
|
734
779
|
RewardEpochDurationBlocks: 3,
|
|
735
780
|
RewardSmoothingBlocks: 1,
|
|
736
|
-
PerEpochRewardFraction:
|
|
781
|
+
PerEpochRewardFraction: sdkmath.LegacyOneDec(),
|
|
737
782
|
})
|
|
738
783
|
|
|
739
|
-
|
|
740
|
-
if
|
|
741
|
-
t.
|
|
784
|
+
err := am.EndBlock(ctx)
|
|
785
|
+
if err != nil {
|
|
786
|
+
t.Fatalf("EndBlock error = %v", err)
|
|
742
787
|
}
|
|
743
788
|
|
|
744
789
|
if len(msgsSent) != 0 {
|
|
745
790
|
t.Errorf("got messages sent = %v, want empty", msgsSent)
|
|
746
791
|
}
|
|
747
792
|
|
|
748
|
-
state = keeper.GetState(ctx)
|
|
749
|
-
if
|
|
793
|
+
state, err = keeper.GetState(ctx)
|
|
794
|
+
if err != nil {
|
|
795
|
+
t.Fatalf("GetState error = %v", err)
|
|
796
|
+
}
|
|
797
|
+
if !state.RewardPool.Equal(tt.wantPool) {
|
|
750
798
|
t.Errorf("got pool %v, want %v", state.RewardPool, tt.wantPool)
|
|
751
799
|
}
|
|
752
800
|
|
|
@@ -771,7 +819,21 @@ type mockAuthKeeper struct {
|
|
|
771
819
|
modAddrs map[string]string
|
|
772
820
|
}
|
|
773
821
|
|
|
774
|
-
|
|
822
|
+
type mockAddressCodec struct{}
|
|
823
|
+
|
|
824
|
+
func (mac mockAddressCodec) StringToBytes(text string) ([]byte, error) {
|
|
825
|
+
return sdk.AccAddressFromBech32(text)
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
func (mac mockAddressCodec) BytesToString(bz []byte) (string, error) {
|
|
829
|
+
return sdk.AccAddress(bz).String(), nil
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
func (ma mockAuthKeeper) AddressCodec() address.Codec {
|
|
833
|
+
return mockAddressCodec{}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
func (ma mockAuthKeeper) GetModuleAccount(_ context.Context, name string) sdk.ModuleAccountI {
|
|
775
837
|
addr, ok := ma.modAddrs[name]
|
|
776
838
|
if !ok {
|
|
777
839
|
return nil
|
|
@@ -780,11 +842,10 @@ func (ma mockAuthKeeper) GetModuleAccount(ctx sdk.Context, name string) authtype
|
|
|
780
842
|
if !ok {
|
|
781
843
|
panic("missing module account")
|
|
782
844
|
}
|
|
783
|
-
return acct.(
|
|
845
|
+
return acct.(sdk.ModuleAccountI)
|
|
784
846
|
}
|
|
785
847
|
|
|
786
|
-
func (ma mockAuthKeeper) GetAccount(
|
|
787
|
-
// fmt.Printf("GetAccount %s\n", addr.String())
|
|
848
|
+
func (ma mockAuthKeeper) GetAccount(_ context.Context, addr sdk.AccAddress) sdk.AccountI {
|
|
788
849
|
return ma.accounts[addr.String()]
|
|
789
850
|
}
|
|
790
851
|
|
|
@@ -824,25 +885,23 @@ func Test_Module_Account(t *testing.T) {
|
|
|
824
885
|
}
|
|
825
886
|
|
|
826
887
|
modAddr := sdk.MustAccAddressFromBech32(moduleBech32)
|
|
827
|
-
if keeper.IsAllowedMonitoringAccount(ctx, modAddr) {
|
|
888
|
+
if keeper.IsAllowedMonitoringAccount(ctx, modAddr.String()) {
|
|
828
889
|
t.Errorf("got IsAllowedMonitoringAccount modAddr = true, want false")
|
|
829
890
|
}
|
|
830
891
|
provisionPool := authtypes.NewModuleAddress("vbank/provision")
|
|
831
|
-
if !keeper.IsAllowedMonitoringAccount(ctx, provisionPool) {
|
|
892
|
+
if !keeper.IsAllowedMonitoringAccount(ctx, provisionPool.String()) {
|
|
832
893
|
t.Errorf("got IsAllowedMonitoringAccount provisionPool = false, want true")
|
|
833
894
|
}
|
|
834
895
|
notModAddr := sdk.MustAccAddressFromBech32(addr1)
|
|
835
|
-
if keeper.IsAllowedMonitoringAccount(ctx, notModAddr) {
|
|
896
|
+
if keeper.IsAllowedMonitoringAccount(ctx, notModAddr.String()) {
|
|
836
897
|
t.Errorf("got IsAllowedMonitoringAccount notModAddr = true, want false")
|
|
837
898
|
}
|
|
838
899
|
missingAddr := sdk.MustAccAddressFromBech32(addr2)
|
|
839
|
-
if keeper.IsAllowedMonitoringAccount(ctx, missingAddr) {
|
|
900
|
+
if keeper.IsAllowedMonitoringAccount(ctx, missingAddr.String()) {
|
|
840
901
|
t.Errorf("got IsAllowedMonitoringAccount missingAddr = false, want true")
|
|
841
902
|
}
|
|
842
903
|
}
|
|
843
904
|
|
|
844
|
-
|
|
845
|
-
|
|
846
905
|
func Test_Receive_Grab_InsufficientFunds(t *testing.T) {
|
|
847
906
|
tests := []struct {
|
|
848
907
|
name string
|
package/x/vibc/handler.go
CHANGED
|
@@ -6,12 +6,13 @@ import (
|
|
|
6
6
|
sdkioerrors "cosmossdk.io/errors"
|
|
7
7
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
8
8
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
9
|
+
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
9
10
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
11
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
11
12
|
)
|
|
12
13
|
|
|
13
14
|
// NewHandler returns a handler for "vibc" type messages.
|
|
14
|
-
func NewHandler(keeper Keeper, bankKeeper types.BankKeeper)
|
|
15
|
+
func NewHandler(keeper Keeper, bankKeeper types.BankKeeper) baseapp.MsgServiceHandler {
|
|
15
16
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
|
16
17
|
switch msg := msg.(type) {
|
|
17
18
|
case *MsgSendPacket:
|
package/x/vibc/keeper/keeper.go
CHANGED
|
@@ -3,17 +3,17 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
"fmt"
|
|
5
5
|
|
|
6
|
+
corestore "cosmossdk.io/core/store"
|
|
6
7
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
7
|
-
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
8
8
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
9
|
|
|
10
10
|
sdkioerrors "cosmossdk.io/errors"
|
|
11
|
-
capability "github.com/cosmos/
|
|
12
|
-
clienttypes "github.com/cosmos/ibc-go/
|
|
13
|
-
channeltypes "github.com/cosmos/ibc-go/
|
|
14
|
-
porttypes "github.com/cosmos/ibc-go/
|
|
15
|
-
host "github.com/cosmos/ibc-go/
|
|
16
|
-
ibcexported "github.com/cosmos/ibc-go/
|
|
11
|
+
capability "github.com/cosmos/ibc-go/modules/capability/types"
|
|
12
|
+
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
|
|
13
|
+
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
|
|
14
|
+
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
|
|
15
|
+
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
|
|
16
|
+
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
|
|
17
17
|
|
|
18
18
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
19
19
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
@@ -35,7 +35,7 @@ type Keeper struct {
|
|
|
35
35
|
|
|
36
36
|
// Filled out by `WithScope`
|
|
37
37
|
scopedKeeper types.ScopedKeeper
|
|
38
|
-
|
|
38
|
+
storeService corestore.KVStoreService
|
|
39
39
|
pushAction vm.ActionPusher
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -57,8 +57,8 @@ func NewKeeper(
|
|
|
57
57
|
|
|
58
58
|
// WithScope returns a new Keeper copied from the receiver, but with the given
|
|
59
59
|
// store key, scoped keeper, and push action.
|
|
60
|
-
func (k Keeper) WithScope(
|
|
61
|
-
k.
|
|
60
|
+
func (k Keeper) WithScope(storeService corestore.KVStoreService, scopedKeeper types.ScopedKeeper, pushAction vm.ActionPusher) Keeper {
|
|
61
|
+
k.storeService = storeService
|
|
62
62
|
k.scopedKeeper = scopedKeeper
|
|
63
63
|
k.pushAction = pushAction
|
|
64
64
|
return k
|
|
@@ -3,7 +3,7 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
5
|
|
|
6
|
-
ibcexported "github.com/cosmos/ibc-go/
|
|
6
|
+
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
|
|
7
7
|
|
|
8
8
|
agtypes "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
9
9
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|