code.vegaprotocol.io/vega@v0.79.0/core/events/governance_proposal_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  	proto "code.vegaprotocol.io/vega/protos/vega"
    25  
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  func TestAssetProposalNewAssetDeepClone(t *testing.T) {
    30  	ctx := context.Background()
    31  
    32  	p := types.Proposal{
    33  		ID:        "Id",
    34  		Reference: "Reference",
    35  		Party:     "PartyId",
    36  		State:     types.ProposalStateDeclined,
    37  		Timestamp: 100000,
    38  		Rationale: &types.ProposalRationale{
    39  			Description: "Wen moon!",
    40  			Title:       "0xdeadbeef",
    41  		},
    42  		Terms: &types.ProposalTerms{
    43  			ClosingTimestamp:    2000000,
    44  			EnactmentTimestamp:  3000000,
    45  			ValidationTimestamp: 4000000,
    46  			Change: &types.ProposalTermsNewAsset{
    47  				NewAsset: &types.NewAsset{
    48  					Changes: &types.AssetDetails{
    49  						Source: &types.AssetDetailsErc20{
    50  							ERC20: &types.ERC20{
    51  								ContractAddress: "Address",
    52  								ChainID:         "1",
    53  							},
    54  						},
    55  					},
    56  				},
    57  			},
    58  		},
    59  	}
    60  
    61  	proposalEvent := events.NewProposalEvent(ctx, p)
    62  	p2 := proposalEvent.Proposal()
    63  
    64  	// Change the original and check we are not updating the wrapped event
    65  	p.ID = "Changed"
    66  	p.Reference = "Changed"
    67  	p.Party = "Changed"
    68  	p.State = types.ProposalStateEnacted
    69  	p.Timestamp = 999
    70  	p.Terms.ClosingTimestamp = 999
    71  	p.Terms.EnactmentTimestamp = 888
    72  	p.Terms.ValidationTimestamp = 777
    73  	p.Rationale.Description = "Wen mars!"
    74  	p.Rationale.Title = "oxcafed00d"
    75  
    76  	na := p.Terms.Change.(*types.ProposalTermsNewAsset)
    77  	erc := na.NewAsset.Changes.Source.(*types.AssetDetailsErc20)
    78  	erc.ERC20.ContractAddress = "Changed"
    79  
    80  	assert.NotEqual(t, p.ID, p2.Id)
    81  	assert.NotEqual(t, p.Reference, p2.Reference)
    82  	assert.NotEqual(t, p.Party, p2.PartyId)
    83  	assert.NotEqual(t, p.State, p2.State)
    84  	assert.NotEqual(t, p.Timestamp, p2.Timestamp)
    85  
    86  	term := p.Terms
    87  	term2 := p2.Terms
    88  	assert.NotEqual(t, term.ClosingTimestamp, term2.ClosingTimestamp)
    89  	assert.NotEqual(t, term.EnactmentTimestamp, term2.EnactmentTimestamp)
    90  	assert.NotEqual(t, term.ValidationTimestamp, term2.ValidationTimestamp)
    91  
    92  	rationale := p.Rationale
    93  	rationale2 := p2.Rationale
    94  	assert.NotEqual(t, rationale.Description, rationale2.Description)
    95  	assert.NotEqual(t, rationale.Title, rationale2.Title)
    96  
    97  	na2 := p2.Terms.Change.(*proto.ProposalTerms_NewAsset)
    98  	erc2 := na2.NewAsset.Changes.Source.(*proto.AssetDetails_Erc20)
    99  	assert.NotEqual(t, erc.ERC20.ContractAddress, erc2.Erc20.ContractAddress)
   100  }