@agoric/cosmos 0.34.1 → 0.34.2-calypso-dev-dabccdc.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/MAINTAINERS.md +3 -0
- package/Makefile +67 -41
- package/agoric/config.go +35 -0
- package/ante/ante.go +65 -0
- package/ante/expected_keepers.go +26 -0
- package/ante/inbound.go +137 -0
- package/ante/inbound_test.go +228 -0
- package/ante/vm_admission.go +65 -0
- package/app/app.go +396 -211
- package/app/export.go +13 -9
- package/app/sim_test.go +4 -4
- package/app/upgrade.go +215 -0
- package/binding.gyp.in +29 -4
- package/buf.work.yaml +4 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/find_binary.go +22 -7
- package/cmd/agd/main.go +133 -10
- package/cmd/libdaemon/main.go +67 -53
- package/cmd/libdaemon/main_test.go +37 -0
- package/daemon/cmd/genaccounts.go +22 -18
- package/daemon/cmd/root.go +253 -52
- package/daemon/cmd/root_test.go +190 -2
- package/daemon/cmd/testnet.go +17 -6
- package/daemon/main.go +6 -3
- package/e2e_test/Makefile +29 -0
- package/e2e_test/README.md +100 -0
- package/e2e_test/go.mod +217 -0
- package/e2e_test/go.sum +1323 -0
- package/e2e_test/ibc_conformance_test.go +56 -0
- package/e2e_test/pfm_test.go +613 -0
- package/e2e_test/util.go +271 -0
- package/git-revision.txt +1 -0
- package/go.mod +207 -0
- package/go.sum +1877 -0
- package/package.json +13 -21
- package/proto/agoric/swingset/genesis.proto +14 -0
- package/proto/agoric/swingset/swingset.proto +6 -3
- package/proto/agoric/vlocalchain/.clang-format +7 -0
- package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
- package/proto/agoric/vstorage/query.proto +53 -1
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +16 -6
- package/third_party/proto/buf.yaml +1 -0
- package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
- package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
- package/third_party/proto/google/api/annotations.proto +1 -1
- package/third_party/proto/google/api/http.proto +181 -120
- package/third_party/proto/google/api/httpbody.proto +9 -6
- package/third_party/proto/google/protobuf/any.proto +1 -7
- package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
- package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
- package/tools/tools.go +11 -0
- package/types/events.go +41 -0
- package/types/kv_entry.go +114 -0
- package/types/kv_entry_helpers.go +276 -0
- package/types/kv_entry_helpers_test.go +237 -0
- package/types/kv_entry_test.go +143 -0
- package/upgradegaia.sh +75 -0
- package/vm/action.go +134 -0
- package/vm/action_test.go +149 -0
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +49 -0
- package/vm/core_proposals.go +51 -0
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/proto_json.go +38 -0
- package/vm/proto_json_test.go +103 -0
- package/vm/server.go +124 -0
- package/x/swingset/abci.go +26 -37
- package/x/swingset/alias.go +9 -6
- package/x/swingset/client/cli/query.go +2 -2
- package/x/swingset/client/cli/tx.go +52 -33
- package/x/swingset/client/proposal_handler.go +2 -17
- package/x/swingset/genesis.go +163 -37
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +309 -0
- package/x/swingset/keeper/extension_snapshotter_test.go +104 -0
- package/x/swingset/keeper/keeper.go +95 -48
- package/x/swingset/keeper/keeper_test.go +77 -0
- package/x/swingset/keeper/migrations.go +7 -2
- package/x/swingset/keeper/msg_server.go +71 -56
- package/x/swingset/keeper/proposal.go +15 -9
- package/x/swingset/keeper/querier.go +24 -15
- package/x/swingset/keeper/swing_store_exports_handler.go +872 -0
- package/x/swingset/keeper/swing_store_exports_handler_test.go +247 -0
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +33 -11
- package/x/swingset/proposal_handler.go +5 -4
- package/x/swingset/swingset.go +73 -0
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/codec.go +2 -2
- package/x/swingset/types/default-params.go +23 -17
- package/x/swingset/types/expected_keepers.go +14 -2
- package/x/swingset/types/genesis.pb.go +361 -18
- package/x/swingset/types/msgs.go +87 -26
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/swingset/types/params.go +76 -1
- package/x/swingset/types/params_test.go +116 -0
- package/x/swingset/types/proposal.go +10 -9
- package/x/swingset/types/swingset.pb.go +83 -81
- package/x/swingset/types/types.go +30 -28
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/keeper.go +3 -2
- package/x/vbank/keeper/querier.go +9 -4
- package/x/vbank/keeper/rewards.go +1 -1
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +34 -32
- package/x/vbank/vbank_test.go +20 -20
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +17 -15
- package/x/vibc/keeper/keeper.go +113 -89
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +28 -6
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/msgs.go +1 -1
- package/x/vibc/types/msgs.pb.go +1 -1
- package/x/vibc/types/receiver.go +170 -0
- package/x/vlocalchain/alias.go +19 -0
- package/x/vlocalchain/handler.go +21 -0
- package/x/vlocalchain/keeper/keeper.go +279 -0
- package/x/vlocalchain/keeper/keeper_test.go +97 -0
- package/x/vlocalchain/types/codec.go +34 -0
- package/x/vlocalchain/types/key.go +27 -0
- package/x/vlocalchain/types/msgs.go +16 -0
- package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
- package/x/vlocalchain/vlocalchain.go +114 -0
- package/x/vlocalchain/vlocalchain_test.go +434 -0
- package/x/vstorage/README.md +138 -0
- package/x/vstorage/capdata/capdata.go +298 -0
- package/x/vstorage/capdata/capdata_test.go +352 -0
- package/x/vstorage/client/cli/query.go +51 -4
- package/x/vstorage/genesis.go +0 -3
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +220 -0
- package/x/vstorage/keeper/keeper.go +75 -57
- package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
- package/x/vstorage/keeper/keeper_test.go +40 -62
- package/x/vstorage/keeper/querier.go +39 -14
- package/x/vstorage/keeper/querier_test.go +113 -0
- package/x/vstorage/module.go +0 -5
- package/x/vstorage/testing/queue.go +27 -0
- package/x/vstorage/types/path_keys.go +22 -10
- package/x/vstorage/types/path_keys_test.go +84 -18
- package/x/vstorage/types/query.pb.go +646 -36
- package/x/vstorage/types/query.pb.gw.go +119 -0
- package/x/vstorage/types/types.go +0 -66
- package/x/vstorage/vstorage.go +33 -35
- package/x/vstorage/vstorage_test.go +19 -19
- package/x/vtransfer/alias.go +13 -0
- package/x/vtransfer/genesis.go +39 -0
- package/x/vtransfer/genesis_test.go +12 -0
- package/x/vtransfer/handler.go +20 -0
- package/x/vtransfer/ibc_middleware.go +186 -0
- package/x/vtransfer/ibc_middleware_test.go +448 -0
- package/x/vtransfer/keeper/keeper.go +281 -0
- package/x/vtransfer/module.go +124 -0
- package/x/vtransfer/types/expected_keepers.go +38 -0
- package/x/vtransfer/types/genesis.pb.go +327 -0
- package/x/vtransfer/types/key.go +9 -0
- package/x/vtransfer/types/msgs.go +9 -0
- package/app/const.go +0 -6
- package/cmd/helper/main.go +0 -21
- package/proto/agoric/lien/genesis.proto +0 -25
- package/proto/agoric/lien/lien.proto +0 -25
- package/x/lien/alias.go +0 -17
- package/x/lien/genesis.go +0 -58
- package/x/lien/genesis_test.go +0 -101
- package/x/lien/keeper/account.go +0 -285
- package/x/lien/keeper/keeper.go +0 -254
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -203
- package/x/lien/lien_test.go +0 -529
- package/x/lien/module.go +0 -115
- package/x/lien/spec/01_concepts.md +0 -146
- package/x/lien/spec/02_messages.md +0 -96
- package/x/lien/types/accountkeeper.go +0 -81
- package/x/lien/types/accountstate.go +0 -27
- package/x/lien/types/expected_keepers.go +0 -18
- package/x/lien/types/genesis.pb.go +0 -567
- package/x/lien/types/key.go +0 -25
- package/x/lien/types/lien.pb.go +0 -403
- package/x/swingset/keeper/snapshotter.go +0 -491
- package/x/swingset/keeper/snapshotter_test.go +0 -185
- package/x/swingset/legacy/v32/params.go +0 -37
- package/x/swingset/legacy/v32/params_test.go +0 -133
- package/x/vibc/ibc.go +0 -442
- /package/{src/index.cjs → index.cjs} +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
12
|
+
"github.com/cosmos/cosmos-sdk/codec"
|
|
13
|
+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
func TestQuerier(t *testing.T) {
|
|
17
|
+
testKit := makeTestKit()
|
|
18
|
+
ctx, keeper := testKit.ctx, testKit.vstorageKeeper
|
|
19
|
+
legacyQuerierCdc := codec.NewAminoCodec(codec.NewLegacyAmino())
|
|
20
|
+
querier := NewQuerier(keeper, legacyQuerierCdc.LegacyAmino)
|
|
21
|
+
|
|
22
|
+
// Populate mock data
|
|
23
|
+
keeper.SetStorage(ctx, agoric.NewKVEntry("foo.bar", "42"))
|
|
24
|
+
keeper.SetStorage(ctx, agoric.NewKVEntry("foo.baz", "hello"))
|
|
25
|
+
|
|
26
|
+
type testCase struct {
|
|
27
|
+
label string
|
|
28
|
+
path []string
|
|
29
|
+
expected []byte
|
|
30
|
+
err *sdkioerrors.Error
|
|
31
|
+
}
|
|
32
|
+
testCases := []testCase{}
|
|
33
|
+
|
|
34
|
+
// Test invalid endpoint
|
|
35
|
+
testCases = append(testCases, []testCase{
|
|
36
|
+
{label: "invalid endpoint",
|
|
37
|
+
path: []string{"foo"},
|
|
38
|
+
err: sdkerrors.ErrUnknownRequest,
|
|
39
|
+
},
|
|
40
|
+
}...)
|
|
41
|
+
|
|
42
|
+
// Test invalid arguments to valid data and children endpoints
|
|
43
|
+
for _, endpoint := range []string{"data", "children"} {
|
|
44
|
+
testCases = append(testCases, []testCase{
|
|
45
|
+
{label: endpoint + ": no entry path",
|
|
46
|
+
path: []string{endpoint},
|
|
47
|
+
err: sdkerrors.ErrInvalidRequest,
|
|
48
|
+
},
|
|
49
|
+
{label: endpoint + ": too many segments",
|
|
50
|
+
path: []string{endpoint, "foo", "bar"},
|
|
51
|
+
err: sdkerrors.ErrInvalidRequest,
|
|
52
|
+
},
|
|
53
|
+
{label: endpoint + ": invalid path",
|
|
54
|
+
path: []string{endpoint, ".", ""},
|
|
55
|
+
err: sdkerrors.ErrInvalidRequest,
|
|
56
|
+
},
|
|
57
|
+
}...)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Test data endpoint with valid vstorage path
|
|
61
|
+
testCases = append(testCases, []testCase{
|
|
62
|
+
{label: "data: non-existent path",
|
|
63
|
+
path: []string{"data", "bar"},
|
|
64
|
+
// DO NOT CHANGE
|
|
65
|
+
// The UI and CLI check for the specific cosmos-sdk error code & codespace
|
|
66
|
+
err: sdkerrors.ErrNotFound,
|
|
67
|
+
},
|
|
68
|
+
{label: "data: path with no data",
|
|
69
|
+
path: []string{"data", "foo"},
|
|
70
|
+
// DO NOT CHANGE
|
|
71
|
+
// The UI and CLI check for the specific cosmos-sdk error code & codespace
|
|
72
|
+
err: sdkerrors.ErrNotFound,
|
|
73
|
+
},
|
|
74
|
+
{label: "data: path with data",
|
|
75
|
+
path: []string{"data", "foo.bar"},
|
|
76
|
+
expected: []byte("{\n \"value\": \"42\"\n}"),
|
|
77
|
+
},
|
|
78
|
+
}...)
|
|
79
|
+
|
|
80
|
+
// Ensure stability of cosmos-sdk error codes
|
|
81
|
+
if codespace, code, _ := sdkioerrors.ABCIInfo(sdkerrors.ErrNotFound, true); codespace != "sdk" || code != 38 {
|
|
82
|
+
t.Errorf("cosmos-sdk ErrNotFound has codespace %s, code %d, expected sdk/38", codespace, code)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Test children endpoint with valid vstorage path
|
|
86
|
+
testCases = append(testCases, []testCase{
|
|
87
|
+
{label: "children: non-existent path",
|
|
88
|
+
path: []string{"children", "bar"},
|
|
89
|
+
expected: []byte("{\n \"children\": []\n}"),
|
|
90
|
+
},
|
|
91
|
+
{label: "children: path with no children",
|
|
92
|
+
path: []string{"children", "foo.bar"},
|
|
93
|
+
expected: []byte("{\n \"children\": []\n}"),
|
|
94
|
+
},
|
|
95
|
+
{label: "children: path with children",
|
|
96
|
+
path: []string{"children", "foo"},
|
|
97
|
+
expected: []byte("{\n \"children\": [\n \"bar\",\n \"baz\"\n ]\n}"),
|
|
98
|
+
},
|
|
99
|
+
}...)
|
|
100
|
+
|
|
101
|
+
for _, desc := range testCases {
|
|
102
|
+
res, err := querier(ctx, desc.path, abci.RequestQuery{})
|
|
103
|
+
if desc.err != nil {
|
|
104
|
+
if err == nil {
|
|
105
|
+
t.Errorf("%s: got no error, want error %q", desc.label, *desc.err)
|
|
106
|
+
} else if codespace, code, _ := sdkioerrors.ABCIInfo(err, true); codespace != desc.err.Codespace() || code != desc.err.ABCICode() {
|
|
107
|
+
t.Errorf("%s: got error %v, want error %q", desc.label, err, *desc.err)
|
|
108
|
+
}
|
|
109
|
+
} else if !bytes.Equal(res, desc.expected) {
|
|
110
|
+
t.Errorf("%s: wrong result: %#v, expected %#v", desc.label, string(res), string(desc.expected))
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
package/x/vstorage/module.go
CHANGED
|
@@ -4,7 +4,6 @@ import (
|
|
|
4
4
|
"context"
|
|
5
5
|
"encoding/json"
|
|
6
6
|
|
|
7
|
-
"github.com/gorilla/mux"
|
|
8
7
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
9
8
|
"github.com/spf13/cobra"
|
|
10
9
|
|
|
@@ -57,10 +56,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
|
|
57
56
|
return ValidateGenesis(&data)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
// Register rest routes
|
|
61
|
-
func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
65
60
|
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
66
61
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package testing
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
|
|
6
|
+
keeper "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/keeper"
|
|
7
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
func GetQueueItems(ctx sdk.Context, vstorageKeeper keeper.Keeper, queuePath string) ([]string, error) {
|
|
11
|
+
head, err := vstorageKeeper.GetIntValue(ctx, queuePath+".head")
|
|
12
|
+
if err != nil {
|
|
13
|
+
return nil, err
|
|
14
|
+
}
|
|
15
|
+
tail, err := vstorageKeeper.GetIntValue(ctx, queuePath+".tail")
|
|
16
|
+
if err != nil {
|
|
17
|
+
return nil, err
|
|
18
|
+
}
|
|
19
|
+
length := tail.Sub(head).Int64()
|
|
20
|
+
values := make([]string, length)
|
|
21
|
+
var i int64
|
|
22
|
+
for i = 0; i < length; i++ {
|
|
23
|
+
path := fmt.Sprintf("%s.%s", queuePath, head.Add(sdk.NewInt(i)).String())
|
|
24
|
+
values[i] = vstorageKeeper.GetEntry(ctx, path).StringValue()
|
|
25
|
+
}
|
|
26
|
+
return values, nil
|
|
27
|
+
}
|
|
@@ -7,9 +7,17 @@ import (
|
|
|
7
7
|
"strings"
|
|
8
8
|
)
|
|
9
9
|
|
|
10
|
-
// - A "path" is a sequence of zero or more dot-separated nonempty
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// - A "path" is a sequence of zero or more dot-separated nonempty segments
|
|
11
|
+
// using a restricted alphabet of ASCII alphanumerics plus underscore and dash,
|
|
12
|
+
// consistent with packages/internal/src/lib-chainStorage.js but not currently
|
|
13
|
+
// enforcing a length restriction on path segments.
|
|
14
|
+
// So `""`, `"foo"`, and `"foo.bar__baz.qux--quux"` are paths but `"."`,
|
|
15
|
+
// `"foo/bar"`, `"fo\to"`, and `"foö"` are not.
|
|
16
|
+
// This alphabet might be expanded in the future, but such expansion SHOULD NOT
|
|
17
|
+
// include control characters (including those that are not ASCII, such as
|
|
18
|
+
// U+202E RIGHT-TO-LEFT OVERRIDE), slash `/` (which separates ABCI request path
|
|
19
|
+
// segments in e.g. `custom/vstorage/data/foo`), or backslash `\` (which should
|
|
20
|
+
// be reserved for adding escape sequences).
|
|
13
21
|
//
|
|
14
22
|
// - An encoded key for a path is the path prefixed with its length (in ASCII
|
|
15
23
|
// digits), separated by nul, followed by the path with dots replaced with nul.
|
|
@@ -42,22 +50,26 @@ func EncodedKeyToPath(key []byte) string {
|
|
|
42
50
|
return string(pathBytes)
|
|
43
51
|
}
|
|
44
52
|
|
|
45
|
-
var
|
|
53
|
+
var pathSegmentPattern = `[a-zA-Z0-9_-]+`
|
|
54
|
+
var pathSeparatorPattern = `\` + PathSeparator
|
|
55
|
+
var pathPattern = fmt.Sprintf(`^$|^%[1]s(%[2]s%[1]s)*$`, pathSegmentPattern, pathSeparatorPattern)
|
|
56
|
+
var pathMatcher = regexp.MustCompile(pathPattern)
|
|
46
57
|
|
|
47
58
|
func ValidatePath(path string) error {
|
|
48
|
-
if
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
if strings.Contains(path, PathSeparator+PathSeparator) {
|
|
52
|
-
return fmt.Errorf("path %q contains doubled separators", path)
|
|
59
|
+
if pathMatcher.MatchString(path) {
|
|
60
|
+
return nil
|
|
53
61
|
}
|
|
62
|
+
// Rescan the string to give a useful error message.
|
|
54
63
|
if strings.HasPrefix(path, PathSeparator) {
|
|
55
64
|
return fmt.Errorf("path %q starts with separator", path)
|
|
56
65
|
}
|
|
57
66
|
if strings.HasSuffix(path, PathSeparator) {
|
|
58
67
|
return fmt.Errorf("path %q ends with separator", path)
|
|
59
68
|
}
|
|
60
|
-
|
|
69
|
+
if strings.Contains(path, PathSeparator+PathSeparator) {
|
|
70
|
+
return fmt.Errorf("path %q contains doubled separators", path)
|
|
71
|
+
}
|
|
72
|
+
return fmt.Errorf("path %q contains invalid characters", path)
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
// PathToEncodedKey converts a path to a byte slice key
|
|
@@ -2,40 +2,106 @@ package types
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"bytes"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strings"
|
|
5
7
|
"testing"
|
|
6
8
|
)
|
|
7
9
|
|
|
8
10
|
func Test_Key_Encoding(t *testing.T) {
|
|
9
11
|
tests := []struct {
|
|
10
|
-
name
|
|
11
|
-
|
|
12
|
-
key
|
|
12
|
+
name string
|
|
13
|
+
path string
|
|
14
|
+
key []byte
|
|
15
|
+
errContains string
|
|
13
16
|
}{
|
|
14
17
|
{
|
|
15
|
-
name:
|
|
16
|
-
|
|
17
|
-
key:
|
|
18
|
+
name: "empty path",
|
|
19
|
+
path: "",
|
|
20
|
+
key: []byte("0\x00"),
|
|
18
21
|
},
|
|
19
22
|
{
|
|
20
|
-
name:
|
|
21
|
-
|
|
22
|
-
key:
|
|
23
|
+
name: "single-segment path",
|
|
24
|
+
path: "some",
|
|
25
|
+
key: []byte("1\x00some"),
|
|
23
26
|
},
|
|
24
27
|
{
|
|
25
|
-
name:
|
|
26
|
-
|
|
27
|
-
key:
|
|
28
|
+
name: "multi-segment path",
|
|
29
|
+
path: "some.child.grandchild",
|
|
30
|
+
key: []byte("3\x00some\x00child\x00grandchild"),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "non-letters",
|
|
34
|
+
path: "-_0_-",
|
|
35
|
+
key: []byte("1\x00-_0_-"),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "lone dot",
|
|
39
|
+
path: ".",
|
|
40
|
+
errContains: "starts with separator",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "starts with dot",
|
|
44
|
+
path: ".foo",
|
|
45
|
+
errContains: "starts with separator",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "ends with dot",
|
|
49
|
+
path: "foo.",
|
|
50
|
+
errContains: "ends with separator",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "empty path segment",
|
|
54
|
+
path: "foo..bar",
|
|
55
|
+
errContains: "doubled separators",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "invalid path character U+0000 NUL",
|
|
59
|
+
path: "foo\x00bar",
|
|
60
|
+
errContains: "invalid character",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "invalid path character U+002F SOLIDUS",
|
|
64
|
+
path: "foo/bar",
|
|
65
|
+
errContains: "invalid character",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "invalid path character U+005C REVERSE SOLIDUS",
|
|
69
|
+
path: "foo\\bar",
|
|
70
|
+
errContains: "invalid character",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "invalid path character U+007C VERTICAL LINE",
|
|
74
|
+
path: "foo|bar",
|
|
75
|
+
errContains: "invalid character",
|
|
28
76
|
},
|
|
29
77
|
}
|
|
30
78
|
|
|
31
79
|
for _, tt := range tests {
|
|
80
|
+
if tt.key != nil {
|
|
81
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
82
|
+
if key := PathToEncodedKey(tt.path); !bytes.Equal(key, tt.key) {
|
|
83
|
+
t.Errorf("pathToKey(%q) = []byte(%q), want []byte(%q)", tt.path, key, tt.key)
|
|
84
|
+
}
|
|
85
|
+
if path := EncodedKeyToPath(tt.key); path != tt.path {
|
|
86
|
+
t.Errorf("keyToPath([]byte(%q)) = %q, want %q", tt.key, path, tt.path)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
expect := tt.errContains
|
|
32
92
|
t.Run(tt.name, func(t *testing.T) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
93
|
+
var key []byte
|
|
94
|
+
defer func() {
|
|
95
|
+
if err := recover(); err != nil {
|
|
96
|
+
errStr := fmt.Sprintf("%v", err)
|
|
97
|
+
if !strings.Contains(errStr, expect) {
|
|
98
|
+
t.Errorf("pathToKey(%q) = error %q, want error %v", tt.path, errStr, expect)
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
t.Errorf("pathToKey(%q) = []byte(%q), want error %v", tt.path, key, expect)
|
|
102
|
+
}
|
|
103
|
+
}()
|
|
104
|
+
key = PathToEncodedKey(tt.path)
|
|
39
105
|
})
|
|
40
106
|
}
|
|
41
107
|
}
|