Skip to content

Commit

Permalink
Fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jul 1, 2020
1 parent 8713c5c commit c5438b4
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 130 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
// Note: update ENV GO_COSMWASM in Dockerfile when updating this
github.com/CosmWasm/go-cosmwasm v0.9.1
github.com/cosmos/cosmos-sdk v0.34.4-0.20200530180557-ba70f4d4dc2e
github.com/gogo/protobuf v1.3.1
github.com/google/gofuzz v1.0.0
github.com/gorilla/mux v1.7.4
github.com/onsi/ginkgo v1.8.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200102211924-4bcbc698314f h1:4O1om+UVU+Hfcihr1timk8YNXHxzZWgCo7ofnrZRApw=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200102211924-4bcbc698314f/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/CosmWasm/go-cosmwasm v0.9.1 h1:w5s2o7H3cmNexct9yv8F6OLXwgxbdfVApwam7DibPqI=
github.com/CosmWasm/go-cosmwasm v0.9.1/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/CosmWasm/go-cosmwasm v0.8.1-0.20200604114456-1b2359bb7eb9 h1:UJOWFHfh2SG47GJcQsjbcEnfw7JM4HPM2cFO1fjjqEs=
github.com/CosmWasm/go-cosmwasm v0.8.1-0.20200604114456-1b2359bb7eb9/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/CosmWasm/go-cosmwasm v0.9.1 h1:w5s2o7H3cmNexct9yv8F6OLXwgxbdfVApwam7DibPqI=
github.com/CosmWasm/go-cosmwasm v0.9.1/go.mod h1:gAFCwllx97ejI+m9SqJQrmd2SBW7HA0fOjvWWJjM2uc=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func ClearContractAdminCmd(cdc *codec.Codec) *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)

contractAddr, err := sdk.AccAddressFromBech32(args[0])
Expand All @@ -101,7 +101,7 @@ func ClearContractAdminCmd(cdc *codec.Codec) *cobra.Command {
Sender: cliCtx.GetFromAddress(),
Contract: contractAddr,
}
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
return cmd
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func handleExecute(ctx sdk.Context, k Keeper, msg *MsgExecuteContract) (*sdk.Res
events = append(events, custom.ToABCIEvents()...)

res.Events = events
return &res, nil
return res, nil
}

func handleMigration(ctx sdk.Context, k Keeper, msg *MsgMigrateContract) (*sdk.Result, error) {
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/internal/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ func setupKeeper(t *testing.T) (Keeper, sdk.Context, func()) {
Time: time.Date(2020, time.April, 22, 12, 0, 0, 0, time.UTC),
}, false, log.NewNopLogger())

cdc := MakeTestCodec()
appCodec, _ := MakeTestCodec()
wasmConfig := wasmTypes.DefaultWasmConfig()

srcKeeper := NewKeeper(cdc, keyContract, auth.AccountKeeper{}, nil, staking.Keeper{}, nil, tempDir, wasmConfig, "", nil, nil)
srcKeeper := NewKeeper(appCodec, keyContract, auth.AccountKeeper{}, nil, staking.Keeper{}, nil, tempDir, wasmConfig, "", nil, nil)
return srcKeeper, ctx, cleanup
}
12 changes: 5 additions & 7 deletions x/wasm/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (k Keeper) importCode(ctx sdk.Context, codeID uint64, codeInfo types.CodeIn
return sdkerrors.Wrapf(types.ErrDuplicate, "duplicate code: %d", codeID)
}
// 0x01 | codeID (uint64) -> ContractInfo
store.Set(key, k.cdc.MustMarshalBinaryBare(codeInfo))
store.Set(key, k.cdc.MustMarshalBinaryBare(&codeInfo))
return nil
}

Expand Down Expand Up @@ -177,7 +177,7 @@ func (k Keeper) Instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A
}

// emit all events from this contract itself
_, events := types.CosmosResult(*res, contractAddress)
events := types.ParseEvents(res.Log, contractAddress)
ctx.EventManager().EmitEvents(events)

err = k.dispatchMessages(ctx, contractAddress, res.Messages)
Expand Down Expand Up @@ -234,9 +234,7 @@ func (k Keeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller
return nil, err
}

return &sdk.Result{
Data: res.Data,
}, nil
return &sdk.Result{Data: data}, nil
}

// Migrate allows to upgrade a contract to a new code with data migration.
Expand Down Expand Up @@ -277,7 +275,7 @@ func (k Keeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller
}

// emit all events from this contract migration itself
data, events := types.CosmosResult(*res, contractAddress)
events := types.ParseEvents(res.Log, contractAddress)
ctx.EventManager().EmitEvents(events)

contractInfo.UpdateCodeID(ctx, newCodeID)
Expand All @@ -287,7 +285,7 @@ func (k Keeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller
return nil, sdkerrors.Wrap(err, "dispatch")
}

return &sdk.Result{Data: data}, nil
return &sdk.Result{Data: res.Data}, nil
}

// UpdateContractAdmin sets the admin value on the ContractInfo. It must be a valid address (use ClearContractAdmin to remove it)
Expand Down
20 changes: 10 additions & 10 deletions x/wasm/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestInstantiate(t *testing.T) {
require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", addr.String())

gasAfter := ctx.GasMeter().GasConsumed()
require.Equal(t, uint64(0x11536), gasAfter-gasBefore)
require.Equal(t, uint64(0x1153c), gasAfter-gasBefore)

// ensure it is stored properly
info := keeper.GetContractInfo(ctx, addr)
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestExecute(t *testing.T) {

// make sure gas is properly deducted from ctx
gasAfter := ctx.GasMeter().GasConsumed()
require.Equal(t, uint64(0x11bef), gasAfter-gasBefore)
require.Equal(t, uint64(0x1130a), gasAfter-gasBefore)

// ensure bob now exists and got both payments released
bobAcct = accKeeper.GetAccount(ctx, bob)
Expand Down Expand Up @@ -592,11 +592,11 @@ func TestMigrateWithDispatchedMessage(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(tempDir)
ctx, keepers := CreateTestInput(t, false, tempDir, SupportedFeatures, nil, nil)
accKeeper, keeper := keepers.AccountKeeper, keepers.WasmKeeper
accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper

deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
creator := createFakeFundedAccount(ctx, accKeeper, deposit.Add(deposit...))
fred := createFakeFundedAccount(ctx, accKeeper, sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)))
creator := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, deposit.Add(deposit...))
fred := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)))

wasmCode, err := ioutil.ReadFile("./testdata/contract.wasm")
require.NoError(t, err)
Expand Down Expand Up @@ -645,7 +645,7 @@ func TestMigrateWithDispatchedMessage(t *testing.T) {
"Type": "transfer",
"Attr": []dict{
{"recipient": myPayoutAddr},
{"sender": contractAddr},
//{"sender": contractAddr},
{"amount": "100000denom"},
},
},
Expand All @@ -670,7 +670,7 @@ func TestMigrateWithDispatchedMessage(t *testing.T) {
require.Len(t, m, 0)

// and all deposit tokens sent to myPayoutAddr
balance := accKeeper.GetAccount(ctx, myPayoutAddr).GetCoins()
balance := bankKeeper.GetAllBalances(ctx, myPayoutAddr)
assert.Equal(t, deposit, balance)
}

Expand Down Expand Up @@ -779,12 +779,12 @@ func TestClearContractAdmin(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(tempDir)
ctx, keepers := CreateTestInput(t, false, tempDir, SupportedFeatures, nil, nil)
accKeeper, keeper := keepers.AccountKeeper, keepers.WasmKeeper
accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper

deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000))
creator := createFakeFundedAccount(ctx, accKeeper, deposit.Add(deposit...))
fred := createFakeFundedAccount(ctx, accKeeper, topUp)
creator := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, deposit.Add(deposit...))
fred := createFakeFundedAccount(t, ctx, accKeeper, bankKeeper, topUp)

wasmCode, err := ioutil.ReadFile("./testdata/contract.wasm")
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,5 @@ func handleExecute(ctx sdk.Context, k Keeper, msg *wasmTypes.MsgExecuteContract)
}

res.Events = ctx.EventManager().Events().ToABCIEvents()
return &res, nil
return res, nil
}
2 changes: 1 addition & 1 deletion x/wasm/internal/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c Code) ValidateBasic() error {
// Contract struct encompasses ContractAddress, ContractInfo, and ContractState
type Contract struct {
ContractAddress sdk.AccAddress `json:"contract_address"`
ContractInfo *ContractInfo `json:"contract_info"`
ContractInfo ContractInfo `json:"contract_info"`
ContractState []Model `json:"contract_state"`
}

Expand Down
9 changes: 1 addition & 8 deletions x/wasm/internal/types/msg.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -142,7 +140,7 @@ func (msg MsgMigrateContract) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender}
}

func (msg MsgUpdateAdministrator) Route() string {
func (msg MsgUpdateAdmin) Route() string {
return RouterKey
}

Expand Down Expand Up @@ -174,11 +172,6 @@ func (msg MsgUpdateAdmin) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender}
}

type MsgClearAdmin struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
Contract sdk.AccAddress `json:"contract" yaml:"contract"`
}

func (msg MsgClearAdmin) Route() string {
return RouterKey
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestInstantiateContractValidation(t *testing.T) {
}
}

func TestMsgUpdateAdministrator(t *testing.T) {
func TestMsgUpdateAdmin(t *testing.T) {
badAddress, err := sdk.AccAddressFromHex("012345")
require.NoError(t, err)
// proper address size
Expand Down
34 changes: 19 additions & 15 deletions x/wasm/internal/types/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package types

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
tmBytes "github.com/tendermint/tendermint/libs/bytes"
wasmTypes "github.com/CosmWasm/go-cosmwasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
tmBytes "github.com/tendermint/tendermint/libs/bytes"
)

const defaultLRUCacheSize = uint64(0)
Expand Down Expand Up @@ -172,21 +172,25 @@ const CustomEventType = "wasm"
const AttributeKeyContractAddr = "contract_address"

// CosmosResult converts from a Wasm Result type
func CosmosResult(wasmResult wasmTypes.Result, contractAddr sdk.AccAddress) ([]byte, sdk.Events) {
var events sdk.Events
if len(wasmResult.Log) > 0 {
// we always tag with the contract address issuing this event
attrs := []sdk.Attribute{sdk.NewAttribute(AttributeKeyContractAddr, contractAddr.String())}
for _, l := range wasmResult.Log {
// and reserve the contract_address key for our use (not contract)
if l.Key != AttributeKeyContractAddr {
attr := sdk.NewAttribute(l.Key, l.Value)
attrs = append(attrs, attr)
}
func CosmosResult(wasmResult wasmTypes.HandleResponse, contractAddr sdk.AccAddress) ([]byte, sdk.Events) {
return wasmResult.Data, ParseEvents(wasmResult.Log, contractAddr)
}

// ParseEvents converts wasm type LogAttribute to cosmos sdk events
func ParseEvents(log []wasmTypes.LogAttribute, contractAddr sdk.AccAddress) sdk.Events {
if len(log) == 0 {
return nil
}
// we always tag with the contract address issuing this event
attrs := []sdk.Attribute{sdk.NewAttribute(AttributeKeyContractAddr, contractAddr.String())}
for _, l := range log {
// and reserve the contract_address key for our use (not contract)
if l.Key != AttributeKeyContractAddr {
attr := sdk.NewAttribute(l.Key, l.Value)
attrs = append(attrs, attr)
}
events = sdk.Events{sdk.NewEvent(CustomEventType, attrs...)}
}
return []byte(wasmResult.Data), events
return sdk.Events{sdk.NewEvent(CustomEventType, attrs...)}
}

// WasmConfig is the extra config required for wasm
Expand Down
Loading

0 comments on commit c5438b4

Please sign in to comment.