code.vegaprotocol.io/vega@v0.79.0/core/events/oracle_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  	dstypes "code.vegaprotocol.io/vega/core/datasource/common"
    23  	"code.vegaprotocol.io/vega/core/events"
    24  	vegapb "code.vegaprotocol.io/vega/protos/vega"
    25  	datapb "code.vegaprotocol.io/vega/protos/vega/data/v1"
    26  
    27  	"github.com/stretchr/testify/assert"
    28  )
    29  
    30  func TestOracleDataDeepClone(t *testing.T) {
    31  	ctx := context.Background()
    32  	pubKeys := []*dstypes.Signer{
    33  		dstypes.CreateSignerFromString("PK1", dstypes.SignerTypePubKey),
    34  		dstypes.CreateSignerFromString("PK2", dstypes.SignerTypePubKey),
    35  		dstypes.CreateSignerFromString("PK3", dstypes.SignerTypePubKey),
    36  	}
    37  
    38  	od := datapb.ExternalData{
    39  		Data: &datapb.Data{
    40  			Signers: dstypes.SignersIntoProto(pubKeys),
    41  			Data: []*datapb.Property{
    42  				{
    43  					Name:  "Name",
    44  					Value: "Value",
    45  				},
    46  			},
    47  			MatchedSpecIds: []string{
    48  				"MS1", "MS2",
    49  			},
    50  			BroadcastAt: 10000,
    51  		},
    52  	}
    53  
    54  	odEvent := events.NewOracleDataEvent(ctx, vegapb.OracleData{ExternalData: &od})
    55  
    56  	od2 := odEvent.OracleData()
    57  
    58  	// Change the original values
    59  	pk1 := dstypes.CreateSignerFromString("Changed1", dstypes.SignerTypePubKey)
    60  	pk2 := dstypes.CreateSignerFromString("Changed2", dstypes.SignerTypePubKey)
    61  	pk3 := dstypes.CreateSignerFromString("Changed3", dstypes.SignerTypePubKey)
    62  
    63  	od.Data.Signers[0] = pk1.IntoProto()
    64  	od.Data.Signers[1] = pk2.IntoProto()
    65  	od.Data.Signers[2] = pk3.IntoProto()
    66  	od.Data.Data[0].Name = "Changed"
    67  	od.Data.Data[0].Value = "Changed"
    68  	od.Data.MatchedSpecIds[0] = "Changed1"
    69  	od.Data.MatchedSpecIds[1] = "Changed2"
    70  	od.Data.BroadcastAt = 999
    71  
    72  	// Check things have changed
    73  	assert.NotEqual(t, od.Data.Signers[0], od2.ExternalData.Data.Signers[0])
    74  
    75  	assert.NotEqual(t, od.Data.Signers[1], od2.ExternalData.Data.Signers[1])
    76  	assert.NotEqual(t, od.Data.Signers[2], od2.ExternalData.Data.Signers[2])
    77  	assert.NotEqual(t, od.Data.Data[0].Name, od2.ExternalData.Data.Data[0].Name)
    78  	assert.NotEqual(t, od.Data.Data[0].Value, od2.ExternalData.Data.Data[0].Value)
    79  	assert.NotEqual(t, od.Data.MatchedSpecIds[0], od2.ExternalData.Data.MatchedSpecIds[0])
    80  	assert.NotEqual(t, od.Data.MatchedSpecIds[1], od2.ExternalData.Data.MatchedSpecIds[1])
    81  	assert.NotEqual(t, od.Data.BroadcastAt, od2.ExternalData.Data.BroadcastAt)
    82  }