code.vegaprotocol.io/vega@v0.79.0/core/events/market_data_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 events_test 17 18 import ( 19 "context" 20 "testing" 21 22 "code.vegaprotocol.io/vega/core/events" 23 "code.vegaprotocol.io/vega/core/types" 24 "code.vegaprotocol.io/vega/libs/num" 25 proto "code.vegaprotocol.io/vega/protos/vega" 26 27 "github.com/stretchr/testify/assert" 28 ) 29 30 func TestMarketDataDeepClone(t *testing.T) { 31 ctx := context.Background() 32 33 md := types.MarketData{ 34 MarkPrice: num.NewUint(1000), 35 BestBidPrice: num.NewUint(2000), 36 BestBidVolume: 3000, 37 BestOfferPrice: num.NewUint(4000), 38 BestOfferVolume: 5000, 39 BestStaticBidPrice: num.NewUint(6000), 40 BestStaticBidVolume: 7000, 41 BestStaticOfferPrice: num.NewUint(8000), 42 BestStaticOfferVolume: 9000, 43 MidPrice: num.NewUint(10000), 44 StaticMidPrice: num.NewUint(11000), 45 Market: "Market", 46 Timestamp: 12000, 47 OpenInterest: 13000, 48 AuctionEnd: 14000, 49 AuctionStart: 15000, 50 IndicativePrice: num.NewUint(16000), 51 IndicativeVolume: 17000, 52 MarketTradingMode: proto.Market_TRADING_MODE_CONTINUOUS, 53 Trigger: proto.AuctionTrigger_AUCTION_TRIGGER_OPENING, 54 TargetStake: "18000", 55 SuppliedStake: "19000", 56 PriceMonitoringBounds: []*types.PriceMonitoringBounds{ 57 { 58 MinValidPrice: num.NewUint(20000), 59 MaxValidPrice: num.NewUint(21000), 60 Trigger: &types.PriceMonitoringTrigger{ 61 Horizon: 22000, 62 Probability: num.DecimalFromFloat(123.45), 63 AuctionExtension: 23000, 64 }, 65 ReferencePrice: num.DecimalFromFloat(24000.), 66 }, 67 }, 68 MarketValueProxy: "MVP", 69 LiquidityProviderFeeShare: []*types.LiquidityProviderFeeShare{ 70 { 71 Party: "Party", 72 EquityLikeShare: "25000", 73 AverageEntryValuation: "26000", 74 AverageScore: "123", 75 }, 76 }, 77 } 78 79 marketDataEvent := events.NewMarketDataEvent(ctx, md) 80 md2 := marketDataEvent.MarketData() 81 82 // Change the original and check we are not updating the wrapped event 83 md.MarkPrice = num.NewUint(999) 84 md.BestBidPrice = num.NewUint(999) 85 md.BestBidVolume = 999 86 md.BestOfferPrice = num.NewUint(999) 87 md.BestOfferVolume = 999 88 md.BestStaticBidPrice = num.NewUint(999) 89 md.BestStaticBidVolume = 999 90 md.BestStaticOfferPrice = num.NewUint(999) 91 md.BestStaticOfferVolume = 999 92 md.MidPrice = num.NewUint(999) 93 md.StaticMidPrice = num.NewUint(999) 94 md.Market = "Changed" 95 md.Timestamp = 999 96 md.OpenInterest = 999 97 md.AuctionEnd = 999 98 md.AuctionStart = 999 99 md.IndicativePrice = num.NewUint(999) 100 md.IndicativeVolume = 999 101 md.MarketTradingMode = types.MarketTradingModeUnspecified 102 md.Trigger = types.AuctionTriggerUnspecified 103 md.TargetStake = "999" 104 md.SuppliedStake = "999" 105 md.PriceMonitoringBounds[0].MinValidPrice = num.NewUint(999) 106 md.PriceMonitoringBounds[0].MaxValidPrice = num.NewUint(999) 107 md.PriceMonitoringBounds[0].Trigger.Horizon = 999 108 md.PriceMonitoringBounds[0].Trigger.Probability = num.DecimalFromFloat(999) 109 md.PriceMonitoringBounds[0].Trigger.AuctionExtension = 999 110 md.PriceMonitoringBounds[0].ReferencePrice = num.DecimalFromFloat(999) 111 md.MarketValueProxy = "Changed" 112 md.LiquidityProviderFeeShare[0].Party = "Changed" 113 md.LiquidityProviderFeeShare[0].EquityLikeShare = "999" 114 md.LiquidityProviderFeeShare[0].AverageEntryValuation = "999" 115 md.LiquidityProviderFeeShare[0].AverageScore = "321" 116 117 assert.NotEqual(t, md.MarkPrice, md2.MarkPrice) 118 assert.NotEqual(t, md.BestBidPrice, md2.BestBidPrice) 119 assert.NotEqual(t, md.BestBidVolume, md2.BestBidVolume) 120 assert.NotEqual(t, md.BestOfferPrice, md2.BestOfferPrice) 121 assert.NotEqual(t, md.BestOfferVolume, md2.BestOfferVolume) 122 assert.NotEqual(t, md.BestStaticBidPrice, md2.BestStaticBidPrice) 123 assert.NotEqual(t, md.BestStaticBidVolume, md2.BestStaticBidVolume) 124 assert.NotEqual(t, md.BestStaticOfferPrice, md2.BestStaticOfferPrice) 125 assert.NotEqual(t, md.BestStaticOfferVolume, md2.BestStaticOfferVolume) 126 assert.NotEqual(t, md.MidPrice, md2.MidPrice) 127 assert.NotEqual(t, md.StaticMidPrice, md2.StaticMidPrice) 128 assert.NotEqual(t, md.Market, md2.Market) 129 assert.NotEqual(t, md.Timestamp, md2.Timestamp) 130 assert.NotEqual(t, md.OpenInterest, md2.OpenInterest) 131 assert.NotEqual(t, md.AuctionEnd, md2.AuctionEnd) 132 assert.NotEqual(t, md.AuctionStart, md2.AuctionStart) 133 assert.NotEqual(t, md.IndicativePrice, md2.IndicativePrice) 134 assert.NotEqual(t, md.IndicativeVolume, md2.IndicativeVolume) 135 assert.NotEqual(t, md.MarketTradingMode, md2.MarketTradingMode) 136 assert.NotEqual(t, md.Trigger, md2.Trigger) 137 assert.NotEqual(t, md.TargetStake, md2.TargetStake) 138 assert.NotEqual(t, md.SuppliedStake, md2.SuppliedStake) 139 assert.NotEqual(t, md.PriceMonitoringBounds[0].MinValidPrice, md2.PriceMonitoringBounds[0].MinValidPrice) 140 assert.NotEqual(t, md.PriceMonitoringBounds[0].MaxValidPrice, md2.PriceMonitoringBounds[0].MaxValidPrice) 141 assert.NotEqual(t, md.PriceMonitoringBounds[0].Trigger.Horizon, md2.PriceMonitoringBounds[0].Trigger.Horizon) 142 assert.NotEqual(t, md.PriceMonitoringBounds[0].Trigger.Probability, md2.PriceMonitoringBounds[0].Trigger.Probability) 143 assert.NotEqual(t, md.PriceMonitoringBounds[0].Trigger.AuctionExtension, md2.PriceMonitoringBounds[0].Trigger.AuctionExtension) 144 assert.NotEqual(t, md.PriceMonitoringBounds[0].ReferencePrice, md2.PriceMonitoringBounds[0].ReferencePrice) 145 assert.NotEqual(t, md.MarketValueProxy, md2.MarketValueProxy) 146 assert.NotEqual(t, md.LiquidityProviderFeeShare[0].Party, md2.LiquidityProviderFeeShare[0].Party) 147 assert.NotEqual(t, md.LiquidityProviderFeeShare[0].EquityLikeShare, md2.LiquidityProviderFeeShare[0].EquityLikeShare) 148 assert.NotEqual(t, md.LiquidityProviderFeeShare[0].AverageEntryValuation, md2.LiquidityProviderFeeShare[0].AverageEntryValuation) 149 assert.NotEqual(t, md.LiquidityProviderFeeShare[0].AverageScore, md2.LiquidityProviderFeeShare[0].AverageScore) 150 }