feat: Port x/wasm module #92

Closed
aleem1314 wants to merge 3 commits from aleem/25-wasmd into main
8 changed files with 73 additions and 84 deletions
Showing only changes of commit 34812d5e27 - Show all commits

View File

@ -16,7 +16,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli" "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
@ -68,7 +68,7 @@ func ProposalStoreCodeCmd() *cobra.Command {
CodeHash: codeHash, CodeHash: codeHash,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -172,7 +172,7 @@ func ProposalInstantiateContractCmd() *cobra.Command {
Funds: src.Funds, Funds: src.Funds,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -234,7 +234,7 @@ func ProposalInstantiateContract2Cmd() *cobra.Command {
content := types.NewInstantiateContract2Proposal(proposalTitle, proposalDescr, runAs, src.Admin, src.CodeID, src.Label, src.Msg, src.Funds, salt, fixMsg) content := types.NewInstantiateContract2Proposal(proposalTitle, proposalDescr, runAs, src.Admin, src.CodeID, src.Label, src.Msg, src.Funds, salt, fixMsg)
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -357,7 +357,7 @@ func ProposalStoreAndInstantiateContractCmd() *cobra.Command {
Funds: amount, Funds: amount,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -411,7 +411,7 @@ func ProposalMigrateContractCmd() *cobra.Command {
Msg: src.Msg, Msg: src.Msg,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -470,7 +470,7 @@ func ProposalExecuteContractCmd() *cobra.Command {
Funds: funds, Funds: funds,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -513,7 +513,7 @@ func ProposalSudoContractCmd() *cobra.Command {
Msg: sudoMsg, Msg: sudoMsg,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -556,7 +556,7 @@ func ProposalUpdateContractAdminCmd() *cobra.Command {
NewAdmin: src.NewAdmin, NewAdmin: src.NewAdmin,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -592,7 +592,7 @@ func ProposalClearContractAdminCmd() *cobra.Command {
Contract: args[0], Contract: args[0],
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -633,7 +633,7 @@ func ProposalPinCodesCmd() *cobra.Command {
CodeIDs: codeIds, CodeIDs: codeIds,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -686,7 +686,7 @@ func ProposalUnpinCodesCmd() *cobra.Command {
CodeIDs: codeIds, CodeIDs: codeIds,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }
@ -785,7 +785,7 @@ $ %s tx gov submit-proposal update-instantiate-config 1:nobody 2:everybody 3:%s1
Description: proposalDescr, Description: proposalDescr,
AccessConfigUpdates: updates, AccessConfigUpdates: updates,
} }
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) msg, err := govv1beta1.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress())
if err != nil { if err != nil {
return err return err
} }

View File

@ -7,7 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
) )
// RegisterLegacyAminoCodec registers the account types and interface // RegisterLegacyAminoCodec registers the account types and interface
@ -65,7 +65,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgUpdateInstantiateConfig{}, &MsgUpdateInstantiateConfig{},
) )
registry.RegisterImplementations( registry.RegisterImplementations(
(*govtypes.Content)(nil), (*govv1beta1.Content)(nil),
&StoreCodeProposal{}, &StoreCodeProposal{},
&InstantiateContractProposal{}, &InstantiateContractProposal{},
&InstantiateContract2Proposal{}, &InstantiateContract2Proposal{},

View File

@ -8,9 +8,9 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
connectiontypes "github.com/cosmos/ibc-go/v4/modules/core/03-connection/types" connectiontypes "github.com/cosmos/ibc-go/v5/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported" ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported"
) )
// BankViewKeeper defines a subset of methods implemented by the cosmos-sdk bank keeper // BankViewKeeper defines a subset of methods implemented by the cosmos-sdk bank keeper

View File

@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/rand"
@ -168,7 +168,7 @@ func TestGenesisContractInfoMarshalUnmarshal(t *testing.T) {
anyTime := time.Now().UTC() anyTime := time.Now().UTC()
// using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking // using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking
myExtension, err := govtypes.NewProposal(&govtypes.TextProposal{Title: "bar"}, 1, anyTime, anyTime) myExtension, err := govv1beta1.NewProposal(&govv1beta1.TextProposal{Title: "bar"}, 1, anyTime, anyTime)
require.NoError(t, err) require.NoError(t, err)
myExtension.TotalDeposit = nil myExtension.TotalDeposit = nil
@ -182,10 +182,10 @@ func TestGenesisContractInfoMarshalUnmarshal(t *testing.T) {
// register proposal as extension type // register proposal as extension type
interfaceRegistry.RegisterImplementations( interfaceRegistry.RegisterImplementations(
(*ContractInfoExtension)(nil), (*ContractInfoExtension)(nil),
&govtypes.Proposal{}, &govv1beta1.Proposal{},
) )
// register gov types for nested Anys // register gov types for nested Anys
govtypes.RegisterInterfaces(interfaceRegistry) govv1beta1.RegisterInterfaces(interfaceRegistry)
// when encode // when encode
gs := GenesisState{ gs := GenesisState{
@ -205,7 +205,7 @@ func TestGenesisContractInfoMarshalUnmarshal(t *testing.T) {
dest := destGs.Contracts[0].ContractInfo dest := destGs.Contracts[0].ContractInfo
assert.Equal(t, src, dest) assert.Equal(t, src, dest)
// and sanity check nested any // and sanity check nested any
var destExt govtypes.Proposal var destExt govv1beta1.Proposal
require.NoError(t, dest.ReadExtension(&destExt)) require.NoError(t, dest.ReadExtension(&destExt))
assert.Equal(t, destExt.GetTitle(), "bar") assert.Equal(t, destExt.GetTitle(), "bar")
} }

View File

@ -9,6 +9,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
) )
type ProposalType string type ProposalType string
@ -66,30 +67,18 @@ func ConvertToProposals(keys []string) ([]ProposalType, error) {
} }
func init() { // register new content types with the sdk func init() { // register new content types with the sdk
govtypes.RegisterProposalType(string(ProposalTypeStoreCode)) govv1beta1.RegisterProposalType(string(ProposalTypeStoreCode))
govtypes.RegisterProposalType(string(ProposalTypeInstantiateContract)) govv1beta1.RegisterProposalType(string(ProposalTypeInstantiateContract))
govtypes.RegisterProposalType(string(ProposalTypeInstantiateContract2)) govv1beta1.RegisterProposalType(string(ProposalTypeInstantiateContract2))
govtypes.RegisterProposalType(string(ProposalTypeMigrateContract)) govv1beta1.RegisterProposalType(string(ProposalTypeMigrateContract))
govtypes.RegisterProposalType(string(ProposalTypeSudoContract)) govv1beta1.RegisterProposalType(string(ProposalTypeSudoContract))
govtypes.RegisterProposalType(string(ProposalTypeExecuteContract)) govv1beta1.RegisterProposalType(string(ProposalTypeExecuteContract))
govtypes.RegisterProposalType(string(ProposalTypeUpdateAdmin)) govv1beta1.RegisterProposalType(string(ProposalTypeUpdateAdmin))
govtypes.RegisterProposalType(string(ProposalTypeClearAdmin)) govv1beta1.RegisterProposalType(string(ProposalTypeClearAdmin))
govtypes.RegisterProposalType(string(ProposalTypePinCodes)) govv1beta1.RegisterProposalType(string(ProposalTypePinCodes))
govtypes.RegisterProposalType(string(ProposalTypeUnpinCodes)) govv1beta1.RegisterProposalType(string(ProposalTypeUnpinCodes))
govtypes.RegisterProposalType(string(ProposalTypeUpdateInstantiateConfig)) govv1beta1.RegisterProposalType(string(ProposalTypeUpdateInstantiateConfig))
govtypes.RegisterProposalType(string(ProposalTypeStoreAndInstantiateContractProposal)) govv1beta1.RegisterProposalType(string(ProposalTypeStoreAndInstantiateContractProposal))
govtypes.RegisterProposalTypeCodec(&StoreCodeProposal{}, "wasm/StoreCodeProposal")
govtypes.RegisterProposalTypeCodec(&InstantiateContractProposal{}, "wasm/InstantiateContractProposal")
govtypes.RegisterProposalTypeCodec(&InstantiateContract2Proposal{}, "wasm/InstantiateContract2Proposal")
govtypes.RegisterProposalTypeCodec(&MigrateContractProposal{}, "wasm/MigrateContractProposal")
govtypes.RegisterProposalTypeCodec(&SudoContractProposal{}, "wasm/SudoContractProposal")
govtypes.RegisterProposalTypeCodec(&ExecuteContractProposal{}, "wasm/ExecuteContractProposal")
govtypes.RegisterProposalTypeCodec(&UpdateAdminProposal{}, "wasm/UpdateAdminProposal")
govtypes.RegisterProposalTypeCodec(&ClearAdminProposal{}, "wasm/ClearAdminProposal")
govtypes.RegisterProposalTypeCodec(&PinCodesProposal{}, "wasm/PinCodesProposal")
govtypes.RegisterProposalTypeCodec(&UnpinCodesProposal{}, "wasm/UnpinCodesProposal")
govtypes.RegisterProposalTypeCodec(&UpdateInstantiateConfigProposal{}, "wasm/UpdateInstantiateConfigProposal")
govtypes.RegisterProposalTypeCodec(&StoreAndInstantiateContractProposal{}, "wasm/StoreAndInstantiateContractProposal")
} }
func NewStoreCodeProposal( func NewStoreCodeProposal(
@ -915,8 +904,8 @@ func validateProposalCommons(title, description string) error {
if len(title) == 0 { if len(title) == 0 {
return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal title cannot be blank") return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal title cannot be blank")
} }
if len(title) > govtypes.MaxTitleLength { if len(title) > govv1beta1.MaxTitleLength {
return sdkerrors.Wrapf(govtypes.ErrInvalidProposalContent, "proposal title is longer than max length of %d", govtypes.MaxTitleLength) return sdkerrors.Wrapf(govtypes.ErrInvalidProposalContent, "proposal title is longer than max length of %d", govv1beta1.MaxTitleLength)
} }
if strings.TrimSpace(description) != description { if strings.TrimSpace(description) != description {
return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal description must not start/end with white spaces") return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal description must not start/end with white spaces")
@ -924,8 +913,8 @@ func validateProposalCommons(title, description string) error {
if len(description) == 0 { if len(description) == 0 {
return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal description cannot be blank") return sdkerrors.Wrap(govtypes.ErrInvalidProposalContent, "proposal description cannot be blank")
} }
if len(description) > govtypes.MaxDescriptionLength { if len(description) > govv1beta1.MaxDescriptionLength {
return sdkerrors.Wrapf(govtypes.ErrInvalidProposalContent, "proposal description is longer than max length of %d", govtypes.MaxDescriptionLength) return sdkerrors.Wrapf(govtypes.ErrInvalidProposalContent, "proposal description is longer than max length of %d", govv1beta1.MaxDescriptionLength)
} }
return nil return nil
} }

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -48,7 +48,7 @@ func TestValidateProposalCommons(t *testing.T) {
}, },
"prevent title exceeds max length ": { "prevent title exceeds max length ": {
src: commonProposal{ src: commonProposal{
Title: strings.Repeat("a", govtypes.MaxTitleLength+1), Title: strings.Repeat("a", govv1beta1.MaxTitleLength+1),
Description: "Bar", Description: "Bar",
}, },
expErr: true, expErr: true,
@ -76,7 +76,7 @@ func TestValidateProposalCommons(t *testing.T) {
"prevent descr exceeds max length ": { "prevent descr exceeds max length ": {
src: commonProposal{ src: commonProposal{
Title: "Foo", Title: "Foo",
Description: strings.Repeat("a", govtypes.MaxDescriptionLength+1), Description: strings.Repeat("a", govv1beta1.MaxDescriptionLength+1),
}, },
expErr: true, expErr: true,
}, },
@ -784,7 +784,7 @@ func TestValidateClearAdminProposal(t *testing.T) {
func TestProposalStrings(t *testing.T) { func TestProposalStrings(t *testing.T) {
specs := map[string]struct { specs := map[string]struct {
src govtypes.Content src govv1beta1.Content
exp string exp string
}{ }{
"store code": { "store code": {
@ -903,7 +903,7 @@ func TestProposalStrings(t *testing.T) {
func TestProposalYaml(t *testing.T) { func TestProposalYaml(t *testing.T) {
specs := map[string]struct { specs := map[string]struct {
src govtypes.Content src govv1beta1.Content
exp string exp string
}{ }{
"store code": { "store code": {
@ -1051,8 +1051,8 @@ func TestConvertToProposals(t *testing.T) {
func TestUnmarshalContentFromJson(t *testing.T) { func TestUnmarshalContentFromJson(t *testing.T) {
specs := map[string]struct { specs := map[string]struct {
src string src string
got govtypes.Content got govv1beta1.Content
exp govtypes.Content exp govv1beta1.Content
}{ }{
"instantiate ": { "instantiate ": {
src: ` src: `
@ -1109,7 +1109,7 @@ func TestUnmarshalContentFromJson(t *testing.T) {
func TestProposalJsonSignBytes(t *testing.T) { func TestProposalJsonSignBytes(t *testing.T) {
const myInnerMsg = `{"foo":"bar"}` const myInnerMsg = `{"foo":"bar"}`
specs := map[string]struct { specs := map[string]struct {
src govtypes.Content src govv1beta1.Content
exp string exp string
}{ }{
"instantiate contract": { "instantiate contract": {
@ -1131,7 +1131,7 @@ func TestProposalJsonSignBytes(t *testing.T) {
} }
for name, spec := range specs { for name, spec := range specs {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
msg, err := govtypes.NewMsgSubmitProposal(spec.src, sdk.NewCoins(), []byte{}) msg, err := govv1beta1.NewMsgSubmitProposal(spec.src, sdk.NewCoins(), []byte{})
require.NoError(t, err) require.NoError(t, err)
bz := msg.GetSignBytes() bz := msg.GetSignBytes()

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -15,7 +15,7 @@ import (
const firstCodeID = 1 const firstCodeID = 1
func TestStoreCodeValidation(t *testing.T) { func TestStoreCodeValidation(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size
@ -79,7 +79,7 @@ func TestStoreCodeValidation(t *testing.T) {
} }
func TestInstantiateContractValidation(t *testing.T) { func TestInstantiateContractValidation(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size
@ -187,7 +187,7 @@ func TestInstantiateContractValidation(t *testing.T) {
} }
func TestInstantiateContract2Validation(t *testing.T) { func TestInstantiateContract2Validation(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size
@ -323,7 +323,7 @@ func TestInstantiateContract2Validation(t *testing.T) {
} }
func TestExecuteContractValidation(t *testing.T) { func TestExecuteContractValidation(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size
@ -432,7 +432,7 @@ func TestExecuteContractValidation(t *testing.T) {
} }
func TestMsgUpdateAdministrator(t *testing.T) { func TestMsgUpdateAdministrator(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size
@ -504,7 +504,7 @@ func TestMsgUpdateAdministrator(t *testing.T) {
} }
func TestMsgClearAdministrator(t *testing.T) { func TestMsgClearAdministrator(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size
@ -555,7 +555,7 @@ func TestMsgClearAdministrator(t *testing.T) {
} }
func TestMsgMigrateContract(t *testing.T) { func TestMsgMigrateContract(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size
@ -681,7 +681,7 @@ func TestMsgJsonSignBytes(t *testing.T) {
} }
func TestMsgUpdateInstantiateConfig(t *testing.T) { func TestMsgUpdateInstantiateConfig(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345") bad, err := sdk.AccAddressFromHexUnsafe("012345")
require.NoError(t, err) require.NoError(t, err)
badAddress := bad.String() badAddress := bad.String()
// proper address size // proper address size

View File

@ -12,7 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/codec/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/rand"
@ -55,7 +55,7 @@ func TestContractInfoValidateBasic(t *testing.T) {
"invalid extension": { "invalid extension": {
srcMutator: func(c *ContractInfo) { srcMutator: func(c *ContractInfo) {
// any protobuf type with ValidateBasic method // any protobuf type with ValidateBasic method
any, err := codectypes.NewAnyWithValue(&govtypes.TextProposal{}) any, err := codectypes.NewAnyWithValue(&govv1beta1.TextProposal{})
require.NoError(t, err) require.NoError(t, err)
c.Extension = any c.Extension = any
}, },
@ -64,7 +64,7 @@ func TestContractInfoValidateBasic(t *testing.T) {
"not validatable extension": { "not validatable extension": {
srcMutator: func(c *ContractInfo) { srcMutator: func(c *ContractInfo) {
// any protobuf type with ValidateBasic method // any protobuf type with ValidateBasic method
any, err := codectypes.NewAnyWithValue(&govtypes.Proposal{}) any, err := codectypes.NewAnyWithValue(&govv1beta1.Proposal{})
require.NoError(t, err) require.NoError(t, err)
c.Extension = any c.Extension = any
}, },
@ -127,7 +127,7 @@ func TestContractInfoSetExtension(t *testing.T) {
anyTime := time.Now().UTC() anyTime := time.Now().UTC()
aNestedProtobufExt := func() ContractInfoExtension { aNestedProtobufExt := func() ContractInfoExtension {
// using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking // using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking
myExtension, err := govtypes.NewProposal(&govtypes.TextProposal{Title: "bar"}, 1, anyTime, anyTime) myExtension, err := govv1beta1.NewProposal(&govv1beta1.TextProposal{Title: "bar"}, 1, anyTime, anyTime)
require.NoError(t, err) require.NoError(t, err)
myExtension.TotalDeposit = nil myExtension.TotalDeposit = nil
return &myExtension return &myExtension
@ -146,10 +146,10 @@ func TestContractInfoSetExtension(t *testing.T) {
expNil: true, expNil: true,
}, },
"validated and accepted": { "validated and accepted": {
src: &govtypes.TextProposal{Title: "bar", Description: "set"}, src: &govv1beta1.TextProposal{Title: "bar", Description: "set"},
}, },
"validated and rejected": { "validated and rejected": {
src: &govtypes.TextProposal{Title: "bar"}, src: &govv1beta1.TextProposal{Title: "bar"},
expErr: true, expErr: true,
}, },
} }
@ -178,7 +178,7 @@ func TestContractInfoMarshalUnmarshal(t *testing.T) {
anyTime := time.Now().UTC() anyTime := time.Now().UTC()
// using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking // using gov proposal here as a random protobuf types as it contains an Any type inside for nested unpacking
myExtension, err := govtypes.NewProposal(&govtypes.TextProposal{Title: "bar"}, 1, anyTime, anyTime) myExtension, err := govv1beta1.NewProposal(&govv1beta1.TextProposal{Title: "bar"}, 1, anyTime, anyTime)
require.NoError(t, err) require.NoError(t, err)
myExtension.TotalDeposit = nil myExtension.TotalDeposit = nil
@ -192,10 +192,10 @@ func TestContractInfoMarshalUnmarshal(t *testing.T) {
// register proposal as extension type // register proposal as extension type
interfaceRegistry.RegisterImplementations( interfaceRegistry.RegisterImplementations(
(*ContractInfoExtension)(nil), (*ContractInfoExtension)(nil),
&govtypes.Proposal{}, &govv1beta1.Proposal{},
) )
// register gov types for nested Anys // register gov types for nested Anys
govtypes.RegisterInterfaces(interfaceRegistry) govv1beta1.RegisterInterfaces(interfaceRegistry)
// when encode // when encode
bz, err := marshaler.Marshal(&src) bz, err := marshaler.Marshal(&src)
@ -207,14 +207,14 @@ func TestContractInfoMarshalUnmarshal(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, src, dest) assert.Equal(t, src, dest)
// and sanity check nested any // and sanity check nested any
var destExt govtypes.Proposal var destExt govv1beta1.Proposal
require.NoError(t, dest.ReadExtension(&destExt)) require.NoError(t, dest.ReadExtension(&destExt))
assert.Equal(t, destExt.GetTitle(), "bar") assert.Equal(t, destExt.GetTitle(), "bar")
} }
func TestContractInfoReadExtension(t *testing.T) { func TestContractInfoReadExtension(t *testing.T) {
anyTime := time.Now().UTC() anyTime := time.Now().UTC()
myExtension, err := govtypes.NewProposal(&govtypes.TextProposal{Title: "foo"}, 1, anyTime, anyTime) myExtension, err := govv1beta1.NewProposal(&govv1beta1.TextProposal{Title: "foo"}, 1, anyTime, anyTime)
require.NoError(t, err) require.NoError(t, err)
type TestExtensionAsStruct struct { type TestExtensionAsStruct struct {
ContractInfoExtension ContractInfoExtension
@ -231,7 +231,7 @@ func TestContractInfoReadExtension(t *testing.T) {
i.SetExtension(&myExtension) i.SetExtension(&myExtension)
}, },
param: func() ContractInfoExtension { param: func() ContractInfoExtension {
return &govtypes.Proposal{} return &govv1beta1.Proposal{}
}, },
expVal: &myExtension, expVal: &myExtension,
}, },
@ -239,9 +239,9 @@ func TestContractInfoReadExtension(t *testing.T) {
setup: func(i *ContractInfo) { setup: func(i *ContractInfo) {
}, },
param: func() ContractInfoExtension { param: func() ContractInfoExtension {
return &govtypes.Proposal{} return &govv1beta1.Proposal{}
}, },
expVal: &govtypes.Proposal{}, expVal: &govv1beta1.Proposal{},
}, },
"nil argument value": { "nil argument value": {
setup: func(i *ContractInfo) { setup: func(i *ContractInfo) {
@ -257,7 +257,7 @@ func TestContractInfoReadExtension(t *testing.T) {
i.SetExtension(&myExtension) i.SetExtension(&myExtension)
}, },
param: func() ContractInfoExtension { param: func() ContractInfoExtension {
return &govtypes.TextProposal{} return &govv1beta1.TextProposal{}
}, },
expErr: true, expErr: true,
}, },