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

Refactor to GRPC message server #366

Merged
merged 7 commits into from
Jan 8, 2021
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 @@ -6,6 +6,7 @@


**Features:**
- Refactor to GRPC message server [\#366](https://github.com/CosmWasm/wasmd/pull/366)
- Make it easy to initialize contracts in genesis file with new CLI commands[\#326](https://github.com/CosmWasm/wasmd/issues/326)
- Upgrade to WasmVM v0.13.0 [\#358](https://github.com/CosmWasm/wasmd/pull/358)
- Upgrade to cosmos-sdk v0.40.0-rc6 [\#354](https://github.com/CosmWasm/wasmd/pull/354)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')

# for dockerized protobuf tools
PROTO_CONTAINER := cosmwasm/prototools-docker:latest
PROTO_CONTAINER := cosmwasm/prototools-docker:v0.1.0
DOCKER_BUF := docker run --rm -v $(shell pwd)/buf.yaml:/workspace/buf.yaml -v $(shell go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk):/workspace/cosmos_sdk_dir -v $(shell pwd):/workspace/wasmd --workdir /workspace $(PROTO_CONTAINER)
HTTPS_GIT := https://github.com/CosmWasm/wasmd.git

Expand Down
451 changes: 277 additions & 174 deletions doc/proto.md

Large diffs are not rendered by default.

61 changes: 34 additions & 27 deletions x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,38 @@ var (
)

type (
ProposalType = types.ProposalType
GenesisState = types.GenesisState
Code = types.Code
Contract = types.Contract
MsgStoreCode = types.MsgStoreCode
MsgInstantiateContract = types.MsgInstantiateContract
MsgExecuteContract = types.MsgExecuteContract
MsgMigrateContract = types.MsgMigrateContract
MsgUpdateAdmin = types.MsgUpdateAdmin
MsgClearAdmin = types.MsgClearAdmin
Model = types.Model
CodeInfo = types.CodeInfo
ContractInfo = types.ContractInfo
CreatedAt = types.AbsoluteTxPosition
Config = types.WasmConfig
ContractInfoWithAddress = types.ContractInfoWithAddress
CodeInfoResponse = types.CodeInfoResponse
MessageHandler = keeper.MessageHandler
BankEncoder = keeper.BankEncoder
CustomEncoder = keeper.CustomEncoder
StakingEncoder = keeper.StakingEncoder
WasmEncoder = keeper.WasmEncoder
MessageEncoders = keeper.MessageEncoders
Keeper = keeper.Keeper
QueryHandler = keeper.QueryHandler
CustomQuerier = keeper.CustomQuerier
QueryPlugins = keeper.QueryPlugins
ProposalType = types.ProposalType
GenesisState = types.GenesisState
Code = types.Code
Contract = types.Contract
MsgStoreCode = types.MsgStoreCode
MsgStoreCodeResponse = types.MsgStoreCodeResponse
MsgInstantiateContract = types.MsgInstantiateContract
MsgInstantiateContractResponse = types.MsgInstantiateContractResponse
MsgExecuteContract = types.MsgExecuteContract
MsgExecuteContractResponse = types.MsgExecuteContractResponse
MsgMigrateContract = types.MsgMigrateContract
MsgMigrateContractResponse = types.MsgMigrateContractResponse
MsgUpdateAdmin = types.MsgUpdateAdmin
MsgUpdateAdminResponse = types.MsgUpdateAdminResponse
MsgClearAdmin = types.MsgClearAdmin
MsgClearAdminResponse = types.MsgClearAdminResponse
MsgServer = types.MsgServer
Model = types.Model
CodeInfo = types.CodeInfo
ContractInfo = types.ContractInfo
CreatedAt = types.AbsoluteTxPosition
Config = types.WasmConfig
ContractInfoWithAddress = types.ContractInfoWithAddress
CodeInfoResponse = types.CodeInfoResponse
MessageHandler = keeper.MessageHandler
BankEncoder = keeper.BankEncoder
CustomEncoder = keeper.CustomEncoder
StakingEncoder = keeper.StakingEncoder
WasmEncoder = keeper.WasmEncoder
MessageEncoders = keeper.MessageEncoders
Keeper = keeper.Keeper
QueryHandler = keeper.QueryHandler
CustomQuerier = keeper.CustomQuerier
QueryPlugins = keeper.QueryPlugins
)
33 changes: 33 additions & 0 deletions x/wasm/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package wasm

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"testing"
)

// ensure store code returns the expected response
func assertStoreCodeResponse(t *testing.T, data []byte, expected uint64) {
var pStoreResp MsgStoreCodeResponse
require.NoError(t, pStoreResp.Unmarshal(data))
require.Equal(t, pStoreResp.CodeID, expected)
}

// ensure execution returns the expected data
func assertExecuteResponse(t *testing.T, data []byte, expected []byte) {
var pExecResp MsgExecuteContractResponse
require.NoError(t, pExecResp.Unmarshal(data))
require.Equal(t, pExecResp.Data, expected)
}

// ensures this returns a valid bech32 address and returns it
func parseInitResponse(t *testing.T, data []byte) string {
var pInstResp MsgInstantiateContractResponse
require.NoError(t, pInstResp.Unmarshal(data))
require.NotEmpty(t, pInstResp.Address)
addr := pInstResp.Address
// ensure this is a valid sdk address
_, err := sdk.AccAddressFromBech32(addr)
require.NoError(t, err)
return addr
}
8 changes: 5 additions & 3 deletions x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func TestInitGenesis(t *testing.T) {
msg := MsgStoreCode{
Sender: creator.String(),
WASMByteCode: testContract,
Source: "https://github.com/CosmWasm/wasmd/blob/master/x/wasm/testdata/escrow.wasm",
Source: "https://github.com/CosmWasm/wasmd/blob/master/x/wasm/testdata/hackatom.wasm",
Builder: "confio/cosmwasm-opt:0.7.0",
}
err := msg.ValidateBasic()
require.NoError(t, err)

res, err := h(data.ctx, &msg)
require.NoError(t, err)
require.Equal(t, res.Data, []byte("1"))
assertStoreCodeResponse(t, res.Data, 1)

_, _, bob := keyPubAddr()
initMsg := initMsg{
Expand All @@ -48,7 +48,7 @@ func TestInitGenesis(t *testing.T) {
}
res, err = h(data.ctx, &initCmd)
require.NoError(t, err)
contractBech32Addr := string(res.Data)
contractBech32Addr := parseInitResponse(t, res.Data)

execCmd := MsgExecuteContract{
Sender: fred.String(),
Expand All @@ -58,6 +58,8 @@ func TestInitGenesis(t *testing.T) {
}
res, err = h(data.ctx, &execCmd)
require.NoError(t, err)
// from https://github.com/CosmWasm/cosmwasm/blob/master/contracts/hackatom/src/contract.rs#L167
assertExecuteResponse(t, res.Data, []byte{0xf0, 0x0b, 0xaa})

// ensure all contract state is as after init
assertCodeList(t, q, data.ctx, 1)
Expand Down
Loading