Skip to content

Commit

Permalink
Add ExecuteContractProposal test
Browse files Browse the repository at this point in the history
  • Loading branch information
the-frey committed Apr 21, 2022
1 parent 64e1fca commit 190b8cc
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
63 changes: 62 additions & 1 deletion x/wasm/types/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func TestValidateMigrateContractProposal(t *testing.T) {

func TestValidateSudoContractProposal(t *testing.T) {
var (
invalidAddress = "invalid address2"
invalidAddress = "invalid address"
)

specs := map[string]struct {
Expand Down Expand Up @@ -372,6 +372,67 @@ func TestValidateSudoContractProposal(t *testing.T) {
}
}

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"
Expand Down
25 changes: 24 additions & 1 deletion x/wasm/types/test_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ func MigrateContractProposalFixture(mutators ...func(p *MigrateContractProposal)
func SudoContractProposalFixture(mutators ...func(p *SudoContractProposal)) *SudoContractProposal {
const (
contractAddr = "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4"
)

p := &SudoContractProposal{
Expand All @@ -276,6 +275,30 @@ func SudoContractProposalFixture(mutators ...func(p *SudoContractProposal)) *Sud
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"
Expand Down

0 comments on commit 190b8cc

Please sign in to comment.