Skip to content

Commit

Permalink
Merge pull request #3305 from vegaprotocol/feature/fix-gql-api-proposal
Browse files Browse the repository at this point in the history
fix governance validation of proposal terms
  • Loading branch information
jeremyletang authored Apr 6, 2021
2 parents 2bdce25 + 72e9577 commit af3df92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions governance/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
const invalidProposalTerms = "invalid proposal terms"

var (
ErrMissingVoteData = errors.New("required fields from vote missing")
ErrMissingVoteData = errors.New("required fields from vote missing")
ErrUnsupportedProposalTerms = errors.New("unsupported proposal terms")
)

//go:generate go run github.com/golang/mock/mockgen -destination mocks/event_bus_mock.go -package mocks code.vegaprotocol.io/vega/governance EventBus
Expand Down Expand Up @@ -380,8 +381,10 @@ func (s *Svc) validateProposalChanges(terms *types.ProposalTerms) error {
return s.validateNewMarketChanges(terms, c.NewMarket)
case *types.ProposalTerms_UpdateNetworkParameter:
return s.validateUpdateNetworkParameterChanges(c.UpdateNetworkParameter)
case *types.ProposalTerms_NewAsset:
return s.validateNewAssetChanges(c.NewAsset)
default:
return nil
return ErrUnsupportedProposalTerms
}
}

Expand All @@ -390,6 +393,11 @@ func (s *Svc) validateUpdateNetworkParameterChanges(np *types.UpdateNetworkParam
return
}

func (s *Svc) validateNewAssetChanges(np *types.NewAsset) (err error) {
_, err = validateNewAsset(np.Changes)
return
}

func (s *Svc) validateNewMarketChanges(
terms *types.ProposalTerms, nm *types.NewMarket) (err error) {
closeTime := time.Unix(terms.ClosingTimestamp, 0)
Expand Down
17 changes: 17 additions & 0 deletions governance/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestPrepareUpdateNetworkParameterProposal(t *testing.T) {
t.Run("prepare update network proposal - failure empty key", testPrepareNetworkParameterUpdateProposalFailureEmptyKey)
t.Run("prepare update network proposal - failure empty value", testPrepareNetworkParameterUpdateProposalFailureEmptyValue)
t.Run("prepare update network proposal - validation failure", testPrepareNetworkParameterUpdateProposalValidationFailure)
t.Run("prepare proposal with invalid changes - validation failure", testPrepareProposalWithInvalidChanges)
}

func testPrepareNetworkParameterUpdateProposalSuccess(t *testing.T) {
Expand Down Expand Up @@ -133,6 +134,22 @@ func testPrepareNetworkParameterUpdateProposalFailureEmptyValue(t *testing.T) {
assert.Nil(t, proposal)
}

func testPrepareProposalWithInvalidChanges(t *testing.T) {
svc := newTestService(t)
defer svc.ctrl.Finish()
terms := types.ProposalTerms{
ClosingTimestamp: time.Now().Add(time.Hour * 24 * 2).UTC().Unix(),
EnactmentTimestamp: time.Now().Add(time.Hour * 24 * 60).UTC().Unix(),
Change: nil,
}

testAuthor := "test-author"
proposal, err := svc.PrepareProposal(svc.ctx, testAuthor, "", &terms)

assert.EqualError(t, err, governance.ErrUnsupportedProposalTerms.Error())
assert.Nil(t, proposal)
}

func testPrepareNetworkParameterUpdateProposalValidationFailure(t *testing.T) {
svc := newTestService(t)
defer svc.ctrl.Finish()
Expand Down

0 comments on commit af3df92

Please sign in to comment.