Skip to content

Commit

Permalink
test: add the test case for InactiveContract
Browse files Browse the repository at this point in the history
  • Loading branch information
Kynea0b committed Aug 16, 2023
1 parent bdce468 commit a9de5ab
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions x/wasmplus/keeper/querier_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package keeper

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"testing"

sdk "github.com/Finschia/finschia-sdk/types"

wasmtypes "github.com/Finschia/wasmd/x/wasm/types"
"github.com/Finschia/wasmd/x/wasmplus/types"
)

Expand Down Expand Up @@ -36,24 +37,50 @@ func TestQueryInactiveContracts(t *testing.T) {
}
}

func TestQueryIsInactiveContract(t *testing.T) {
func TestQueryInactiveContract(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)
keeper := keepers.WasmKeeper

example := InstantiateHackatomExampleContract(t, ctx, keepers)

contractAddr := example.Contract
q := Querier(keeper)
rq := types.QueryInactiveContractRequest{Address: example.Contract.String()}
res, err := q.InactiveContract(sdk.WrapSDKContext(ctx), &rq)
require.NoError(t, err)
require.False(t, res.Inactivated)

// set inactive
err = keeper.deactivateContract(ctx, example.Contract)
require.NoError(t, err)
specs := map[string]struct {
srcQuery *types.QueryInactiveContractRequest
expInactivated bool
expErr error
}{
"query": {
srcQuery: &types.QueryInactiveContractRequest{Address: contractAddr.String()},
expInactivated: true,
},
"query with unknown address": {
srcQuery: &types.QueryInactiveContractRequest{Address: RandomBech32AccountAddress(t)},
expErr: wasmtypes.ErrNotFound,
},
"with empty request": {
srcQuery: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
},
}

rq = types.QueryInactiveContractRequest{Address: example.Contract.String()}
res, err = q.InactiveContract(sdk.WrapSDKContext(ctx), &rq)
require.NoError(t, err)
require.True(t, res.Inactivated)
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
got, err := q.InactiveContract(sdk.WrapSDKContext(ctx), spec.srcQuery)
if spec.expErr != nil {
require.Equal(t, spec.expErr, err, "but got %+v", err)
return
}
require.NoError(t, err)
require.False(t, got.Inactivated)

// set inactive
err = keeper.deactivateContract(ctx, example.Contract)
require.NoError(t, err)

got, err = q.InactiveContract(sdk.WrapSDKContext(ctx), spec.srcQuery)
require.NoError(t, err)
require.True(t, got.Inactivated)
})
}
}

0 comments on commit a9de5ab

Please sign in to comment.