Skip to content

Commit

Permalink
test: add the check for expPaginationTotal (CosmWasm#73)
Browse files Browse the repository at this point in the history
* test: add the check for `expPaginationTotal`

* chore: add the pr for change.log

* fix: add test code for `expPaginationTotal`

* fix: Unify without setting expPaginationTotal when an error occurs

* Update x/wasm/keeper/querier_test.go

Co-authored-by: 170210 <85928898+170210@users.noreply.github.com>

* Update CHANGELOG.md

---------

Co-authored-by: 170210 <85928898+170210@users.noreply.github.com>
  • Loading branch information
Kynea0b and 170210 authored Aug 16, 2023
1 parent 8eca926 commit bdce468
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [\#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
* [\#70](https://github.com/Finschia/wasmd/pull/70) add event checking to TestInstantiateContract
* [\#73](https://github.com/Finschia/wasmd/pull/73) test: add the check for expPaginationTotal

### Bug Fixes
* [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field
Expand Down
62 changes: 42 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,7 @@ func TestQueryAllContractState(t *testing.T) {
for _, exp := range spec.expModelContainsNot {
assert.NotContains(t, got.Models, exp)
}
assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total)
})
}
}
Expand Down Expand Up @@ -344,10 +350,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 @@ -363,6 +370,7 @@ func TestQueryContractHistory(t *testing.T) {
Msg: []byte(`"init message"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
}},
expPaginationTotal: 1,
},
"response with multiple entries": {
srcHistory: []types.ContractCodeHistoryEntry{{
Expand Down Expand Up @@ -398,6 +406,7 @@ func TestQueryContractHistory(t *testing.T) {
Msg: []byte(`"migrate message 2"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 5, TxIndex: 6},
}},
expPaginationTotal: 3,
},
"with pagination offset": {
srcHistory: []types.ContractCodeHistoryEntry{{
Expand All @@ -423,6 +432,7 @@ func TestQueryContractHistory(t *testing.T) {
Msg: []byte(`"migrate message 1"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
}},
expPaginationTotal: 2,
},
"with invalid pagination key": {
srcHistory: []types.ContractCodeHistoryEntry{{
Expand Down Expand Up @@ -465,6 +475,7 @@ func TestQueryContractHistory(t *testing.T) {
Msg: []byte(`"init message"`),
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
}},
expPaginationTotal: 0,
},
"unknown contract address": {
req: &types.QueryContractHistoryRequest{Address: otherBech32Addr},
Expand Down Expand Up @@ -503,6 +514,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 @@ -568,23 +580,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 @@ -593,7 +609,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 @@ -612,7 +629,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 @@ -621,7 +639,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 @@ -650,6 +669,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 @@ -929,6 +949,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 @@ -955,6 +976,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

0 comments on commit bdce468

Please sign in to comment.