code.vegaprotocol.io/vega@v0.79.0/core/events/liquidity_provision_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  
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  func TestLiquidityProvisionDeepClone(t *testing.T) {
    30  	ctx := context.Background()
    31  
    32  	lp := &types.LiquidityProvision{
    33  		ID:               "Id",
    34  		Party:            "PartyId",
    35  		CreatedAt:        10000,
    36  		UpdatedAt:        20000,
    37  		MarketID:         "MarketId",
    38  		CommitmentAmount: num.NewUint(30000),
    39  		Fee:              num.DecimalFromFloat(0.01),
    40  		Version:          1,
    41  		Status:           types.LiquidityProvisionStatusUndeployed,
    42  		Reference:        "Reference",
    43  	}
    44  
    45  	// Create the event
    46  	lpEvent := events.NewLiquidityProvisionEvent(ctx, lp)
    47  	lp2 := lpEvent.LiquidityProvision()
    48  
    49  	// Alter the original message
    50  	lp.ID = "Changed"
    51  	lp.Party = "Changed"
    52  	lp.CreatedAt = 999
    53  	lp.UpdatedAt = 999
    54  	lp.MarketID = "Changed"
    55  	lp.CommitmentAmount = num.NewUint(999)
    56  	lp.Fee = num.DecimalFromFloat(99.9)
    57  	lp.Version = 999
    58  	lp.Status = types.LiquidityProvisionUnspecified
    59  	lp.Reference = "Changed"
    60  
    61  	// Check that values are different
    62  	assert.NotEqual(t, lp.ID, lp2.Id)
    63  	assert.NotEqual(t, lp.Party, lp2.PartyId)
    64  	assert.NotEqual(t, lp.CreatedAt, lp2.CreatedAt)
    65  	assert.NotEqual(t, lp.UpdatedAt, lp2.UpdatedAt)
    66  	assert.NotEqual(t, lp.MarketID, lp2.MarketId)
    67  	assert.NotEqual(t, lp.CommitmentAmount, lp2.CommitmentAmount)
    68  	assert.NotEqual(t, lp.Fee, lp2.Fee)
    69  	assert.NotEqual(t, lp.Version, lp2.Version)
    70  	assert.NotEqual(t, lp.Status, lp2.Status)
    71  	assert.NotEqual(t, lp.Reference, lp2.Reference)
    72  }