code.vegaprotocol.io/vega@v0.79.0/datanode/sqlsubscribers/market_created_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 sqlsubscribers_test 17 18 import ( 19 "context" 20 "testing" 21 22 "code.vegaprotocol.io/vega/core/datasource" 23 dstypes "code.vegaprotocol.io/vega/core/datasource/common" 24 "code.vegaprotocol.io/vega/core/datasource/external/signedoracle" 25 "code.vegaprotocol.io/vega/core/events" 26 "code.vegaprotocol.io/vega/core/types" 27 "code.vegaprotocol.io/vega/datanode/sqlsubscribers" 28 "code.vegaprotocol.io/vega/datanode/sqlsubscribers/mocks" 29 "code.vegaprotocol.io/vega/libs/num" 30 "code.vegaprotocol.io/vega/protos/vega" 31 datapb "code.vegaprotocol.io/vega/protos/vega/data/v1" 32 33 "github.com/golang/mock/gomock" 34 ) 35 36 func Test_MarketCreated_Push(t *testing.T) { 37 t.Run("MarketCreatedEvent should call market SQL store Add", shouldCallMarketSQLStoreAdd) 38 } 39 40 func shouldCallMarketSQLStoreAdd(t *testing.T) { 41 ctrl := gomock.NewController(t) 42 43 store := mocks.NewMockMarketsStore(ctrl) 44 45 store.EXPECT().Upsert(context.Background(), gomock.Any()).Times(1) 46 subscriber := sqlsubscribers.NewMarketCreated(store) 47 subscriber.Flush(context.Background()) 48 subscriber.Push(context.Background(), events.NewMarketCreatedEvent(context.Background(), getTestMarket(false))) 49 } 50 51 func getTestMarket(termInt bool) types.Market { 52 term := &datasource.Spec{ 53 ID: "", 54 CreatedAt: 0, 55 UpdatedAt: 0, 56 Data: datasource.NewDefinition( 57 datasource.ContentTypeOracle, 58 ).SetOracleConfig( 59 &signedoracle.SpecConfiguration{ 60 Signers: nil, 61 Filters: nil, 62 }, 63 ), 64 Status: 0, 65 } 66 67 if termInt { 68 term = &datasource.Spec{ 69 ID: "", 70 CreatedAt: 0, 71 UpdatedAt: 0, 72 Data: datasource.NewDefinition( 73 datasource.ContentTypeInternalTimeTermination, 74 ).SetTimeTriggerConditionConfig( 75 []*dstypes.SpecCondition{ 76 { 77 Operator: datapb.Condition_OPERATOR_EQUALS, 78 Value: "test-value", 79 }, 80 }, 81 ), 82 Status: 0, 83 } 84 } 85 86 return types.Market{ 87 ID: "DEADBEEF", 88 TradableInstrument: &types.TradableInstrument{ 89 Instrument: &types.Instrument{ 90 ID: "TEST_INSTRUMENT", 91 Code: "TEST", 92 Name: "Test Instrument", 93 Metadata: &types.InstrumentMetadata{ 94 Tags: []string{"AAA", "BBB"}, 95 }, 96 Product: &types.InstrumentFuture{ 97 Future: &types.Future{ 98 SettlementAsset: "", 99 QuoteName: "", 100 DataSourceSpecForSettlementData: &datasource.Spec{ 101 ID: "", 102 CreatedAt: 0, 103 UpdatedAt: 0, 104 Data: datasource.NewDefinition( 105 datasource.ContentTypeOracle, 106 ).SetOracleConfig( 107 &signedoracle.SpecConfiguration{ 108 Signers: nil, 109 Filters: nil, 110 }, 111 ), 112 Status: 0, 113 }, 114 DataSourceSpecForTradingTermination: term, 115 DataSourceSpecBinding: &datasource.SpecBindingForFuture{ 116 SettlementDataProperty: "", 117 TradingTerminationProperty: "", 118 }, 119 }, 120 }, 121 }, 122 MarginCalculator: &types.MarginCalculator{ 123 ScalingFactors: &types.ScalingFactors{ 124 SearchLevel: num.DecimalZero(), 125 InitialMargin: num.DecimalZero(), 126 CollateralRelease: num.DecimalZero(), 127 }, 128 }, 129 RiskModel: &types.TradableInstrumentSimpleRiskModel{ 130 SimpleRiskModel: &types.SimpleRiskModel{ 131 Params: &types.SimpleModelParams{ 132 FactorLong: num.DecimalZero(), 133 FactorShort: num.DecimalZero(), 134 MaxMoveUp: num.DecimalZero(), 135 MinMoveDown: num.DecimalZero(), 136 ProbabilityOfTrading: num.DecimalZero(), 137 }, 138 }, 139 }, 140 }, 141 DecimalPlaces: 16, 142 PositionDecimalPlaces: 8, 143 Fees: &types.Fees{ 144 Factors: &types.FeeFactors{ 145 MakerFee: num.DecimalZero(), 146 InfrastructureFee: num.DecimalZero(), 147 LiquidityFee: num.DecimalZero(), 148 }, 149 LiquidityFeeSettings: &types.LiquidityFeeSettings{ 150 Method: vega.LiquidityFeeSettings_METHOD_MARGINAL_COST, 151 }, 152 }, 153 OpeningAuction: nil, 154 PriceMonitoringSettings: &types.PriceMonitoringSettings{ 155 Parameters: &types.PriceMonitoringParameters{ 156 Triggers: []*types.PriceMonitoringTrigger{ 157 { 158 Horizon: 0, 159 HorizonDec: num.DecimalZero(), 160 Probability: num.NewDecimalFromFloat(0.99), 161 AuctionExtension: 0, 162 }, 163 }, 164 }, 165 }, 166 LiquidityMonitoringParameters: &types.LiquidityMonitoringParameters{ 167 TargetStakeParameters: &types.TargetStakeParameters{ 168 TimeWindow: 0, 169 ScalingFactor: num.DecimalZero(), 170 }, 171 }, 172 TickSize: num.UintOne(), 173 TradingMode: 0, 174 State: 0, 175 MarketTimestamps: &types.MarketTimestamps{ 176 Proposed: 0, 177 Pending: 0, 178 Open: 0, 179 Close: 0, 180 }, 181 LiquiditySLAParams: &types.LiquiditySLAParams{ 182 PriceRange: num.DecimalFromFloat(0.95), 183 }, 184 } 185 }