code.vegaprotocol.io/vega@v0.79.0/commands/proposal_submission_update_market_state_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 21 "code.vegaprotocol.io/vega/commands" 22 types "code.vegaprotocol.io/vega/protos/vega" 23 commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" 24 25 "github.com/stretchr/testify/require" 26 ) 27 28 func TestCheckProposalSubmissionForUpdateMarketState(t *testing.T) { 29 t.Run("Submitting a market state update change without an update fails", testUpdateMarketStateChangeSubmissionWithoutUpdateFails) 30 t.Run("Submitting a market state update change without a change configuration fails", testUpdateMarketStateChangeSubmissionWithoutConfigurationFails) 31 t.Run("Submitting a market state update change without a market id fails", testUpdateMarketStateChangeSubmissionWithoutMarketIDFails) 32 t.Run("Submitting a market state update change without an update type fails", testUpdateMarketStateChangeSubmissionWithoutUpdateTypeFails) 33 t.Run("Submitting a market state update change for anything but termination and passing a price fails", testUpdateMarketStateChangeSubmissionPriceNotExpectedFails) 34 t.Run("Submitting a market state update change for terminating a market with invalid price fails", testUpdateMarketStateChangeSubmissionWithInvalidPrice) 35 } 36 37 func testUpdateMarketStateChangeSubmissionWithoutUpdateFails(t *testing.T) { 38 err := checkProposalSubmission(&commandspb.ProposalSubmission{ 39 Terms: &types.ProposalTerms{ 40 Change: &types.ProposalTerms_UpdateMarketState{}, 41 }, 42 }) 43 require.Contains(t, err.Get("proposal_submission.terms.change.update_market_state"), commands.ErrIsRequired) 44 } 45 46 func testUpdateMarketStateChangeSubmissionWithoutConfigurationFails(t *testing.T) { 47 err := checkProposalSubmission(&commandspb.ProposalSubmission{ 48 Terms: &types.ProposalTerms{ 49 Change: &types.ProposalTerms_UpdateMarketState{ 50 UpdateMarketState: &types.UpdateMarketState{}, 51 }, 52 }, 53 }) 54 require.Contains(t, err.Get("proposal_submission.terms.change.update_market_state.changes"), commands.ErrIsRequired) 55 } 56 57 func testUpdateMarketStateChangeSubmissionWithoutMarketIDFails(t *testing.T) { 58 err := checkProposalSubmission(&commandspb.ProposalSubmission{ 59 Terms: &types.ProposalTerms{ 60 Change: &types.ProposalTerms_UpdateMarketState{ 61 UpdateMarketState: &types.UpdateMarketState{ 62 Changes: &types.UpdateMarketStateConfiguration{}, 63 }, 64 }, 65 }, 66 }) 67 require.Contains(t, err.Get("proposal_submission.terms.change.update_market_state.changes.marketId"), commands.ErrIsRequired) 68 } 69 70 func testUpdateMarketStateChangeSubmissionWithoutUpdateTypeFails(t *testing.T) { 71 err := checkProposalSubmission(&commandspb.ProposalSubmission{ 72 Terms: &types.ProposalTerms{ 73 Change: &types.ProposalTerms_UpdateMarketState{ 74 UpdateMarketState: &types.UpdateMarketState{ 75 Changes: &types.UpdateMarketStateConfiguration{ 76 MarketId: "marketID", 77 }, 78 }, 79 }, 80 }, 81 }) 82 require.Contains(t, err.Get("proposal_submission.terms.change.update_market_state.changes.updateType"), commands.ErrIsRequired) 83 } 84 85 func testUpdateMarketStateChangeSubmissionPriceNotExpectedFails(t *testing.T) { 86 price := "123" 87 err := checkProposalSubmission(&commandspb.ProposalSubmission{ 88 Terms: &types.ProposalTerms{ 89 Change: &types.ProposalTerms_UpdateMarketState{ 90 UpdateMarketState: &types.UpdateMarketState{ 91 Changes: &types.UpdateMarketStateConfiguration{ 92 MarketId: "marketID", 93 UpdateType: types.MarketStateUpdateType_MARKET_STATE_UPDATE_TYPE_RESUME, 94 Price: &price, 95 }, 96 }, 97 }, 98 }, 99 }) 100 require.Contains(t, err.Get("proposal_submission.terms.change.update_market_state.changes.price"), commands.ErrMustBeEmpty) 101 102 err = checkProposalSubmission(&commandspb.ProposalSubmission{ 103 Terms: &types.ProposalTerms{ 104 Change: &types.ProposalTerms_UpdateMarketState{ 105 UpdateMarketState: &types.UpdateMarketState{ 106 Changes: &types.UpdateMarketStateConfiguration{ 107 MarketId: "marketID", 108 UpdateType: types.MarketStateUpdateType_MARKET_STATE_UPDATE_TYPE_SUSPEND, 109 Price: &price, 110 }, 111 }, 112 }, 113 }, 114 }) 115 require.Contains(t, err.Get("proposal_submission.terms.change.update_market_state.changes.price"), commands.ErrMustBeEmpty) 116 } 117 118 func testUpdateMarketStateChangeSubmissionWithInvalidPrice(t *testing.T) { 119 invalidPrices := []string{"aaa", "-1", "1.234"} 120 for _, inv := range invalidPrices { 121 err := checkProposalSubmission(&commandspb.ProposalSubmission{ 122 Terms: &types.ProposalTerms{ 123 Change: &types.ProposalTerms_UpdateMarketState{ 124 UpdateMarketState: &types.UpdateMarketState{ 125 Changes: &types.UpdateMarketStateConfiguration{ 126 MarketId: "marketID", 127 UpdateType: types.MarketStateUpdateType_MARKET_STATE_UPDATE_TYPE_TERMINATE, 128 Price: &inv, 129 }, 130 }, 131 }, 132 }, 133 }) 134 require.Contains(t, err.Get("proposal_submission.terms.change.update_market_state.changes.price"), commands.ErrIsNotValid) 135 } 136 }