@agoric/cosmos 0.34.2-dev-7ed74d7.0 → 0.34.2-dev-316a778.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/git-revision.txt CHANGED
@@ -1 +1 @@
1
- 7ed74d7
1
+ 316a778
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-7ed74d7.0+7ed74d7",
3
+ "version": "0.34.2-dev-316a778.0+316a778",
4
4
  "description": "Connect JS to the Cosmos blockchain SDK",
5
5
  "parsers": {
6
6
  "js": "mjs"
@@ -38,5 +38,5 @@
38
38
  "typeCoverage": {
39
39
  "atLeast": 0
40
40
  },
41
- "gitHead": "7ed74d76185ae163c4df6254e8ff6b76cfac56ce"
41
+ "gitHead": "316a77874b161cc418567adbfc41463892b2aa16"
42
42
  }
@@ -13,6 +13,7 @@ import (
13
13
  "github.com/cosmos/cosmos-sdk/store"
14
14
  storetypes "github.com/cosmos/cosmos-sdk/store/types"
15
15
  sdk "github.com/cosmos/cosmos-sdk/types"
16
+ sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
16
17
  authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
17
18
  paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
18
19
  paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
@@ -233,6 +234,24 @@ func (b *mockBank) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins)
233
234
 
234
235
  func (b *mockBank) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
235
236
  b.record(fmt.Sprintf("SendCoinsFromAccountToModule %s %s %s", senderAddr, recipientModule, amt))
237
+
238
+ // for each coin in the request, check spendable vs. requested
239
+ for _, coin := range amt {
240
+ // mimic GetBalance logic
241
+ have := b.balances[senderAddr.String()].AmountOf(coin.Denom)
242
+ spendable := sdk.NewCoin(coin.Denom, have)
243
+
244
+ if spendable.IsLT(coin) {
245
+ // wrap exactly like the real x/bank keeper
246
+ // https://github.com/agoric-labs/cosmos-sdk/blob/8b2b975304291c51991278734daa2ff5e57fcb83/x/bank/keeper/send.go#L252-L256
247
+ return sdkerrors.Wrapf(
248
+ sdkerrors.ErrInsufficientFunds,
249
+ "spendable balance %s is smaller than %s",
250
+ spendable, coin,
251
+ )
252
+ }
253
+ }
254
+
236
255
  return nil
237
256
  }
238
257
 
@@ -821,3 +840,63 @@ func Test_Module_Account(t *testing.T) {
821
840
  t.Errorf("got IsAllowedMonitoringAccount missingAddr = false, want true")
822
841
  }
823
842
  }
843
+
844
+
845
+
846
+ func Test_Receive_Grab_InsufficientFunds(t *testing.T) {
847
+ tests := []struct {
848
+ name string
849
+ initialBalance sdk.Coin
850
+ }{
851
+ {
852
+ name: "only 100 available",
853
+ initialBalance: sdk.NewInt64Coin("ufoo", 100),
854
+ },
855
+ {
856
+ name: "zero available",
857
+ initialBalance: sdk.NewInt64Coin("ufoo", 0),
858
+ },
859
+ }
860
+
861
+ for _, tc := range tests {
862
+ t.Run(tc.name, func(t *testing.T) {
863
+ // set up mockBank with the desired starting balance
864
+ bank := &mockBank{balances: map[string]sdk.Coins{
865
+ addr1: sdk.NewCoins(tc.initialBalance),
866
+ }}
867
+
868
+ // wire into keeper
869
+ keeper, ctx := makeTestKit(nil, bank)
870
+ handler := NewPortHandler(AppModule{}, keeper)
871
+ ctl := sdk.WrapSDKContext(ctx)
872
+
873
+ // attempt to grab 500ufoo
874
+ grabAmt := sdk.NewCoins(sdk.NewInt64Coin("ufoo", 500))
875
+ _, err := handler.Receive(ctl, fmt.Sprintf(`{
876
+ "type":"VBANK_GRAB",
877
+ "sender":"%s",
878
+ "amount":"500",
879
+ "denom":"ufoo"
880
+ }`, addr1))
881
+ if err == nil {
882
+ t.Fatal("expected insufficient-funds error, got nil")
883
+ }
884
+
885
+ expected := fmt.Sprintf(
886
+ "cannot grab %s coins: spendable balance %s is smaller than %s: %s",
887
+ grabAmt.Sort().String(),
888
+ tc.initialBalance.String(),
889
+ grabAmt.Sort().String(),
890
+ sdkerrors.ErrInsufficientFunds.Error(),
891
+ )
892
+
893
+ t.Logf("actual error: %q", err.Error())
894
+
895
+ got := err.Error()
896
+ if got != expected {
897
+ t.Errorf("wrong error message:\n expected: %q\n got: %q",
898
+ expected, got)
899
+ }
900
+ })
901
+ }
902
+ }