Skip to content

Commit

Permalink
fix: filter allowed account according to the spec for to/from for buy…
Browse files Browse the repository at this point in the history
… back
  • Loading branch information
ze97286 committed Sep 25, 2024
1 parent 90124af commit c7c4529
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 7 additions & 3 deletions commands/proposal_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import (

const ReferenceMaxLen int = 100

var validAccountTypes = map[vegapb.AccountType]struct{}{
var validFromAccountTypesForPAP = map[vegapb.AccountType]struct{}{
vegapb.AccountType_ACCOUNT_TYPE_BUY_BACK_FEES: {},
}

var validToAccountTypesForPAP = map[vegapb.AccountType]struct{}{
vegapb.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE: {},
vegapb.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD: {},
vegapb.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY: {},
Expand Down Expand Up @@ -435,13 +439,13 @@ func checkAutomatedPurchaseConfig(newAutoPurchase *vegapb.ProposalTerms_NewProto
if change.FromAccountType == vegapb.AccountType_ACCOUNT_TYPE_UNSPECIFIED {
errs.AddForProperty("proposal_submission.terms.change.protocol_automated_purchase.changes.from_account_type", ErrIsRequired)
}
if _, ok := validAccountTypes[change.FromAccountType]; !ok {
if _, ok := validFromAccountTypesForPAP[change.FromAccountType]; !ok {
errs.AddForProperty("proposal_submission.terms.change.protocol_automated_purchase.changes.from_account_type", ErrIsNotValid)
}
if change.ToAccountType == vegapb.AccountType_ACCOUNT_TYPE_UNSPECIFIED {
errs.AddForProperty("proposal_submission.terms.change.protocol_automated_purchase.changes.to_account_type", ErrIsRequired)
}
if _, ok := validAccountTypes[change.ToAccountType]; !ok {
if _, ok := validToAccountTypesForPAP[change.ToAccountType]; !ok {
errs.AddForProperty("proposal_submission.terms.change.protocol_automated_purchase.changes.to_account_type", ErrIsNotValid)
}
if len(change.MarketId) == 0 {
Expand Down
9 changes: 3 additions & 6 deletions commands/proposal_submission_pap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ func TestSubmissionOfNewPAPWithoutFromAssetFails(t *testing.T) {
}

func TestSubmissionOfNewPAPInvalidFromAccountTypeFails(t *testing.T) {
validAccountTypes := map[types.AccountType]struct{}{
types.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE: {},
types.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD: {},
types.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY: {},
types.AccountType_ACCOUNT_TYPE_BUY_BACK_FEES: {},
validFromAccountTypes := map[types.AccountType]struct{}{
types.AccountType_ACCOUNT_TYPE_BUY_BACK_FEES: {},
}
for tp := range types.AccountType_name {
err := checkProposalSubmission(&commandspb.ProposalSubmission{
Expand All @@ -81,7 +78,7 @@ func TestSubmissionOfNewPAPInvalidFromAccountTypeFails(t *testing.T) {
},
},
})
_, ok := validAccountTypes[types.AccountType(tp)]
_, ok := validFromAccountTypes[types.AccountType(tp)]
if !ok {
if tp == 0 {
assert.Contains(t, err.Get("proposal_submission.terms.change.protocol_automated_purchase.changes.from_account_type"), commands.ErrIsRequired)
Expand Down

0 comments on commit c7c4529

Please sign in to comment.