Skip to content

Commit

Permalink
Merge branch 'main' into test/TestExecuteContract
Browse files Browse the repository at this point in the history
  • Loading branch information
da1suk8 committed Aug 22, 2023
2 parents eb647b8 + f36b389 commit e7682bb
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
* [\#78](https://github.com/Finschia/wasmd/pull/78) add the check for TestMigrateContract
* [\#69](https://github.com/Finschia/wasmd/pull/69) refactor: refactor test cases for Params
* [\#71](https://github.com/Finschia/wasmd/pull/71) add test cases in ContractsByCode
* [\#82](https://github.com/Finschia/wasmd/pull/82) add test case to QueryInactiveContracts
* [\#87](https://github.com/Finschia/wasmd/pull/87) add an integration test for TestExecuteContract

### 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
* [\#89](https://github.com/Finschia/wasmd/pull/89) fill ContractInfo querier result's Updated field
* [\#90](https://github.com/Finschia/wasmd/pull/90) delete output in TestQueryContractsByCode

### Breaking Changes

Expand All @@ -31,6 +34,7 @@

### Document Updates
* [\#54](https://github.com/Finschia/wasmd/pull/54) add documentation about errors (codespace and codes)
* [\#92](https://github.com/Finschia/wasmd/pull/92) modify links in x/wasmplus README.md


## [v0.1.4](https://github.com/Finschia/wasmd/releases/tag/v0.1.4) - 2023.05.22
Expand Down
4 changes: 3 additions & 1 deletion x/wasm/client/testutil/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractInfo() {

codeID, err := strconv.ParseUint(s.codeID, 10, 64)
s.Require().NoError(err)
s.Require().True(s.setupHeight > 0)
codeUpdateHeight := uint64(s.setupHeight)

testCases := map[string]struct {
args []string
Expand All @@ -158,7 +160,7 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractInfo() {
Creator: val.Address.String(),
Admin: val.Address.String(),
Label: "TestContract",
Created: nil,
Created: &types.AbsoluteTxPosition{BlockHeight: codeUpdateHeight, TxIndex: 0},
IBCPortID: "",
Extension: nil,
},
Expand Down
2 changes: 0 additions & 2 deletions x/wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ func queryContractInfo(ctx sdk.Context, addr sdk.AccAddress, keeper types.ViewKe
if info == nil {
return nil, types.ErrNotFound
}
// redact the Created field (just used for sorting, not part of public API)
info.Created = nil
return &types.QueryContractInfoResponse{
Address: addr.String(),
ContractInfo: *info,
Expand Down
13 changes: 4 additions & 9 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ func TestQueryContractsByCode(t *testing.T) {
adminAddr := contract.CreatorAddr
label := "demo contract to query"
contractAddr, _, err := keepers.ContractKeeper.Instantiate(ctx, contract.CodeID, contract.CreatorAddr, adminAddr, initMsgBz, label, initialAmount)
fmt.Println(contract.CodeID)
require.NoError(t, err)
return contractAddr
}
Expand Down Expand Up @@ -856,20 +855,16 @@ func TestQueryContractInfo(t *testing.T) {
src: &types.QueryContractInfoRequest{Address: contractAddr.String()},
stored: types.ContractInfoFixture(),
expRsp: &types.QueryContractInfoResponse{
Address: contractAddr.String(),
ContractInfo: types.ContractInfoFixture(func(info *types.ContractInfo) {
info.Created = nil // not returned on queries
}),
Address: contractAddr.String(),
ContractInfo: types.ContractInfoFixture(),
},
},
"with extension": {
src: &types.QueryContractInfoRequest{Address: contractAddr.String()},
stored: types.ContractInfoFixture(myExtension),
expRsp: &types.QueryContractInfoResponse{
Address: contractAddr.String(),
ContractInfo: types.ContractInfoFixture(myExtension, func(info *types.ContractInfo) {
info.Created = nil // not returned on queries
}),
Address: contractAddr.String(),
ContractInfo: types.ContractInfoFixture(myExtension),
},
},
"not found": {
Expand Down
6 changes: 3 additions & 3 deletions x/wasmplus/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# wasmplus

Extended module of [finschia/wasmd/x/wasm](https://github.com/Finschia/wasmd/tree/cae21ecd251cea44f56209e0a4586ca2979c6c87/x/wasm) module.
Extended module of [finschia/wasmd/x/wasm](../wasm) module.

## Concepts

Expand All @@ -26,10 +26,10 @@ Through `ActivateContractProposal`, you can release restrictions on the use of i
#### queries
##### InactiveContracts
* Query API to query a list of all disabled smart contract addresses with pagination
* [Detailed specification](../../docs/proto/proto-docs.md#activatecontractproposal)
* [Detailed specification](../../docs/proto/proto-docs.md#queryinactivecontractsrequest)
##### InactiveContract
* Query API to check if a specific smart contract address is disabled
* [Detailed specification](../../docs/proto/proto-docs.md#deactivatecontractproposal)
* [Detailed specification](../../docs/proto/proto-docs.md#queryinactivecontractrequest)

### Msg/StoreCodeAndInstantiateContract
`Msg/StoreCodeAndInstantiateContract` allows `StoreCode` and `InstantiateContract` to be processed as one tx message.
Expand Down
88 changes: 82 additions & 6 deletions x/wasmplus/keeper/querier_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package keeper

import (
"encoding/base64"
"fmt"
"github.com/Finschia/finschia-sdk/types/query"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
Expand All @@ -20,20 +23,85 @@ func TestQueryInactiveContracts(t *testing.T) {
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
example2 := InstantiateHackatomExampleContract(t, ctx, keepers)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
example3 := InstantiateHackatomExampleContract(t, ctx, keepers)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)

// Address order of contracts is ascending order of byte array whose address is decoded by bech32
expAddrs := GenerateSortedBech32Address(example1.Contract.Bytes(), example2.Contract.Bytes(), example3.Contract.Bytes())

// set inactive
err := keeper.deactivateContract(ctx, example1.Contract)
require.NoError(t, err)
err = keeper.deactivateContract(ctx, example2.Contract)
require.NoError(t, err)
err = keeper.deactivateContract(ctx, example3.Contract)
require.NoError(t, err)

q := Querier(keeper)
rq := types.QueryInactiveContractsRequest{}
res, err := q.InactiveContracts(sdk.WrapSDKContext(ctx), &rq)
require.NoError(t, err)
expect := []string{example1.Contract.String(), example2.Contract.String()}
for _, exp := range expect {
assert.Contains(t, res.Addresses, exp)
specs := map[string]struct {
srcQuery *types.QueryInactiveContractsRequest
expAddrs []string
expPaginationTotal uint64
expErr error
}{
"req nil": {
srcQuery: nil,
expErr: status.Error(codes.InvalidArgument, "empty request"),
},
"query all": {
srcQuery: &types.QueryInactiveContractsRequest{},
expAddrs: expAddrs,
expPaginationTotal: 3,
},
"with pagination offset": {
srcQuery: &types.QueryInactiveContractsRequest{
Pagination: &query.PageRequest{
Offset: 1,
},
},
expAddrs: []string{expAddrs[1], expAddrs[2]},
expPaginationTotal: 3,
},
"with invalid pagination key": {
srcQuery: &types.QueryInactiveContractsRequest{
Pagination: &query.PageRequest{
Offset: 1,
Key: []byte("test"),
},
},
expErr: fmt.Errorf("invalid request, either offset or key is expected, got both"),
},
"with pagination limit": {
srcQuery: &types.QueryInactiveContractsRequest{
Pagination: &query.PageRequest{
Limit: 1,
},
},
expAddrs: []string{expAddrs[0]},
expPaginationTotal: 0,
},
"with pagination next key": {
srcQuery: &types.QueryInactiveContractsRequest{
Pagination: &query.PageRequest{
Key: fromBase64("reSl9YA6Q5g1xjY5Wo1kje5XsvyQ2Y3Bf6iHFZtpY4s="),
},
},
expAddrs: []string{expAddrs[1], expAddrs[2]},
expPaginationTotal: 0,
},
}

for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
got, err := q.InactiveContracts(sdk.WrapSDKContext(ctx), spec.srcQuery)
if spec.expErr != nil {
require.Equal(t, spec.expErr, err, "but got %+v", err)
return
}
require.NoError(t, err)
assert.Equal(t, spec.expAddrs, got.Addresses)
assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total)
})
}
}

Expand Down Expand Up @@ -88,3 +156,11 @@ func TestQueryInactiveContract(t *testing.T) {
})
}
}

func fromBase64(s string) []byte {
r, err := base64.StdEncoding.DecodeString(s)
if err != nil {
panic(err)
}
return r
}
14 changes: 14 additions & 0 deletions x/wasmplus/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"os"
"sort"
"testing"
"time"

Expand Down Expand Up @@ -688,3 +689,16 @@ func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
addr := sdk.AccAddress(pub.Address())
return key, pub, addr
}

func GenerateSortedBech32Address(addrs ...[]byte) []string {
sort.Slice(addrs, func(i, j int) bool {
return string(addrs[i]) < string(addrs[j])
})

expAddrs := make([]string, len(addrs))
for i, b := range addrs {
expAddrs[i] = sdk.AccAddress(b).String()
}

return expAddrs
}

0 comments on commit e7682bb

Please sign in to comment.