Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test case to QueryInactiveContracts #82

Merged
merged 18 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [\#73](https://github.com/Finschia/wasmd/pull/73) test: add the check for expPaginationTotal
* [\#72](https://github.com/Finschia/wasmd/pull/72) add pagination next key test in ContractHistory
* [\#75](https://github.com/Finschia/wasmd/pull/75) test: add the test case for InactiveContract
* [\#82](https://github.com/Finschia/wasmd/pull/82) test: add test case to QueryInactiveContracts

### Bug Fixes
* [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field
Expand Down
83 changes: 77 additions & 6 deletions x/wasmplus/keeper/querier_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package keeper

import (
"encoding/base64"
"fmt"
"github.com/Finschia/finschia-sdk/types/query"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -28,13 +31,81 @@ func TestQueryInactiveContracts(t *testing.T) {
require.NoError(t, err)

q := Querier(keeper)
rq := types.QueryInactiveContractsRequest{}
res, err := q.InactiveContracts(sdk.WrapSDKContext(ctx), &rq)
require.NoError(t, err)
expect := []string{example1.Contract.String(), example2.Contract.String()}
for _, exp := range expect {
assert.Contains(t, res.Addresses, exp)
specs := map[string]struct {
srcQuery *types.QueryInactiveContractsRequest
expAddrs []string
expPaginationTotal uint64
expErr error
}{
"req nil": {
srcQuery: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
},
"query all": {
srcQuery: &types.QueryInactiveContractsRequest{},
expAddrs: []string{example1.Contract.String(), example2.Contract.String()},
expPaginationTotal: 2,
},
"with pagination offset": {
srcQuery: &types.QueryInactiveContractsRequest{
Pagination: &query.PageRequest{
Offset: 1,
},
},
expAddrs: []string{example1.Contract.String()},
170210 marked this conversation as resolved.
Show resolved Hide resolved
expPaginationTotal: 2,
},
"with invalid pagination key": {
srcQuery: &types.QueryInactiveContractsRequest{
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.QueryInactiveContractsRequest{
Pagination: &query.PageRequest{
Limit: 1,
},
},
expAddrs: []string{example2.Contract.String()},
170210 marked this conversation as resolved.
Show resolved Hide resolved
expPaginationTotal: 0,
},
"with pagination next key": {
srcQuery: &types.QueryInactiveContractsRequest{
Pagination: &query.PageRequest{
Key: fromBase64("AAAAAAAAAAM="),
},
},
expAddrs: []string{},
170210 marked this conversation as resolved.
Show resolved Hide resolved
expPaginationTotal: 0,
},
}

for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
got, err := q.InactiveContracts(sdk.WrapSDKContext(ctx), spec.srcQuery)
if spec.expErr != nil {
require.Equal(t, spec.expErr, err, "but got %+v", err)
return
}
require.NoError(t, err)
for _, expAddr := range spec.expAddrs {
assert.Contains(t, got.Addresses, expAddr)
}
assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total)
})
}
}

func fromBase64(s string) []byte {
r, err := base64.StdEncoding.DecodeString(s)
if err != nil {
panic(err)
}
return r
}

func TestQueryInactiveContract(t *testing.T) {
Expand Down