diff --git a/x/wasm/types/codec.go b/x/wasm/types/codec.go index 007f42ed4b..1d2114a576 100644 --- a/x/wasm/types/codec.go +++ b/x/wasm/types/codec.go @@ -17,12 +17,14 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { //nolint:staticcheck cdc.RegisterConcrete(&MsgMigrateContract{}, "wasm/MsgMigrateContract", nil) cdc.RegisterConcrete(&MsgUpdateAdmin{}, "wasm/MsgUpdateAdmin", nil) cdc.RegisterConcrete(&MsgClearAdmin{}, "wasm/MsgClearAdmin", nil) + cdc.RegisterConcrete(&PinCodesProposal{}, "wasm/PinCodesProposal", nil) cdc.RegisterConcrete(&UnpinCodesProposal{}, "wasm/UnpinCodesProposal", nil) - cdc.RegisterConcrete(&StoreCodeProposal{}, "wasm/StoreCodeProposal", nil) cdc.RegisterConcrete(&InstantiateContractProposal{}, "wasm/InstantiateContractProposal", nil) cdc.RegisterConcrete(&MigrateContractProposal{}, "wasm/MigrateContractProposal", nil) + cdc.RegisterConcrete(&SudoContractProposal{}, "wasm/SudoContractProposal", nil) + cdc.RegisterConcrete(&ExecuteContractProposal{}, "wasm/ExecuteContractProposal", nil) cdc.RegisterConcrete(&UpdateAdminProposal{}, "wasm/UpdateAdminProposal", nil) cdc.RegisterConcrete(&ClearAdminProposal{}, "wasm/ClearAdminProposal", nil) } @@ -44,6 +46,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { &StoreCodeProposal{}, &InstantiateContractProposal{}, &MigrateContractProposal{}, + &SudoContractProposal{}, + &ExecuteContractProposal{}, &UpdateAdminProposal{}, &ClearAdminProposal{}, &PinCodesProposal{}, diff --git a/x/wasm/types/proposal_test.go b/x/wasm/types/proposal_test.go index dfae82698b..6ccd4b1a79 100644 --- a/x/wasm/types/proposal_test.go +++ b/x/wasm/types/proposal_test.go @@ -317,6 +317,122 @@ func TestValidateMigrateContractProposal(t *testing.T) { } } +func TestValidateSudoContractProposal(t *testing.T) { + var ( + invalidAddress = "invalid address" + ) + + specs := map[string]struct { + src *SudoContractProposal + expErr bool + }{ + "all good": { + src: SudoContractProposalFixture(), + }, + "msg is nil": { + src: SudoContractProposalFixture(func(p *SudoContractProposal) { + p.Msg = nil + }), + expErr: true, + }, + "msg with invalid json": { + src: SudoContractProposalFixture(func(p *SudoContractProposal) { + p.Msg = []byte("not a json message") + }), + expErr: true, + }, + "base data missing": { + src: SudoContractProposalFixture(func(p *SudoContractProposal) { + p.Title = "" + }), + expErr: true, + }, + "contract missing": { + src: SudoContractProposalFixture(func(p *SudoContractProposal) { + p.Contract = "" + }), + expErr: true, + }, + "contract invalid": { + src: SudoContractProposalFixture(func(p *SudoContractProposal) { + p.Contract = invalidAddress + }), + expErr: true, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + err := spec.src.ValidateBasic() + if spec.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} + +func TestValidateExecuteContractProposal(t *testing.T) { + var ( + invalidAddress = "invalid address" + ) + + specs := map[string]struct { + src *ExecuteContractProposal + expErr bool + }{ + "all good": { + src: ExecuteContractProposalFixture(), + }, + "msg is nil": { + src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { + p.Msg = nil + }), + expErr: true, + }, + "msg with invalid json": { + src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { + p.Msg = []byte("not a valid json message") + }), + expErr: true, + }, + "base data missing": { + src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { + p.Title = "" + }), + expErr: true, + }, + "contract missing": { + src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { + p.Contract = "" + }), + expErr: true, + }, + "contract invalid": { + src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { + p.Contract = invalidAddress + }), + expErr: true, + }, + "run as is invalid": { + src: ExecuteContractProposalFixture(func(p *ExecuteContractProposal) { + p.RunAs = invalidAddress + }), + expErr: true, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + err := spec.src.ValidateBasic() + if spec.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} + func TestValidateUpdateAdminProposal(t *testing.T) { var ( invalidAddress = "invalid address" diff --git a/x/wasm/types/test_fixtures.go b/x/wasm/types/test_fixtures.go index 568c4f7c91..ca3a919b5a 100644 --- a/x/wasm/types/test_fixtures.go +++ b/x/wasm/types/test_fixtures.go @@ -257,6 +257,48 @@ func MigrateContractProposalFixture(mutators ...func(p *MigrateContractProposal) return p } +func SudoContractProposalFixture(mutators ...func(p *SudoContractProposal)) *SudoContractProposal { + const ( + contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" + ) + + p := &SudoContractProposal{ + Title: "Foo", + Description: "Bar", + Contract: contractAddr, + Msg: []byte(`{"do":"something"}`), + } + + for _, m := range mutators { + m(p) + } + return p +} + +func ExecuteContractProposalFixture(mutators ...func(p *ExecuteContractProposal)) *ExecuteContractProposal { + const ( + contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" + anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4" + ) + + p := &ExecuteContractProposal{ + Title: "Foo", + Description: "Bar", + Contract: contractAddr, + RunAs: anyAddress, + Msg: []byte(`{"do":"something"}`), + Funds: sdk.Coins{{ + Denom: "stake", + Amount: sdk.NewInt(1), + }}, + } + + for _, m := range mutators { + m(p) + } + return p +} + func UpdateAdminProposalFixture(mutators ...func(p *UpdateAdminProposal)) *UpdateAdminProposal { const ( contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"