diff --git a/x/wasm/client/cli/gov_tx.go b/x/wasm/client/cli/gov_tx.go index cb315e4ce4..56cb7eff9c 100644 --- a/x/wasm/client/cli/gov_tx.go +++ b/x/wasm/client/cli/gov_tx.go @@ -108,7 +108,7 @@ func ProposalInstantiateContractCmd(cdc *codec.Codec) *cobra.Command { }, RunAs: creator, Admin: src.Admin, - Code: src.Code, + CodeID: src.CodeID, Label: src.Label, InitMsg: src.InitMsg, InitFunds: src.InitFunds, @@ -171,7 +171,7 @@ func ProposalMigrateContractCmd(cdc *codec.Codec) *cobra.Command { Description: viper.GetString(cli.FlagDescription), }, Contract: src.Contract, - Code: src.Code, + CodeID: src.CodeID, MigrateMsg: src.MigrateMsg, RunAs: runAs, } diff --git a/x/wasm/client/cli/new_tx.go b/x/wasm/client/cli/new_tx.go index 756562f2da..fd47930901 100644 --- a/x/wasm/client/cli/new_tx.go +++ b/x/wasm/client/cli/new_tx.go @@ -55,7 +55,7 @@ func parseMigrateContractArgs(args []string, cliCtx context.CLIContext) (types.M msg := types.MsgMigrateContract{ Sender: cliCtx.GetFromAddress(), Contract: contractAddr, - Code: codeID, + CodeID: codeID, MigrateMsg: []byte(migrateMsg), } return msg, nil diff --git a/x/wasm/client/cli/tx.go b/x/wasm/client/cli/tx.go index d6c93ed8dc..0db2862fad 100644 --- a/x/wasm/client/cli/tx.go +++ b/x/wasm/client/cli/tx.go @@ -185,7 +185,7 @@ func parseInstantiateArgs(args []string, cliCtx context.CLIContext) (types.MsgIn // build and sign the transaction, then broadcast to Tendermint msg := types.MsgInstantiateContract{ Sender: cliCtx.GetFromAddress(), - Code: codeID, + CodeID: codeID, Label: label, InitFunds: amount, InitMsg: []byte(initMsg), diff --git a/x/wasm/client/rest/gov.go b/x/wasm/client/rest/gov.go index 41e0037df7..c274cafd61 100644 --- a/x/wasm/client/rest/gov.go +++ b/x/wasm/client/rest/gov.go @@ -91,7 +91,7 @@ func (s InstantiateProposalJsonReq) Content() gov.Content { WasmProposal: types.WasmProposal{Title: s.Title, Description: s.Description}, RunAs: s.RunAs, Admin: s.Admin, - Code: s.Code, + CodeID: s.Code, Label: s.Label, InitMsg: s.InitMsg, InitFunds: s.InitFunds, @@ -140,7 +140,7 @@ func (s MigrateProposalJsonReq) Content() gov.Content { return types.MigrateContractProposal{ WasmProposal: types.WasmProposal{Title: s.Title, Description: s.Description}, Contract: s.Contract, - Code: s.Code, + CodeID: s.Code, MigrateMsg: s.MigrateMsg, RunAs: s.RunAs, } diff --git a/x/wasm/client/rest/new_tx.go b/x/wasm/client/rest/new_tx.go index 7b872487dc..a4a74676b9 100644 --- a/x/wasm/client/rest/new_tx.go +++ b/x/wasm/client/rest/new_tx.go @@ -84,7 +84,7 @@ func migrateContractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { msg := types.MsgMigrateContract{ Sender: cliCtx.GetFromAddress(), Contract: contractAddress, - Code: req.CodeID, + CodeID: req.CodeID, MigrateMsg: req.MigrateMsg, } if err = msg.ValidateBasic(); err != nil { diff --git a/x/wasm/client/rest/tx.go b/x/wasm/client/rest/tx.go index 93976e7f4a..006f9f88ef 100644 --- a/x/wasm/client/rest/tx.go +++ b/x/wasm/client/rest/tx.go @@ -115,7 +115,7 @@ func instantiateContractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { msg := types.MsgInstantiateContract{ Sender: cliCtx.GetFromAddress(), - Code: codeID, + CodeID: codeID, InitFunds: req.Deposit, InitMsg: req.InitMsg, Admin: req.Admin, diff --git a/x/wasm/genesis_test.go b/x/wasm/genesis_test.go index 204779ca0a..1f5c523eb2 100644 --- a/x/wasm/genesis_test.go +++ b/x/wasm/genesis_test.go @@ -90,7 +90,7 @@ func TestInitGenesis(t *testing.T) { initCmd := MsgInstantiateContract{ Sender: creator, - Code: 1, + CodeID: 1, InitMsg: initMsgBz, InitFunds: deposit, } diff --git a/x/wasm/handler.go b/x/wasm/handler.go index 9af9624f96..f0a158ba9d 100644 --- a/x/wasm/handler.go +++ b/x/wasm/handler.go @@ -90,7 +90,7 @@ func handleStoreCode(ctx sdk.Context, k Keeper, msg *MsgStoreCode) (*sdk.Result, } func handleInstantiate(ctx sdk.Context, k Keeper, msg *MsgInstantiateContract) (*sdk.Result, error) { - contractAddr, err := k.Instantiate(ctx, msg.Code, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds) + contractAddr, err := k.Instantiate(ctx, msg.CodeID, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds) if err != nil { return nil, err } @@ -100,7 +100,7 @@ func handleInstantiate(ctx sdk.Context, k Keeper, msg *MsgInstantiateContract) ( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName), sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()), - sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", msg.Code)), + sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", msg.CodeID)), sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()), ) @@ -129,7 +129,7 @@ func handleExecute(ctx sdk.Context, k Keeper, msg *MsgExecuteContract) (*sdk.Res } func handleMigration(ctx sdk.Context, k Keeper, msg *MsgMigrateContract) (*sdk.Result, error) { - res, err := k.Migrate(ctx, msg.Contract, msg.Sender, msg.Code, msg.MigrateMsg) + res, err := k.Migrate(ctx, msg.Contract, msg.Sender, msg.CodeID, msg.MigrateMsg) if err != nil { return nil, err } diff --git a/x/wasm/internal/keeper/handler_plugin.go b/x/wasm/internal/keeper/handler_plugin.go index 6954190652..a8be89b4a7 100644 --- a/x/wasm/internal/keeper/handler_plugin.go +++ b/x/wasm/internal/keeper/handler_plugin.go @@ -218,7 +218,7 @@ func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmTypes.WasmMsg) ([]sdk.Msg, er sdkMsg := types.MsgInstantiateContract{ Sender: sender, - Code: msg.Instantiate.CodeID, + CodeID: msg.Instantiate.CodeID, // TODO: add this to CosmWasm Label: fmt.Sprintf("Auto-created by %s", sender), InitMsg: msg.Instantiate.Msg, diff --git a/x/wasm/internal/keeper/handler_plugin_test.go b/x/wasm/internal/keeper/handler_plugin_test.go index a016d35379..4351430683 100644 --- a/x/wasm/internal/keeper/handler_plugin_test.go +++ b/x/wasm/internal/keeper/handler_plugin_test.go @@ -139,7 +139,7 @@ func TestEncoding(t *testing.T) { output: []sdk.Msg{ types.MsgInstantiateContract{ Sender: addr1, - Code: 7, + CodeID: 7, // TODO: fix this Label: fmt.Sprintf("Auto-created by %s", addr1), InitMsg: jsonMsg, diff --git a/x/wasm/internal/keeper/proposal_handler.go b/x/wasm/internal/keeper/proposal_handler.go index 97b89e3dec..047c292316 100644 --- a/x/wasm/internal/keeper/proposal_handler.go +++ b/x/wasm/internal/keeper/proposal_handler.go @@ -63,7 +63,7 @@ func handleInstantiateProposal(ctx sdk.Context, k Keeper, p types.InstantiateCon return err } - contractAddr, err := k.instantiate(ctx, p.Code, p.RunAs, p.Admin, p.InitMsg, p.Label, p.InitFunds, GovAuthorizationPolicy{}) + contractAddr, err := k.instantiate(ctx, p.CodeID, p.RunAs, p.Admin, p.InitMsg, p.Label, p.InitFunds, GovAuthorizationPolicy{}) if err != nil { return err } @@ -71,7 +71,7 @@ func handleInstantiateProposal(ctx sdk.Context, k Keeper, p types.InstantiateCon ourEvent := sdk.NewEvent( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", p.Code)), + sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", p.CodeID)), sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()), ) ctx.EventManager().EmitEvent(ourEvent) @@ -83,7 +83,7 @@ func handleMigrateProposal(ctx sdk.Context, k Keeper, p types.MigrateContractPro return err } - res, err := k.migrate(ctx, p.Contract, p.RunAs, p.Code, p.MigrateMsg, GovAuthorizationPolicy{}) + res, err := k.migrate(ctx, p.Contract, p.RunAs, p.CodeID, p.MigrateMsg, GovAuthorizationPolicy{}) if err != nil { return err } diff --git a/x/wasm/internal/keeper/proposal_integration_test.go b/x/wasm/internal/keeper/proposal_integration_test.go index 9feee2dc73..9557b05ac2 100644 --- a/x/wasm/internal/keeper/proposal_integration_test.go +++ b/x/wasm/internal/keeper/proposal_integration_test.go @@ -79,7 +79,7 @@ func TestInstantiateProposal(t *testing.T) { otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, sdk.AddrLen) ) src := types.InstantiateContractProposalFixture(func(p *types.InstantiateContractProposal) { - p.Code = 1 + p.CodeID = 1 p.RunAs = oneAddress p.Admin = otherAddress p.Label = "testing" @@ -149,7 +149,7 @@ func TestMigrateProposal(t *testing.T) { Title: "Foo", Description: "Bar", }, - Code: 2, + CodeID: 2, Contract: contractAddr, MigrateMsg: migMsgBz, RunAs: otherAddress, diff --git a/x/wasm/internal/keeper/test_common.go b/x/wasm/internal/keeper/test_common.go index 91a721a4d9..07b348bb21 100644 --- a/x/wasm/internal/keeper/test_common.go +++ b/x/wasm/internal/keeper/test_common.go @@ -228,7 +228,7 @@ func TestHandler(k Keeper) sdk.Handler { } func handleInstantiate(ctx sdk.Context, k Keeper, msg *wasmtypes.MsgInstantiateContract) (*sdk.Result, error) { - contractAddr, err := k.Instantiate(ctx, msg.Code, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds) + contractAddr, err := k.Instantiate(ctx, msg.CodeID, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds) if err != nil { return nil, err } diff --git a/x/wasm/internal/types/msg.go b/x/wasm/internal/types/msg.go index 88c7a2dc29..2559597d44 100644 --- a/x/wasm/internal/types/msg.go +++ b/x/wasm/internal/types/msg.go @@ -63,7 +63,7 @@ type MsgInstantiateContract struct { Sender sdk.AccAddress `json:"sender" yaml:"sender"` // Admin is an optional address that can execute migrations Admin sdk.AccAddress `json:"admin,omitempty" yaml:"admin"` - Code uint64 `json:"code_id" yaml:"code_id"` + CodeID uint64 `json:"code_id" yaml:"code_id"` Label string `json:"label" yaml:"label"` InitMsg json.RawMessage `json:"init_msg" yaml:"init_msg"` InitFunds sdk.Coins `json:"init_funds" yaml:"init_funds"` @@ -82,7 +82,7 @@ func (msg MsgInstantiateContract) ValidateBasic() error { return err } - if msg.Code == 0 { + if msg.CodeID == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required") } @@ -150,7 +150,7 @@ func (msg MsgExecuteContract) GetSigners() []sdk.AccAddress { type MsgMigrateContract struct { Sender sdk.AccAddress `json:"sender" yaml:"sender"` Contract sdk.AccAddress `json:"contract" yaml:"contract"` - Code uint64 `json:"code_id" yaml:"code_id"` + CodeID uint64 `json:"code_id" yaml:"code_id"` MigrateMsg json.RawMessage `json:"msg" yaml:"msg"` } @@ -163,7 +163,7 @@ func (msg MsgMigrateContract) Type() string { } func (msg MsgMigrateContract) ValidateBasic() error { - if msg.Code == 0 { + if msg.CodeID == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required") } if err := sdk.VerifyAddressFormat(msg.Sender); err != nil { diff --git a/x/wasm/internal/types/msg_test.go b/x/wasm/internal/types/msg_test.go index 588cf565a7..b0848e7f95 100644 --- a/x/wasm/internal/types/msg_test.go +++ b/x/wasm/internal/types/msg_test.go @@ -146,7 +146,7 @@ func TestInstantiateContractValidation(t *testing.T) { "correct minimal": { msg: MsgInstantiateContract{ Sender: goodAddress, - Code: 1, + CodeID: 1, Label: "foo", InitMsg: []byte("{}"), }, @@ -177,7 +177,7 @@ func TestInstantiateContractValidation(t *testing.T) { "bad sender minimal": { msg: MsgInstantiateContract{ Sender: badAddress, - Code: 1, + CodeID: 1, Label: "foo", InitMsg: []byte("{}"), }, @@ -186,7 +186,7 @@ func TestInstantiateContractValidation(t *testing.T) { "correct maximal": { msg: MsgInstantiateContract{ Sender: goodAddress, - Code: 1, + CodeID: 1, Label: "foo", InitMsg: []byte(`{"some": "data"}`), InitFunds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}}, @@ -196,7 +196,7 @@ func TestInstantiateContractValidation(t *testing.T) { "negative funds": { msg: MsgInstantiateContract{ Sender: goodAddress, - Code: 1, + CodeID: 1, Label: "foo", InitMsg: []byte(`{"some": "data"}`), // we cannot use sdk.NewCoin() constructors as they panic on creating invalid data (before we can test) @@ -354,7 +354,7 @@ func TestMsgMigrateContract(t *testing.T) { src: MsgMigrateContract{ Sender: goodAddress, Contract: anotherGoodAddress, - Code: 1, + CodeID: 1, MigrateMsg: []byte{1}, }, }, @@ -362,21 +362,21 @@ func TestMsgMigrateContract(t *testing.T) { src: MsgMigrateContract{ Sender: goodAddress, Contract: anotherGoodAddress, - Code: 1, + CodeID: 1, }, }, "bad sender": { src: MsgMigrateContract{ Sender: badAddress, Contract: anotherGoodAddress, - Code: 1, + CodeID: 1, }, expErr: true, }, "empty sender": { src: MsgMigrateContract{ Contract: anotherGoodAddress, - Code: 1, + CodeID: 1, }, expErr: true, }, @@ -391,14 +391,14 @@ func TestMsgMigrateContract(t *testing.T) { src: MsgMigrateContract{ Sender: goodAddress, Contract: badAddress, - Code: 1, + CodeID: 1, }, expErr: true, }, "empty contract addr": { src: MsgMigrateContract{ Sender: goodAddress, - Code: 1, + CodeID: 1, }, expErr: true, }, diff --git a/x/wasm/internal/types/proposal.go b/x/wasm/internal/types/proposal.go index 39e29dee60..b690a81b77 100644 --- a/x/wasm/internal/types/proposal.go +++ b/x/wasm/internal/types/proposal.go @@ -167,7 +167,7 @@ type InstantiateContractProposal struct { RunAs sdk.AccAddress `json:"run_as"` // Admin is an optional address that can execute migrations Admin sdk.AccAddress `json:"admin,omitempty"` - Code uint64 `json:"code_id"` + CodeID uint64 `json:"code_id"` Label string `json:"label"` InitMsg json.RawMessage `json:"init_msg"` InitFunds sdk.Coins `json:"init_funds"` @@ -187,7 +187,7 @@ func (p InstantiateContractProposal) ValidateBasic() error { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "run as") } - if p.Code == 0 { + if p.CodeID == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required") } @@ -219,7 +219,7 @@ func (p InstantiateContractProposal) String() string { Label: %s InitMsg: %q InitFunds: %s -`, p.Title, p.Description, p.RunAs, p.Admin, p.Code, p.Label, p.InitMsg, p.InitFunds) +`, p.Title, p.Description, p.RunAs, p.Admin, p.CodeID, p.Label, p.InitMsg, p.InitFunds) } func (p InstantiateContractProposal) MarshalYAML() (interface{}, error) { @@ -227,7 +227,7 @@ func (p InstantiateContractProposal) MarshalYAML() (interface{}, error) { WasmProposal `yaml:",inline"` RunAs sdk.AccAddress `yaml:"run_as"` Admin sdk.AccAddress `yaml:"admin"` - Code uint64 `yaml:"code_id"` + CodeID uint64 `yaml:"code_id"` Label string `yaml:"label"` InitMsg string `yaml:"init_msg"` InitFunds sdk.Coins `yaml:"init_funds"` @@ -235,7 +235,7 @@ func (p InstantiateContractProposal) MarshalYAML() (interface{}, error) { WasmProposal: p.WasmProposal, RunAs: p.RunAs, Admin: p.Admin, - Code: p.Code, + CodeID: p.CodeID, Label: p.Label, InitMsg: string(p.InitMsg), InitFunds: p.InitFunds, @@ -246,7 +246,7 @@ func (p InstantiateContractProposal) MarshalYAML() (interface{}, error) { type MigrateContractProposal struct { WasmProposal `yaml:",inline"` Contract sdk.AccAddress `json:"contract"` - Code uint64 `json:"code_id"` + CodeID uint64 `json:"code_id"` MigrateMsg json.RawMessage `json:"msg"` // RunAs is the address that is passed to the contract's environment as sender RunAs sdk.AccAddress `json:"run_as"` @@ -260,7 +260,7 @@ func (p MigrateContractProposal) ValidateBasic() error { if err := p.WasmProposal.ValidateBasic(); err != nil { return err } - if p.Code == 0 { + if p.CodeID == 0 { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required") } if err := sdk.VerifyAddressFormat(p.Contract); err != nil { @@ -281,20 +281,20 @@ func (p MigrateContractProposal) String() string { Code id: %d Run as: %s MigrateMsg %q -`, p.Title, p.Description, p.Contract, p.Code, p.RunAs, p.MigrateMsg) +`, p.Title, p.Description, p.Contract, p.CodeID, p.RunAs, p.MigrateMsg) } func (p MigrateContractProposal) MarshalYAML() (interface{}, error) { return struct { WasmProposal `yaml:",inline"` Contract sdk.AccAddress `yaml:"contract"` - Code uint64 `yaml:"code_id"` + CodeID uint64 `yaml:"code_id"` MigrateMsg string `yaml:"msg"` RunAs sdk.AccAddress `yaml:"run_as"` }{ WasmProposal: p.WasmProposal, Contract: p.Contract, - Code: p.Code, + CodeID: p.CodeID, MigrateMsg: string(p.MigrateMsg), RunAs: p.RunAs, }, nil diff --git a/x/wasm/internal/types/proposal_test.go b/x/wasm/internal/types/proposal_test.go index 151e4ac8d5..3616287363 100644 --- a/x/wasm/internal/types/proposal_test.go +++ b/x/wasm/internal/types/proposal_test.go @@ -228,7 +228,7 @@ func TestValidateInstantiateContractProposal(t *testing.T) { }, "code id empty": { src: InstantiateContractProposalFixture(func(p *InstantiateContractProposal) { - p.Code = 0 + p.CodeID = 0 }), expErr: true, }, @@ -300,7 +300,7 @@ func TestValidateMigrateContractProposal(t *testing.T) { }, "code id empty": { src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.Code = 0 + p.CodeID = 0 }), expErr: true, }, diff --git a/x/wasm/internal/types/test_fixtures.go b/x/wasm/internal/types/test_fixtures.go index 555147377e..b614248f52 100644 --- a/x/wasm/internal/types/test_fixtures.go +++ b/x/wasm/internal/types/test_fixtures.go @@ -154,7 +154,7 @@ func InstantiateContractProposalFixture(mutators ...func(p *InstantiateContractP }, RunAs: anyValidAddress, Admin: anyValidAddress, - Code: 1, + CodeID: 1, Label: "testing", InitMsg: initMsgBz, InitFunds: nil, @@ -190,7 +190,7 @@ func MigrateContractProposalFixture(mutators ...func(p *MigrateContractProposal) Description: "Bar", }, Contract: contractAddr, - Code: 1, + CodeID: 1, MigrateMsg: migMsgBz, RunAs: anyValidAddress, } diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index 571175e3a1..37ae4c0170 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -171,7 +171,7 @@ func TestHandleInstantiate(t *testing.T) { // create with no balance is also legal initCmd := MsgInstantiateContract{ Sender: creator, - Code: 1, + CodeID: 1, InitMsg: initMsgBz, InitFunds: nil, } @@ -228,7 +228,7 @@ func TestHandleExecute(t *testing.T) { initCmd := MsgInstantiateContract{ Sender: creator, - Code: 1, + CodeID: 1, InitMsg: initMsgBz, InitFunds: deposit, } @@ -339,7 +339,7 @@ func TestHandleExecuteEscrow(t *testing.T) { initCmd := MsgInstantiateContract{ Sender: creator, - Code: 1, + CodeID: 1, InitMsg: initMsgBz, InitFunds: deposit, }