Skip to content

Commit

Permalink
test(logic): add more test for wasm handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Mar 14, 2023
1 parent d23c15f commit e9323fc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
4 changes: 2 additions & 2 deletions x/logic/interpreter/fs/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (w WasmFS) Open(ctx context.Context, uri *url.URL) ([]byte, error) {

paths := strings.SplitAfter(uri.Opaque, ":")
pathsLen := len(paths)
if pathsLen <= 1 {
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)
}

Expand All @@ -42,7 +42,7 @@ func (w WasmFS) Open(ctx context.Context, uri *url.URL) ([]byte, error) {
}

if !uri.Query().Has(queryKey) {
return nil, fmt.Errorf("uri should contains query params")
return nil, fmt.Errorf("uri should contains `query` params")
}
query := uri.Query().Get(queryKey)

Expand Down
69 changes: 52 additions & 17 deletions x/logic/interpreter/fs/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,57 @@ func TestWasmHandler(t *testing.T) {
uri: `cosmwasm:cw-storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
wantResult: []byte("calc(X) :- X is 100 + 200."),
},
//{
// contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
// query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
// data: []byte(""),
// canOpen: true,
// uri: `cosmwasm:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
// wantResult: []byte("\"\""),
//},
//{
// contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
// query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
// data: []byte(""),
// canOpen: true,
// uri: `cosmwasm:?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
// wantResult: []byte("\"\""),
//},
{
contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
data: []byte("Y2FsYyhYKSA6LSAgWCBpcyAxMDAgKyAyMDAu"),
canOpen: true,
uri: `cosmwasm:cw-storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
wantResult: []byte("\"\""),
wantError: fmt.Errorf("failed unmarshal json wasm response to string: invalid character 'Y' looking for beginning of value"),
},
{
contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
data: []byte("\"Y2FsYyhYKSA6LSAgWCBpcyAxMDAgKyAyMDAu\""),
canOpen: true,
uri: `cosmwasm:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
wantResult: []byte("calc(X) :- X is 100 + 200."),
},
{
contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
data: []byte("\"Y2FsYyhYKSA6LSAgWCBpcyAxMDAgKyAyMDAu\""),
canOpen: false,
uri: `okp4:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
},
{
contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
data: []byte("\"hey\""),
canOpen: true,
uri: `cosmwasm:cw-storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
wantResult: []byte("\"\""),
wantError: fmt.Errorf("failed decode wasm base64 respone: illegal base64 data at input byte 0"),
},
{
contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
data: []byte("\"hey\""),
canOpen: true,
uri: `cosmwasm:cw-storage?query=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
wantResult: []byte("\"\""),
wantError: fmt.Errorf("failed convert path 'cw-storage' to contract address: decoding bech32 failed: invalid separator index -1"),
},
{
contractAddress: "okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht",
query: []byte("{\"object_data\":{\"id\": \"4cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05\"}}"),
data: []byte("\"hey\""),
canOpen: true,
uri: `cosmwasm:cw-storage:okp415ekvz3qdter33mdnk98v8whv5qdr53yusksnfgc08xd26fpdn3ts8gddht?wasm=%7B%22object_data%22%3A%7B%22id%22%3A%20%224cbe36399aabfcc7158ee7a66cbfffa525bb0ceab33d1ff2cff08759fe0a9b05%22%7D%7D`,
wantResult: []byte("\"\""),
wantError: fmt.Errorf("uri should contains `query` params"),
},
}
for nc, tc := range cases {
Convey(fmt.Sprintf("Given the uri #%d: %s", nc, tc.uri), func() {
Expand Down Expand Up @@ -88,7 +123,7 @@ func TestWasmHandler(t *testing.T) {

if tc.wantError != nil {
So(err, ShouldNotBeNil)
So(err, ShouldEqual, tc.wantError.Error())
So(err.Error(), ShouldEqual, tc.wantError.Error())
} else {
So(err, ShouldBeNil)
So(data, ShouldResemble, tc.wantResult)
Expand Down

0 comments on commit e9323fc

Please sign in to comment.