Skip to content

Commit

Permalink
test: add the test case for invalid address
Browse files Browse the repository at this point in the history
  • Loading branch information
Kynea0b committed Aug 20, 2023
1 parent 87f69d6 commit 6e2e797
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 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: bech32.ErrInvalidLength(5),
},
"with pagination offset": {
srcQuery: &types.QueryAllContractStateRequest{
Address: contractAddr.String(),
Expand Down Expand Up @@ -119,6 +124,10 @@ 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 {
if errors.Is(err, spec.expErr) {
require.True(t, errors.Is(err, spec.expErr))
return
}
require.Equal(t, spec.expErr, err, "but got %+v", err)
return
}
Expand Down Expand Up @@ -163,6 +172,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

0 comments on commit 6e2e797

Please sign in to comment.