Skip to content

Commit

Permalink
Merge branch 'main' into test/TestInstantiateContract2
Browse files Browse the repository at this point in the history
  • Loading branch information
da1suk8 authored Aug 17, 2023
2 parents 47a06b2 + 87f69d6 commit 5817116
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @da1suk8 @dudong2 @loloicci @kokeshiM0chi
* @da1suk8 @dudong2 @loloicci @kokeshiM0chi @170210
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
* [\#64](https://github.com/Finschia/wasmd/pull/64) test: add test cases to confirm output for PinnedCodes
* [\#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
* [\#74](https://github.com/Finschia/wasmd/pull/74) add event checking to TestInstantiateContract2

### Bug Fixes
* [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field
* [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci
Expand Down
26 changes: 26 additions & 0 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,32 @@ func TestQueryContractHistory(t *testing.T) {
}},
expPaginationTotal: 0,
},
"with pagination next key": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeInit,
CodeID: firstCodeID,
Updated: &types.AbsoluteTxPosition{BlockHeight: 1, TxIndex: 2},
Msg: []byte(`"init message"`),
}, {
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
Msg: []byte(`"migrate message 1"`),
}},
req: &types.QueryContractHistoryRequest{
Address: myContractBech32Addr,
Pagination: &query.PageRequest{
Key: fromBase64("AAAAAAAAAAI="),
},
},
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.ContractCodeHistoryOperationTypeMigrate,
CodeID: 2,
Updated: &types.AbsoluteTxPosition{BlockHeight: 3, TxIndex: 4},
Msg: []byte(`"migrate message 1"`),
}},
expPaginationTotal: 0,
},
"unknown contract address": {
req: &types.QueryContractHistoryRequest{Address: otherBech32Addr},
srcHistory: []types.ContractCodeHistoryEntry{{
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 5817116

Please sign in to comment.