code.vegaprotocol.io/vega@v0.79.0/commands/proposal_submission_update_rebate_program_test.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package commands_test 17 18 import ( 19 "testing" 20 "time" 21 22 "code.vegaprotocol.io/vega/commands" 23 types "code.vegaprotocol.io/vega/protos/vega" 24 commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" 25 26 "github.com/stretchr/testify/assert" 27 ) 28 29 func TestVolumeRebateSubmission(t *testing.T) { 30 t.Run("empty submission", testUpdateRebateProgram) 31 t.Run("0095-HVMR-001: invalid end timestamp", testInvalidEndTime) 32 t.Run("0095-HVMR-003: tier validation", testInvalidTiers) 33 t.Run("0095-HVMR-004: invalid window length", testInvalidWindowLength) 34 } 35 36 func testUpdateRebateProgram(t *testing.T) { 37 err := checkProposalSubmission(&commandspb.ProposalSubmission{ 38 Terms: &types.ProposalTerms{ 39 Change: &types.ProposalTerms_UpdateVolumeRebateProgram{}, 40 }, 41 }) 42 43 assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program"), commands.ErrIsRequired) 44 // missing changes, same problem 45 err = checkProposalSubmission(&commandspb.ProposalSubmission{ 46 Terms: &types.ProposalTerms{ 47 Change: &types.ProposalTerms_UpdateVolumeRebateProgram{ 48 UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{}, 49 }, 50 }, 51 }) 52 53 assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes"), commands.ErrIsRequired) 54 } 55 56 // testInvalidEndTime covers 0095-HVMR-001. 57 func testInvalidEndTime(t *testing.T) { 58 end := time.Now() 59 enact := end.Add(time.Second) 60 prop := &commandspb.ProposalSubmission{ 61 Terms: &types.ProposalTerms{ 62 EnactmentTimestamp: enact.Unix(), 63 Change: &types.ProposalTerms_UpdateVolumeRebateProgram{ 64 UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{ 65 Changes: &types.VolumeRebateProgramChanges{ 66 EndOfProgramTimestamp: end.Unix(), 67 }, 68 }, 69 }, 70 }, 71 } 72 err := checkProposalSubmission(prop) 73 assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes.end_of_program_timestamp"), commands.ErrMustBeGreaterThanEnactmentTimestamp) 74 } 75 76 // testInvalidWindowLength covers 0095-HVMR-004. 77 func testInvalidWindowLength(t *testing.T) { 78 enact := time.Now() 79 end := enact.Add(time.Second) 80 prop := &commandspb.ProposalSubmission{ 81 Terms: &types.ProposalTerms{ 82 EnactmentTimestamp: enact.Unix(), 83 Change: &types.ProposalTerms_UpdateVolumeRebateProgram{ 84 UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{ 85 Changes: &types.VolumeRebateProgramChanges{ 86 EndOfProgramTimestamp: end.Unix(), 87 WindowLength: 0, // zero is invalid 88 }, 89 }, 90 }, 91 }, 92 } 93 err := checkProposalSubmission(prop) 94 assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes.window_length"), commands.ErrIsRequired) 95 // now too high of a value 96 prop = &commandspb.ProposalSubmission{ 97 Terms: &types.ProposalTerms{ 98 EnactmentTimestamp: enact.Unix(), 99 Change: &types.ProposalTerms_UpdateVolumeRebateProgram{ 100 UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{ 101 Changes: &types.VolumeRebateProgramChanges{ 102 EndOfProgramTimestamp: end.Unix(), 103 WindowLength: 10000, 104 }, 105 }, 106 }, 107 }, 108 } 109 err = checkProposalSubmission(prop) 110 assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes.window_length"), commands.ErrMustBeAtMost200) 111 } 112 113 // testInvalidTiers covers 0095-HVMR-003. 114 func testInvalidTiers(t *testing.T) { 115 errMap := map[string]error{ 116 "proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.0.minimum_party_maker_volume_fraction": commands.ErrIsRequired, 117 "proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.1.minimum_party_maker_volume_fraction": commands.ErrIsNotValidNumber, 118 "proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.2.minimum_party_maker_volume_fraction": commands.ErrMustBePositive, 119 "proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.3.minimum_party_maker_volume_fraction": commands.ErrMustBePositive, 120 "proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.4.additional_maker_rebate": commands.ErrIsRequired, 121 "proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.5.additional_maker_rebate": commands.ErrIsNotValidNumber, 122 "proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.6.additional_maker_rebate": commands.ErrMustBePositiveOrZero, 123 } 124 enact := time.Now() 125 end := enact.Add(time.Second) 126 prop := &commandspb.ProposalSubmission{ 127 Terms: &types.ProposalTerms{ 128 EnactmentTimestamp: enact.Unix(), 129 Change: &types.ProposalTerms_UpdateVolumeRebateProgram{ 130 UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{ 131 Changes: &types.VolumeRebateProgramChanges{ 132 EndOfProgramTimestamp: end.Unix(), 133 WindowLength: 10, 134 BenefitTiers: []*types.VolumeRebateBenefitTier{ 135 { 136 MinimumPartyMakerVolumeFraction: "", 137 AdditionalMakerRebate: "0.1", 138 }, 139 { 140 MinimumPartyMakerVolumeFraction: "invalid", 141 AdditionalMakerRebate: "0.1", 142 }, 143 { 144 MinimumPartyMakerVolumeFraction: "-1", 145 AdditionalMakerRebate: "0.1", 146 }, 147 { 148 MinimumPartyMakerVolumeFraction: "0", 149 AdditionalMakerRebate: "0.1", 150 }, 151 { 152 MinimumPartyMakerVolumeFraction: "0.1", 153 AdditionalMakerRebate: "", 154 }, 155 { 156 MinimumPartyMakerVolumeFraction: "0.1", 157 AdditionalMakerRebate: "invalid", 158 }, 159 { 160 MinimumPartyMakerVolumeFraction: "0.1", 161 AdditionalMakerRebate: "-0.1", 162 }, 163 }, 164 }, 165 }, 166 }, 167 }, 168 } 169 err := checkProposalSubmission(prop) 170 for g, c := range errMap { 171 assert.Contains(t, err.Get(g), c, err.Error()) 172 } 173 }