@agoric/cosmos 0.34.2-dev-da89a20.0 → 0.34.2-dev-75cc4e2.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/app/app.go CHANGED
@@ -655,6 +655,7 @@ func NewAgoricApp(
655
655
  keys[vlocalchain.StoreKey],
656
656
  app.BaseApp.MsgServiceRouter(),
657
657
  app.BaseApp.GRPCQueryRouter(),
658
+ app.AccountKeeper,
658
659
  )
659
660
  app.vlocalchainPort = app.AgdServer.MustRegisterPortHandler(
660
661
  "vlocalchain",
package/git-revision.txt CHANGED
@@ -1 +1 @@
1
- da89a20
1
+ 75cc4e2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-da89a20.0+da89a20",
3
+ "version": "0.34.2-dev-75cc4e2.0+75cc4e2",
4
4
  "description": "Connect JS to the Cosmos blockchain SDK",
5
5
  "parsers": {
6
6
  "js": "mjs"
@@ -39,5 +39,5 @@
39
39
  "typeCoverage": {
40
40
  "atLeast": 0
41
41
  },
42
- "gitHead": "da89a207e62599dab3984d298e35c40d958edb4d"
42
+ "gitHead": "75cc4e26530875f8d625722f3bd372dca656fa38"
43
43
  }
package/vm/action.go CHANGED
@@ -86,7 +86,7 @@ func PopulateAction(ctx sdk.Context, action Action) Action {
86
86
  var headerPtr *ActionHeader
87
87
  if fieldType.Type == actionHeaderType {
88
88
  headerPtr = field.Addr().Interface().(*ActionHeader)
89
- } else if fieldType.Type == reflect.PtrTo(actionHeaderType) {
89
+ } else if fieldType.Type == reflect.PointerTo(actionHeaderType) {
90
90
  if field.IsNil() {
91
91
  headerPtr = &ActionHeader{}
92
92
  } else {
@@ -28,6 +28,7 @@ type Keeper struct {
28
28
  cdc codec.Codec
29
29
  msgRouter types.MsgRouter
30
30
  queryRouter types.GRPCQueryRouter
31
+ acctKeeper types.AccountKeeper
31
32
  }
32
33
 
33
34
  // NewKeeper creates a new dIBC Keeper instance
@@ -36,12 +37,14 @@ func NewKeeper(
36
37
  key storetypes.StoreKey,
37
38
  msgRouter types.MsgRouter,
38
39
  queryRouter types.GRPCQueryRouter,
40
+ acctKeeper types.AccountKeeper,
39
41
  ) Keeper {
40
42
  return Keeper{
41
43
  key: key,
42
44
  cdc: cdc,
43
45
  msgRouter: msgRouter,
44
46
  queryRouter: queryRouter,
47
+ acctKeeper: acctKeeper,
45
48
  }
46
49
  }
47
50
 
@@ -266,14 +269,27 @@ func (k Keeper) AllocateAddress(cctx context.Context) sdk.AccAddress {
266
269
  localchainModuleAcc := sdkaddress.Module(types.ModuleName, []byte("localchain"))
267
270
  header := ctx.BlockHeader()
268
271
 
269
- // Increment our sequence number.
270
- seq := store.Get(types.KeyLastSequence)
271
- seq = types.NextSequence(seq)
272
- store.Set(types.KeyLastSequence, seq)
272
+ // Loop until we find an unused address.
273
+ for {
274
+ // Increment our sequence number.
275
+ seq := store.Get(types.KeyLastSequence)
276
+ seq = types.NextSequence(seq)
277
+ store.Set(types.KeyLastSequence, seq)
273
278
 
274
- buf := seq
275
- buf = append(buf, header.AppHash...)
276
- buf = append(buf, header.DataHash...)
279
+ buf := seq
280
+ buf = append(buf, header.AppHash...)
281
+ buf = append(buf, header.DataHash...)
277
282
 
278
- return sdkaddress.Derive(localchainModuleAcc, buf)
283
+ addr := sdkaddress.Derive(localchainModuleAcc, buf)
284
+ if k.acctKeeper.HasAccount(ctx, addr) {
285
+ continue
286
+ }
287
+
288
+ // We found an unused address, so create an account for it.
289
+ acct := k.acctKeeper.NewAccountWithAddress(ctx, addr)
290
+ k.acctKeeper.SetAccount(ctx, acct)
291
+
292
+ // All good, return the address.
293
+ return addr
294
+ }
279
295
  }
@@ -10,7 +10,6 @@ import (
10
10
  banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
11
11
  )
12
12
 
13
-
14
13
  func TestKeeper_ParseRequestTypeURL(t *testing.T) {
15
14
  testCases := []struct {
16
15
  name string
@@ -46,7 +45,7 @@ func TestKeeper_DeserializeTxMessages(t *testing.T) {
46
45
 
47
46
  banktypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
48
47
 
49
- keeper := NewKeeper(cdc, nil, nil, nil)
48
+ keeper := NewKeeper(cdc, nil, nil, nil, nil)
50
49
 
51
50
  expectedMsgSend := []sdk.Msg{
52
51
  &banktypes.MsgSend{
@@ -63,22 +62,22 @@ func TestKeeper_DeserializeTxMessages(t *testing.T) {
63
62
  wantErr bool
64
63
  }{
65
64
  {
66
- name: "camelCase keys",
67
- json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","fromAddress":"cosmos1abc","toAddress":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
65
+ name: "camelCase keys",
66
+ json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","fromAddress":"cosmos1abc","toAddress":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
68
67
  expected: expectedMsgSend,
69
- wantErr: false,
68
+ wantErr: false,
70
69
  },
71
70
  {
72
- name: "snake_case keys",
73
- json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
71
+ name: "snake_case keys",
72
+ json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
74
73
  expected: expectedMsgSend,
75
- wantErr: false,
74
+ wantErr: false,
76
75
  },
77
76
  {
78
- name: "misspelled key",
79
- json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_addresss":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
77
+ name: "misspelled key",
78
+ json: `{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_addresss":"cosmos1abc","to_address":"cosmos1xyz","amount":[{"denom":"stake","amount":"100"}]}]}`,
80
79
  expected: expectedMsgSend,
81
- wantErr: true,
80
+ wantErr: true,
82
81
  },
83
82
  }
84
83
 
@@ -0,0 +1,12 @@
1
+ package types
2
+
3
+ import (
4
+ sdk "github.com/cosmos/cosmos-sdk/types"
5
+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
6
+ )
7
+
8
+ type AccountKeeper interface {
9
+ NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
10
+ HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool
11
+ SetAccount(ctx sdk.Context, acc authtypes.AccountI)
12
+ }
@@ -16,6 +16,7 @@ import (
16
16
  "github.com/cosmos/cosmos-sdk/store"
17
17
  storetypes "github.com/cosmos/cosmos-sdk/store/types"
18
18
  sdk "github.com/cosmos/cosmos-sdk/types"
19
+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
19
20
  banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
20
21
  stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
21
22
  transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
@@ -36,6 +37,25 @@ const (
36
37
  msgAllocateAddress = `{"type":"VLOCALCHAIN_ALLOCATE_ADDRESS"}`
37
38
  )
38
39
 
40
+ type mockAccounts struct {
41
+ existing map[string]bool
42
+ }
43
+
44
+ var _ types.AccountKeeper = (*mockAccounts)(nil)
45
+
46
+ func (a *mockAccounts) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI {
47
+ return authtypes.NewBaseAccountWithAddress(addr)
48
+ }
49
+
50
+ func (a *mockAccounts) HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool {
51
+ existing := a.existing[addr.String()]
52
+ return existing
53
+ }
54
+
55
+ func (a *mockAccounts) SetAccount(ctx sdk.Context, acc authtypes.AccountI) {
56
+ a.existing[acc.GetAddress().String()] = true
57
+ }
58
+
39
59
  type mockBank struct {
40
60
  banktypes.UnimplementedQueryServer
41
61
  banktypes.UnimplementedMsgServer
@@ -108,7 +128,7 @@ func (s *mockStaking) UnbondingDelegation(cctx context.Context, req *stakingtype
108
128
  }
109
129
 
110
130
  // makeTestKit creates a minimal Keeper and Context for use in testing.
111
- func makeTestKit(bank *mockBank, transfer *mockTransfer, staking *mockStaking) (vm.PortHandler, context.Context) {
131
+ func makeTestKit(bank *mockBank, transfer *mockTransfer, staking *mockStaking, accts *mockAccounts) (vm.PortHandler, context.Context) {
112
132
  encodingConfig := params.MakeEncodingConfig()
113
133
  cdc := encodingConfig.Marshaler
114
134
 
@@ -127,9 +147,8 @@ func makeTestKit(bank *mockBank, transfer *mockTransfer, staking *mockStaking) (
127
147
  stakingtypes.RegisterMsgServer(txRouter, staking)
128
148
  stakingtypes.RegisterQueryServer(queryRouter, staking)
129
149
 
130
-
131
150
  // create a new Keeper
132
- keeper := vlocalchain.NewKeeper(cdc, vlocalchainStoreKey, txRouter, queryRouter)
151
+ keeper := vlocalchain.NewKeeper(cdc, vlocalchainStoreKey, txRouter, queryRouter, accts)
133
152
 
134
153
  db := dbm.NewMemDB()
135
154
  ms := store.NewCommitMultiStore(db)
@@ -153,13 +172,15 @@ func TestAllocateAddress(t *testing.T) {
153
172
  bank := &mockBank{}
154
173
  transfer := &mockTransfer{}
155
174
  staking := &mockStaking{}
156
- handler, cctx := makeTestKit(bank, transfer, staking)
175
+ acct := &mockAccounts{existing: map[string]bool{
176
+ firstAddr: true,
177
+ "cosmos1c5hplwyxk5jr2dsygjqepzfqvfukwduq9c4660aah76krf99m6gs0k7hvl": true,
178
+ }}
179
+ handler, cctx := makeTestKit(bank, transfer, staking, acct)
157
180
 
158
181
  addrs := map[string]bool{
159
- firstAddr: false,
160
182
  "cosmos1yj40fakym8kf4wvgz9tky7k9f3v9msm3t7frscrmkjsdkxkpsfkqgeczkg": false,
161
183
  "cosmos1s76vryj7m8k8nm9le65a4plhf5rym5sumtt2n0vwnk5l6k4cwuhsj56ujj": false,
162
- "cosmos1c5hplwyxk5jr2dsygjqepzfqvfukwduq9c4660aah76krf99m6gs0k7hvl": false,
163
184
  "cosmos1ys3a7mtna3cad0wxcs4ddukn37stexjdvns8jfdn4uerlr95y4xqnrypf6": false,
164
185
  }
165
186
  numToTest := len(addrs)
@@ -185,6 +206,9 @@ func TestAllocateAddress(t *testing.T) {
185
206
  t.Fatalf("unexpected duplicate address[%d]: %v", i, addr)
186
207
  }
187
208
  addrs[addr] = true
209
+ if !acct.existing[addr] {
210
+ t.Fatalf("expected address[%d]: %v to be added to accounts", i, addr)
211
+ }
188
212
  }
189
213
  }
190
214
 
@@ -197,7 +221,8 @@ func TestQuery(t *testing.T) {
197
221
  }}
198
222
  transfer := &mockTransfer{}
199
223
  staking := &mockStaking{}
200
- handler, cctx := makeTestKit(bank, transfer, staking)
224
+ accts := &mockAccounts{existing: map[string]bool{}}
225
+ handler, cctx := makeTestKit(bank, transfer, staking, accts)
201
226
 
202
227
  // get balances
203
228
  testCases := []struct {
@@ -338,7 +363,8 @@ func TestExecuteTx(t *testing.T) {
338
363
  }}
339
364
  transfer := &mockTransfer{}
340
365
  staking := &mockStaking{}
341
- handler, cctx := makeTestKit(bank, transfer, staking)
366
+ accts := &mockAccounts{existing: map[string]bool{}}
367
+ handler, cctx := makeTestKit(bank, transfer, staking, accts)
342
368
 
343
369
  // create a new message
344
370
  msg := `{"type":"VLOCALCHAIN_ALLOCATE_ADDRESS"}`
@@ -426,7 +452,7 @@ func TestExecuteTx(t *testing.T) {
426
452
  if len(resp) != 1 {
427
453
  t.Fatalf("expected 1 response, got %d", len(resp))
428
454
  }
429
-
455
+
430
456
  if _, ok := resp[0]["completionTime"]; !ok {
431
457
  t.Error("expected 'completionTime' field in response")
432
458
  }