Skip to content

Commit

Permalink
test: add test cases for invalid pagination key (#66)
Browse files Browse the repository at this point in the history
* test: add invalid pagination key test in AllContractState

Signed-off-by: 170210 <j170210@icloud.com>

* test: add invalid pagination key test in ContractHistory

Signed-off-by: 170210 <j170210@icloud.com>

* test: add invalid pagination key test in Codes

Signed-off-by: 170210 <j170210@icloud.com>

* chore: add this PR to CHANGELOG

Signed-off-by: 170210 <j170210@icloud.com>

---------

Signed-off-by: 170210 <j170210@icloud.com>
  • Loading branch information
170210 authored Aug 14, 2023
1 parent 1f60af6 commit a2607fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Improvements
* [\#63](https://github.com/Finschia/wasmd/pull/63) add event checking to TestStoreCode
* [\#65](https://github.com/Finschia/wasmd/pull/65) add test cases for empty request in each function
* [\#66](https://github.com/Finschia/wasmd/pull/66) add test cases for invalid pagination key in some functions

### Bug Fixes
* [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci
Expand Down
43 changes: 40 additions & 3 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ func TestQueryAllContractState(t *testing.T) {
{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)},
},
},
"with invalid pagination key": {
srcQuery: &types.QueryAllContractStateRequest{
Address: contractAddr.String(),
Pagination: &query.PageRequest{
Offset: 1,
Key: []byte("test"),
},
},
expErr: fmt.Errorf("invalid request, either offset or key is expected, got both"),
},
"with pagination limit": {
srcQuery: &types.QueryAllContractStateRequest{
Address: contractAddr.String(),
Expand Down Expand Up @@ -104,7 +114,7 @@ func TestQueryAllContractState(t *testing.T) {
t.Run(msg, func(t *testing.T) {
got, err := q.AllContractState(sdk.WrapSDKContext(ctx), spec.srcQuery)
if spec.expErr != nil {
require.True(t, errors.Is(err, spec.expErr), "but got %+v", err)
require.Equal(t, spec.expErr, err, "but got %+v", err)
return
}
for _, exp := range spec.expModelContains {
Expand Down Expand Up @@ -409,6 +419,23 @@ func TestQueryContractHistory(t *testing.T) {
Msg: []byte(`"migrate message 1"`),
}},
},
"with invalid pagination key": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeGenesis,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Msg: []byte(`"init message"`),
}},
req: &types.QueryContractHistoryRequest{
Address: myContractBech32Addr,
Pagination: &query.PageRequest{
Offset: 1,
Key: []byte("test"),
},
},
expErr: fmt.Errorf("invalid request, either offset or key is expected, got both"),
},

"with pagination limit": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
Expand Down Expand Up @@ -462,7 +489,7 @@ func TestQueryContractHistory(t *testing.T) {
// then
if spec.expErr != nil {
if err != nil {
assert.Equal(t, spec.expErr, err)
require.Equal(t, spec.expErr, err, "but got %+v", err)
} else {
require.Error(t, spec.expErr)
}
Expand Down Expand Up @@ -562,6 +589,16 @@ func TestQueryCodeList(t *testing.T) {
},
expCodeIDs: []uint64{2, 3},
},
"with invalid pagination key": {
storedCodeIDs: []uint64{1, 2, 3},
req: &types.QueryCodesRequest{
Pagination: &query.PageRequest{
Offset: 1,
Key: []byte("test"),
},
},
expErr: fmt.Errorf("invalid request, either offset or key is expected, got both"),
},
"with pagination limit": {
storedCodeIDs: []uint64{1, 2, 3},
req: &types.QueryCodesRequest{
Expand Down Expand Up @@ -601,7 +638,7 @@ func TestQueryCodeList(t *testing.T) {
got, err := q.Codes(sdk.WrapSDKContext(xCtx), spec.req)
// then
if spec.expErr != nil {
require.True(t, errors.Is(err, spec.expErr), "but got %+v", err)
require.Equal(t, spec.expErr, err, "but got %+v", err)
return
}
require.NoError(t, err)
Expand Down

0 comments on commit a2607fb

Please sign in to comment.