Skip to content

Commit

Permalink
test: add the test case for invalid address (#88)
Browse files Browse the repository at this point in the history
* test: add test case to `QueryInactiveContracts`

* chore: add this pr for changelog.md

* test: add the test case for invalid address

* test: add the test case for invalid address

* chore: add this pr to CHANGE.log

* fix: Fix address judgment and pagination key

* feat: add the function for byte array to use addresses order check

* test: add func for make test data for addresses order

* fix: Add a function to create an ordered address array

Fix to create an ordered address array and test it as an expected value

* fix: fix lint error

* fix: add the error handling for lint

* fix: fix `Error: unreachable: unreachable code (govet)` for `golangci-lint`

* fix: fix panic message

* refactor: Changed []byte array comparison to string comparison

* fix: revert commit for go.mod go.sum

* fix: fix lint

* fix: fix lint

* fix: delete unnecessary code

* fix: rename function name and add a contract for order

* fix: Changed to equal judgment as before with wrap error as expected value

* test: add the invalid address test case to `TestQueryContractInfo` and `TestQueryContractHistory`
  • Loading branch information
Kynea0b authored Aug 23, 2023
1 parent 00c6a22 commit 36ce1d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [\#82](https://github.com/Finschia/wasmd/pull/82) add test case to QueryInactiveContracts
* [\#87](https://github.com/Finschia/wasmd/pull/87) add an integration test for TestExecuteContract
* [\#79](https://github.com/Finschia/wasmd/pull/79) add an integration test for TestStoreAndInstantiateContract
* [\#88](https://github.com/Finschia/wasmd/pull/88) add the test case for invalid address

### Bug Fixes
* [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field
Expand Down
27 changes: 27 additions & 0 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/cosmos/btcutil/bech32"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -55,6 +56,10 @@ func TestQueryAllContractState(t *testing.T) {
srcQuery: &types.QueryAllContractStateRequest{Address: RandomBech32AccountAddress(t)},
expErr: types.ErrNotFound,
},
"query all with invalid address": {
srcQuery: &types.QueryAllContractStateRequest{Address: "abcde"},
expErr: fmt.Errorf("decoding bech32 failed: %w", bech32.ErrInvalidLength(5)),
},
"with pagination offset": {
srcQuery: &types.QueryAllContractStateRequest{
Address: contractAddr.String(),
Expand Down Expand Up @@ -163,6 +168,10 @@ func TestQuerySmartContractState(t *testing.T) {
srcQuery: &types.QuerySmartContractStateRequest{Address: RandomBech32AccountAddress(t), QueryData: []byte(`{"verifier":{}}`)},
expErr: types.ErrNotFound,
},
"query smart with invalid address": {
srcQuery: &types.QuerySmartContractStateRequest{Address: "abcde", QueryData: []byte(`{"verifier":{}}`)},
expErr: bech32.ErrInvalidLength(5),
},
"with empty request": {
srcQuery: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
Expand Down Expand Up @@ -267,6 +276,10 @@ func TestQueryRawContractState(t *testing.T) {
srcQuery: &types.QueryRawContractStateRequest{Address: RandomBech32AccountAddress(t), QueryData: []byte("foo")},
expErr: types.ErrNotFound,
},
"query raw with invalid address": {
srcQuery: &types.QueryRawContractStateRequest{Address: "abcde", QueryData: []byte("foo")},
expErr: bech32.ErrInvalidLength(5),
},
"with empty request": {
srcQuery: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
Expand Down Expand Up @@ -633,6 +646,16 @@ func TestQueryContractHistory(t *testing.T) {
}},
expErr: types.ErrEmpty,
},
"query with invalid address": {
req: &types.QueryContractHistoryRequest{Address: "abcde"},
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeGenesis,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Msg: []byte(`"init message"`),
}},
expErr: fmt.Errorf("decoding bech32 failed: %w", bech32.ErrInvalidLength(5)),
},
"with empty request": {
req: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
Expand Down Expand Up @@ -872,6 +895,10 @@ func TestQueryContractInfo(t *testing.T) {
stored: types.ContractInfoFixture(),
expErr: types.ErrNotFound,
},
"query with invalid address": {
src: &types.QueryContractInfoRequest{Address: "abcde"},
expErr: bech32.ErrInvalidLength(5),
},
"with empty request": {
src: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
Expand Down

0 comments on commit 36ce1d3

Please sign in to comment.