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

Fix SudoContractProposal and ExecuteContractProposal #808

Merged
merged 3 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion x/wasm/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -44,6 +46,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&StoreCodeProposal{},
&InstantiateContractProposal{},
&MigrateContractProposal{},
&SudoContractProposal{},
&ExecuteContractProposal{},
the-frey marked this conversation as resolved.
Show resolved Hide resolved
&UpdateAdminProposal{},
&ClearAdminProposal{},
&PinCodesProposal{},
Expand Down
55 changes: 55 additions & 0 deletions x/wasm/types/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,61 @@ func TestValidateMigrateContractProposal(t *testing.T) {
}
}

func TestValidateSudoContractProposal(t *testing.T) {
the-frey marked this conversation as resolved.
Show resolved Hide resolved
var (
invalidAddress = "invalid address2"
)

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)
}
})
}
}

the-frey marked this conversation as resolved.
Show resolved Hide resolved
func TestValidateUpdateAdminProposal(t *testing.T) {
var (
invalidAddress = "invalid address"
Expand Down
19 changes: 19 additions & 0 deletions x/wasm/types/test_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,25 @@ func MigrateContractProposalFixture(mutators ...func(p *MigrateContractProposal)
return p
}

func SudoContractProposalFixture(mutators ...func(p *SudoContractProposal)) *SudoContractProposal {
const (
contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4"
the-frey marked this conversation as resolved.
Show resolved Hide resolved
)

p := &SudoContractProposal{
Title: "Foo",
Description: "Bar",
Contract: contractAddr,
Msg: []byte(`{"do":"something"}`),
}

for _, m := range mutators {
m(p)
}
return p
}

func UpdateAdminProposalFixture(mutators ...func(p *UpdateAdminProposal)) *UpdateAdminProposal {
const (
contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
Expand Down