@agoric/cosmos 0.34.2-dev-e26232e.0 → 0.34.2-dev-0f42fb6.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
- e26232e
1
+ 0f42fb6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-e26232e.0+e26232e",
3
+ "version": "0.34.2-dev-0f42fb6.0+0f42fb6",
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": "e26232e68e2019db07078ae4962de47b3d0a6666"
41
+ "gitHead": "0f42fb639a6b3619de097ec0f819499200c9f6b7"
42
42
  }
@@ -0,0 +1,112 @@
1
+ package keeper
2
+
3
+ import (
4
+ "bytes"
5
+ "testing"
6
+
7
+ agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
8
+
9
+ abci "github.com/tendermint/tendermint/abci/types"
10
+
11
+ "github.com/cosmos/cosmos-sdk/codec"
12
+ sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
13
+ )
14
+
15
+ func TestQuerier(t *testing.T) {
16
+ testKit := makeTestKit()
17
+ ctx, keeper := testKit.ctx, testKit.vstorageKeeper
18
+ legacyQuerierCdc := codec.NewAminoCodec(codec.NewLegacyAmino())
19
+ querier := NewQuerier(keeper, legacyQuerierCdc.LegacyAmino)
20
+
21
+ // Populate mock data
22
+ keeper.SetStorage(ctx, agoric.NewKVEntry("foo.bar", "42"))
23
+ keeper.SetStorage(ctx, agoric.NewKVEntry("foo.baz", "hello"))
24
+
25
+ type testCase struct {
26
+ label string
27
+ path []string
28
+ expected []byte
29
+ err *sdkerrors.Error
30
+ }
31
+ testCases := []testCase{}
32
+
33
+ // Test invalid endpoint
34
+ testCases = append(testCases, []testCase{
35
+ {label: "invalid endpoint",
36
+ path: []string{"foo"},
37
+ err: sdkerrors.ErrUnknownRequest,
38
+ },
39
+ }...)
40
+
41
+ // Test invalid arguments to valid data and children endpoints
42
+ for _, endpoint := range []string{"data", "children"} {
43
+ testCases = append(testCases, []testCase{
44
+ {label: endpoint + ": no entry path",
45
+ path: []string{endpoint},
46
+ err: sdkerrors.ErrInvalidRequest,
47
+ },
48
+ {label: endpoint + ": too many segments",
49
+ path: []string{endpoint, "foo", "bar"},
50
+ err: sdkerrors.ErrInvalidRequest,
51
+ },
52
+ {label: endpoint + ": invalid path",
53
+ path: []string{endpoint, ".", ""},
54
+ err: sdkerrors.ErrInvalidRequest,
55
+ },
56
+ }...)
57
+ }
58
+
59
+ // Test data endpoint with valid vstorage path
60
+ testCases = append(testCases, []testCase{
61
+ {label: "data: non-existent path",
62
+ path: []string{"data", "bar"},
63
+ // DO NOT CHANGE
64
+ // The UI and CLI check for the specific cosmos-sdk error code & codespace
65
+ err: sdkerrors.ErrNotFound,
66
+ },
67
+ {label: "data: path with no data",
68
+ path: []string{"data", "foo"},
69
+ // DO NOT CHANGE
70
+ // The UI and CLI check for the specific cosmos-sdk error code & codespace
71
+ err: sdkerrors.ErrNotFound,
72
+ },
73
+ {label: "data: path with data",
74
+ path: []string{"data", "foo.bar"},
75
+ expected: []byte("{\n \"value\": \"42\"\n}"),
76
+ },
77
+ }...)
78
+
79
+ // Ensure stability of cosmos-sdk error codes
80
+ if codespace, code, _ := sdkerrors.ABCIInfo(sdkerrors.ErrNotFound, true); codespace != "sdk" || code != 38 {
81
+ t.Errorf("cosmos-sdk ErrNotFound has codespace %s, code %d, expected sdk/38", codespace, code)
82
+ }
83
+
84
+ // Test children endpoint with valid vstorage path
85
+ testCases = append(testCases, []testCase{
86
+ {label: "children: non-existent path",
87
+ path: []string{"children", "bar"},
88
+ expected: []byte("{\n \"children\": []\n}"),
89
+ },
90
+ {label: "children: path with no children",
91
+ path: []string{"children", "foo.bar"},
92
+ expected: []byte("{\n \"children\": []\n}"),
93
+ },
94
+ {label: "children: path with children",
95
+ path: []string{"children", "foo"},
96
+ expected: []byte("{\n \"children\": [\n \"bar\",\n \"baz\"\n ]\n}"),
97
+ },
98
+ }...)
99
+
100
+ for _, desc := range testCases {
101
+ res, err := querier(ctx, desc.path, abci.RequestQuery{})
102
+ if desc.err != nil {
103
+ if err == nil {
104
+ t.Errorf("%s: got no error, want error %q", desc.label, *desc.err)
105
+ } else if codespace, code, _ := sdkerrors.ABCIInfo(err, true); codespace != desc.err.Codespace() || code != desc.err.ABCICode() {
106
+ t.Errorf("%s: got error %v, want error %q", desc.label, err, *desc.err)
107
+ }
108
+ } else if !bytes.Equal(res, desc.expected) {
109
+ t.Errorf("%s: wrong result: %#v, expected %#v", desc.label, string(res), string(desc.expected))
110
+ }
111
+ }
112
+ }