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 the check for expPaginationTotal #73

Merged
merged 7 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -10,6 +10,7 @@
* [\#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
* [\#64](https://github.com/Finschia/wasmd/pull/64) test: add test cases to confirm output for PinnedCodes
* [\#73](https://github.com/Finschia/wasmd/pull/73) test: add the check for expPaginationTotal

### Bug Fixes
* [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci
Expand Down
63 changes: 43 additions & 20 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ func TestQueryAllContractState(t *testing.T) {
srcQuery *types.QueryAllContractStateRequest
expModelContains []types.Model
expModelContainsNot []types.Model
expPaginationTotal uint64
expErr error
}{
"query all": {
srcQuery: &types.QueryAllContractStateRequest{Address: contractAddr.String()},
expModelContains: contractModel,
srcQuery: &types.QueryAllContractStateRequest{Address: contractAddr.String()},
expModelContains: contractModel,
expPaginationTotal: 3,
},
"query all with unknown address": {
srcQuery: &types.QueryAllContractStateRequest{Address: RandomBech32AccountAddress(t)},
Expand All @@ -66,6 +68,7 @@ func TestQueryAllContractState(t *testing.T) {
expModelContainsNot: []types.Model{
{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)},
},
expPaginationTotal: 3,
},
"with invalid pagination key": {
srcQuery: &types.QueryAllContractStateRequest{
Expand All @@ -90,6 +93,7 @@ func TestQueryAllContractState(t *testing.T) {
expModelContainsNot: []types.Model{
{Key: []byte("foo"), Value: []byte(`"bar"`)},
},
expPaginationTotal: 0,
},
"with pagination next key": {
srcQuery: &types.QueryAllContractStateRequest{
Expand All @@ -104,6 +108,7 @@ func TestQueryAllContractState(t *testing.T) {
expModelContainsNot: []types.Model{
{Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)},
},
expPaginationTotal: 0,
},
"with empty request": {
srcQuery: nil,
Expand All @@ -123,6 +128,8 @@ func TestQueryAllContractState(t *testing.T) {
for _, exp := range spec.expModelContainsNot {
assert.NotContains(t, got.Models, exp)
}
assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total)

Kynea0b marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Expand Down Expand Up @@ -344,10 +351,11 @@ func TestQueryContractHistory(t *testing.T) {
)

specs := map[string]struct {
srcHistory []types.ContractCodeHistoryEntry
req *types.QueryContractHistoryRequest
expContent []types.ContractCodeHistoryEntry
expErr error
srcHistory []types.ContractCodeHistoryEntry
req *types.QueryContractHistoryRequest
expContent []types.ContractCodeHistoryEntry
expPaginationTotal uint64
expErr error
}{
"response with internal fields cleared": {
srcHistory: []types.ContractCodeHistoryEntry{{
Expand All @@ -362,6 +370,7 @@ func TestQueryContractHistory(t *testing.T) {
CodeID: firstCodeID,
Msg: []byte(`"init message"`),
}},
expPaginationTotal: 1,
},
"response with multiple entries": {
srcHistory: []types.ContractCodeHistoryEntry{{
Expand Down Expand Up @@ -394,6 +403,7 @@ func TestQueryContractHistory(t *testing.T) {
CodeID: 3,
Msg: []byte(`"migrate message 2"`),
}},
expPaginationTotal: 3,
},
"with pagination offset": {
srcHistory: []types.ContractCodeHistoryEntry{{
Expand All @@ -418,6 +428,7 @@ func TestQueryContractHistory(t *testing.T) {
CodeID: 2,
Msg: []byte(`"migrate message 1"`),
}},
expPaginationTotal: 2,
},
"with invalid pagination key": {
srcHistory: []types.ContractCodeHistoryEntry{{
Expand Down Expand Up @@ -459,6 +470,7 @@ func TestQueryContractHistory(t *testing.T) {
CodeID: firstCodeID,
Msg: []byte(`"init message"`),
}},
expPaginationTotal: 0,
},
"unknown contract address": {
req: &types.QueryContractHistoryRequest{Address: otherBech32Addr},
Expand Down Expand Up @@ -497,6 +509,7 @@ func TestQueryContractHistory(t *testing.T) {
}
require.NoError(t, err)
assert.Equal(t, spec.expContent, got.Entries)
assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total)
})
}
}
Expand Down Expand Up @@ -562,23 +575,27 @@ func TestQueryCodeList(t *testing.T) {
keeper := keepers.WasmKeeper

specs := map[string]struct {
storedCodeIDs []uint64
req *types.QueryCodesRequest
expCodeIDs []uint64
expErr error
storedCodeIDs []uint64
req *types.QueryCodesRequest
expCodeIDs []uint64
expPaginationTotal uint64
expErr error
}{
"none": {
req: &types.QueryCodesRequest{},
req: &types.QueryCodesRequest{},
expPaginationTotal: 0,
},
"no gaps": {
storedCodeIDs: []uint64{1, 2, 3},
req: &types.QueryCodesRequest{},
expCodeIDs: []uint64{1, 2, 3},
storedCodeIDs: []uint64{1, 2, 3},
req: &types.QueryCodesRequest{},
expCodeIDs: []uint64{1, 2, 3},
expPaginationTotal: 3,
},
"with gaps": {
storedCodeIDs: []uint64{2, 4, 6},
req: &types.QueryCodesRequest{},
expCodeIDs: []uint64{2, 4, 6},
storedCodeIDs: []uint64{2, 4, 6},
req: &types.QueryCodesRequest{},
expCodeIDs: []uint64{2, 4, 6},
expPaginationTotal: 3,
},
"with pagination offset": {
storedCodeIDs: []uint64{1, 2, 3},
Expand All @@ -587,7 +604,8 @@ func TestQueryCodeList(t *testing.T) {
Offset: 1,
},
},
expCodeIDs: []uint64{2, 3},
expCodeIDs: []uint64{2, 3},
expPaginationTotal: 3,
},
"with invalid pagination key": {
storedCodeIDs: []uint64{1, 2, 3},
Expand All @@ -606,7 +624,8 @@ func TestQueryCodeList(t *testing.T) {
Limit: 2,
},
},
expCodeIDs: []uint64{1, 2},
expCodeIDs: []uint64{1, 2},
expPaginationTotal: 0,
},
"with pagination next key": {
storedCodeIDs: []uint64{1, 2, 3},
Expand All @@ -615,7 +634,8 @@ func TestQueryCodeList(t *testing.T) {
Key: fromBase64("AAAAAAAAAAI="),
},
},
expCodeIDs: []uint64{2, 3},
expCodeIDs: []uint64{2, 3},
expPaginationTotal: 0,
},
"with empty request": {
req: nil,
Expand Down Expand Up @@ -644,6 +664,7 @@ func TestQueryCodeList(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, got.CodeInfos)
require.Len(t, got.CodeInfos, len(spec.expCodeIDs))
assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total)
for i, exp := range spec.expCodeIDs {
assert.EqualValues(t, exp, got.CodeInfos[i].CodeID)
}
Expand Down Expand Up @@ -923,6 +944,7 @@ func TestQueryCodeInfoList(t *testing.T) {
codeInfo: codeInfoWithConfig(types.AccessTypeOnlyAddress.With(anyAddress)),
},
}
expPaginationTotal := 0

allCodesResponse := make([]types.CodeInfoResponse, 0)
for _, code := range codes {
Expand All @@ -949,6 +971,7 @@ func TestQueryCodeInfoList(t *testing.T) {
require.NoError(t, err)
require.Len(t, got.CodeInfos, 3)
require.EqualValues(t, allCodesResponse, got.CodeInfos)
assert.EqualValues(t, expPaginationTotal, got.Pagination.Total)
}

func fromBase64(s string) []byte {
Expand Down