Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add the test case for InactiveContract #75

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
}