From db727a06dce0859a22f8ebdd3856b9d3fafc0aad Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Tue, 14 Mar 2023 15:09:53 +0100 Subject: [PATCH] fix(logic): fix linter and empty path error --- x/logic/interpreter/fs/wasm.go | 11 +++++++---- x/logic/interpreter/fs/wasm_test.go | 12 ++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/x/logic/interpreter/fs/wasm.go b/x/logic/interpreter/fs/wasm.go index c3de1526..7b2bda18 100644 --- a/x/logic/interpreter/fs/wasm.go +++ b/x/logic/interpreter/fs/wasm.go @@ -12,8 +12,10 @@ import ( "github.com/okp4/okp4d/x/logic/types" ) -const queryKey = "query" -const scheme = "cosmwasm" +const ( + queryKey = "query" + scheme = "cosmwasm" +) type WasmFS struct { wasmKeeper types.WasmKeeper @@ -32,8 +34,9 @@ func (w WasmFS) Open(ctx context.Context, uri *url.URL) ([]byte, error) { paths := strings.SplitAfter(uri.Opaque, ":") pathsLen := len(paths) - if pathsLen < 1 { - return nil, fmt.Errorf("incorect path, should contains eithier contract address or contract name and contract address : '%s:{contractName}:{contractAddr}?query={query}'", scheme) + if pathsLen < 1 || paths[pathsLen-1] == "" { + return nil, fmt.Errorf("emtpy path given, should be '%s:{contractName}:{contractAddr}?query={query}'", + scheme) } contractAddr, err := sdk.AccAddressFromBech32(paths[pathsLen-1]) diff --git a/x/logic/interpreter/fs/wasm_test.go b/x/logic/interpreter/fs/wasm_test.go index 0e55c058..6bffa21b 100644 --- a/x/logic/interpreter/fs/wasm_test.go +++ b/x/logic/interpreter/fs/wasm_test.go @@ -1,4 +1,4 @@ -//nolint:gocognit,lll +//nolint:lll package fs import ( @@ -89,6 +89,15 @@ func TestWasmHandler(t *testing.T) { wantResult: []byte("\"\""), wantError: fmt.Errorf("uri should contains `query` params"), }, + { + contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht", + query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"), + data: []byte("\"hey\""), + canOpen: true, + uri: `cosmwasm:?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`, + wantResult: []byte("\"\""), + wantError: fmt.Errorf("emtpy path given, should be 'cosmwasm:{contractName}:{contractAddr}?query={query}'"), + }, } for nc, tc := range cases { Convey(fmt.Sprintf("Given the uri #%d: %s", nc, tc.uri), func() { @@ -131,7 +140,6 @@ func TestWasmHandler(t *testing.T) { }) } }) - }) }) })