Skip to content

Commit

Permalink
test: add the test case for InactiveContract (#75)
Browse files Browse the repository at this point in the history
* test: add the test case for `InactiveContract`

* fix: add the change.log

* fix: Fixed the pre-setting to be done before test execution

For testing about inactiveContact
  • Loading branch information
Kynea0b authored Aug 17, 2023
1 parent 07aec27 commit 87f69d6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [\#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
* [\#72](https://github.com/Finschia/wasmd/pull/72) add pagination next key test in ContractHistory
* [\#75](https://github.com/Finschia/wasmd/pull/75) test: add the test case for InactiveContract

### Bug Fixes
* [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field
Expand Down
55 changes: 43 additions & 12 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,54 @@ 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)
rq := &types.QueryInactiveContractRequest{Address: example.Contract.String()}

// confirm that Contract is active
got, err := q.InactiveContract(sdk.WrapSDKContext(ctx), rq)
require.NoError(t, err)
require.False(t, res.Inactivated)
require.False(t, got.Inactivated)

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

rq = types.QueryInactiveContractRequest{Address: example.Contract.String()}
res, err = q.InactiveContract(sdk.WrapSDKContext(ctx), &rq)
require.NoError(t, err)
require.True(t, res.Inactivated)
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"),
},
}

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.True(t, got.Inactivated)
})
}
}

0 comments on commit 87f69d6

Please sign in to comment.