code.vegaprotocol.io/vega@v0.79.0/core/events/order_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 TestOrderDeepClone(t *testing.T) { 31 ctx := context.Background() 32 33 o := &types.Order{ 34 ID: "Id", 35 MarketID: "MarketId", 36 Party: "PartyId", 37 Side: proto.Side_SIDE_BUY, 38 Price: num.NewUint(1000), 39 Size: 2000, 40 Remaining: 3000, 41 TimeInForce: proto.Order_TIME_IN_FORCE_GFN, 42 Type: proto.Order_TYPE_LIMIT, 43 CreatedAt: 4000, 44 Status: proto.Order_STATUS_ACTIVE, 45 ExpiresAt: 5000, 46 Reference: "Reference", 47 Reason: proto.ErrEditNotAllowed, 48 UpdatedAt: 6000, 49 Version: 7000, 50 BatchID: 8000, 51 PeggedOrder: &types.PeggedOrder{ 52 Reference: proto.PeggedReference_PEGGED_REFERENCE_MID, 53 Offset: num.NewUint(9000), 54 }, 55 } 56 57 oEvent := events.NewOrderEvent(ctx, o) 58 o2 := oEvent.Order() 59 60 // Change the original values 61 o.ID = "Changed" 62 o.MarketID = "Changed" 63 o.Party = "Changed" 64 o.Side = proto.Side_SIDE_UNSPECIFIED 65 o.Price = num.NewUint(999) 66 o.Size = 999 67 o.Remaining = 999 68 o.TimeInForce = proto.Order_TIME_IN_FORCE_UNSPECIFIED 69 o.Type = proto.Order_TYPE_UNSPECIFIED 70 o.CreatedAt = 999 71 o.Status = proto.Order_STATUS_UNSPECIFIED 72 o.ExpiresAt = 999 73 o.Reference = "Changed" 74 o.Reason = proto.ErrInvalidMarketID 75 o.UpdatedAt = 999 76 o.Version = 999 77 o.BatchID = 999 78 o.PeggedOrder.Reference = proto.PeggedReference_PEGGED_REFERENCE_UNSPECIFIED 79 o.PeggedOrder.Offset = num.NewUint(999) 80 81 // Check things have changed 82 assert.NotEqual(t, o.ID, o2.Id) 83 assert.NotEqual(t, o.MarketID, o2.MarketId) 84 assert.NotEqual(t, o.Party, o2.PartyId) 85 assert.NotEqual(t, o.Side, o2.Side) 86 assert.NotEqual(t, o.Price, o2.Price) 87 assert.NotEqual(t, o.Size, o2.Size) 88 assert.NotEqual(t, o.Remaining, o2.Remaining) 89 assert.NotEqual(t, o.TimeInForce, o2.TimeInForce) 90 assert.NotEqual(t, o.Type, o2.Type) 91 assert.NotEqual(t, o.CreatedAt, o2.CreatedAt) 92 assert.NotEqual(t, o.Status, o2.Status) 93 assert.NotEqual(t, o.ExpiresAt, o2.ExpiresAt) 94 assert.NotEqual(t, o.Reference, o2.Reference) 95 assert.NotEqual(t, o.Reason, o2.Reason) 96 assert.NotEqual(t, o.UpdatedAt, o2.UpdatedAt) 97 assert.NotEqual(t, o.Version, o2.Version) 98 assert.NotEqual(t, o.BatchID, o2.BatchId) 99 assert.NotEqual(t, o.PeggedOrder.Reference, o2.PeggedOrder.Reference) 100 assert.NotEqual(t, o.PeggedOrder.Offset, o2.PeggedOrder.Offset) 101 }