code.vegaprotocol.io/vega@v0.79.0/core/events/trade_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 TestTradeDeepClone(t *testing.T) { 31 ctx := context.Background() 32 33 trade := &types.Trade{ 34 ID: "Id", 35 MarketID: "MarketId", 36 Price: num.NewUint(1000), 37 MarketPrice: num.NewUint(1000), 38 Size: 2000, 39 Buyer: "Buyer", 40 Seller: "Seller", 41 Aggressor: proto.Side_SIDE_BUY, 42 BuyOrder: "BuyOrder", 43 SellOrder: "SellOrder", 44 Timestamp: 3000, 45 Type: proto.Trade_TYPE_DEFAULT, 46 BuyerFee: &types.Fee{ 47 MakerFee: num.NewUint(4000), 48 InfrastructureFee: num.NewUint(5000), 49 LiquidityFee: num.NewUint(6000), 50 }, 51 SellerFee: &types.Fee{ 52 MakerFee: num.NewUint(7000), 53 InfrastructureFee: num.NewUint(8000), 54 LiquidityFee: num.NewUint(9000), 55 }, 56 BuyerAuctionBatch: 10000, 57 SellerAuctionBatch: 11000, 58 } 59 60 tEvent := events.NewTradeEvent(ctx, *trade) 61 trade2 := tEvent.Trade() 62 63 // Change the original values 64 trade.ID = "Changed" 65 trade.MarketID = "Changed" 66 trade.Price = num.NewUint(999) 67 trade.MarketPrice = num.NewUint(999) 68 trade.Size = 999 69 trade.Buyer = "Changed" 70 trade.Seller = "Changed" 71 trade.Aggressor = proto.Side_SIDE_UNSPECIFIED 72 trade.BuyOrder = "Changed" 73 trade.SellOrder = "Changed" 74 trade.Timestamp = 999 75 trade.Type = proto.Trade_TYPE_UNSPECIFIED 76 trade.BuyerFee.MakerFee = num.NewUint(999) 77 trade.BuyerFee.InfrastructureFee = num.NewUint(999) 78 trade.BuyerFee.LiquidityFee = num.NewUint(999) 79 trade.SellerFee.MakerFee = num.NewUint(999) 80 trade.SellerFee.InfrastructureFee = num.NewUint(999) 81 trade.SellerFee.LiquidityFee = num.NewUint(999) 82 trade.BuyerAuctionBatch = 999 83 trade.SellerAuctionBatch = 999 84 85 // Check things have changed 86 assert.NotEqual(t, trade.ID, trade2.Id) 87 assert.NotEqual(t, trade.MarketID, trade2.MarketId) 88 assert.NotEqual(t, trade.Price, trade2.Price) 89 assert.NotEqual(t, trade.Size, trade2.Size) 90 assert.NotEqual(t, trade.Buyer, trade2.Buyer) 91 assert.NotEqual(t, trade.Seller, trade2.Seller) 92 assert.NotEqual(t, trade.Aggressor, trade2.Aggressor) 93 assert.NotEqual(t, trade.BuyOrder, trade2.BuyOrder) 94 assert.NotEqual(t, trade.SellOrder, trade2.SellOrder) 95 assert.NotEqual(t, trade.Timestamp, trade2.Timestamp) 96 assert.NotEqual(t, trade.Type, trade2.Type) 97 assert.NotEqual(t, trade.BuyerFee.MakerFee, trade2.BuyerFee.MakerFee) 98 assert.NotEqual(t, trade.BuyerFee.InfrastructureFee, trade2.BuyerFee.InfrastructureFee) 99 assert.NotEqual(t, trade.BuyerFee.LiquidityFee, trade2.BuyerFee.LiquidityFee) 100 assert.NotEqual(t, trade.SellerFee.MakerFee, trade2.SellerFee.MakerFee) 101 assert.NotEqual(t, trade.SellerFee.InfrastructureFee, trade2.SellerFee.InfrastructureFee) 102 assert.NotEqual(t, trade.SellerFee.LiquidityFee, trade2.SellerFee.LiquidityFee) 103 assert.NotEqual(t, trade.BuyerAuctionBatch, trade2.BuyerAuctionBatch) 104 assert.NotEqual(t, trade.SellerAuctionBatch, trade2.SellerAuctionBatch) 105 }