Skip to content

Commit

Permalink
fix(logic): fix linter and empty path error
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Mar 14, 2023
1 parent e9323fc commit db727a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 7 additions & 4 deletions x/logic/interpreter/fs/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down
12 changes: 10 additions & 2 deletions x/logic/interpreter/fs/wasm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//nolint:gocognit,lll
//nolint:lll
package fs

import (
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -131,7 +140,6 @@ func TestWasmHandler(t *testing.T) {
})
}
})

})
})
})
Expand Down

0 comments on commit db727a0

Please sign in to comment.