code.vegaprotocol.io/vega@v0.79.0/core/events/validator_update_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 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 24 25 "github.com/stretchr/testify/assert" 26 ) 27 28 const ( 29 nodeID = "vega-master-public-key" 30 vegaPublicKey = "vega-public-key" 31 vegaPublicKeyIndex = 1 32 ethAddress = "eth-address" 33 tmPublicKey = "tm-public-key" 34 infoURL = "no1.xyz.vega/nodes/a" 35 country = "GB" 36 name = "Validator" 37 avatarURL = "https://not-an-avatar.com" 38 fromEpoch = 5 39 epochSeq = 2 40 ) 41 42 func TestValidatorUpdate(t *testing.T) { 43 t.Run("returns public key", func(t *testing.T) { 44 ctx := context.Background() 45 vu := events.NewValidatorUpdateEvent(ctx, nodeID, vegaPublicKey, vegaPublicKeyIndex, ethAddress, tmPublicKey, infoURL, country, name, avatarURL, fromEpoch, true, epochSeq) 46 47 assert.Equal(t, vegaPublicKey, vu.VegaPublicKey()) 48 }) 49 50 t.Run("returns Tendermint public key", func(t *testing.T) { 51 ctx := context.Background() 52 vu := events.NewValidatorUpdateEvent(ctx, nodeID, vegaPublicKey, vegaPublicKeyIndex, ethAddress, tmPublicKey, infoURL, country, name, avatarURL, fromEpoch, true, epochSeq) 53 54 assert.Equal(t, tmPublicKey, vu.TendermintPublicKey()) 55 }) 56 57 t.Run("returns info url", func(t *testing.T) { 58 ctx := context.Background() 59 vu := events.NewValidatorUpdateEvent(ctx, nodeID, vegaPublicKey, vegaPublicKeyIndex, ethAddress, tmPublicKey, infoURL, country, name, avatarURL, fromEpoch, true, epochSeq) 60 61 assert.Equal(t, infoURL, vu.InfoURL()) 62 }) 63 64 t.Run("returns country", func(t *testing.T) { 65 ctx := context.Background() 66 vu := events.NewValidatorUpdateEvent(ctx, nodeID, vegaPublicKey, vegaPublicKeyIndex, ethAddress, tmPublicKey, infoURL, country, name, avatarURL, fromEpoch, true, epochSeq) 67 68 assert.Equal(t, country, vu.Country()) 69 }) 70 71 t.Run("returns validator update event proto", func(t *testing.T) { 72 ctx := context.Background() 73 vu := events.NewValidatorUpdateEvent(ctx, nodeID, vegaPublicKey, vegaPublicKeyIndex, ethAddress, tmPublicKey, infoURL, country, name, avatarURL, fromEpoch, true, epochSeq) 74 75 expected := eventspb.ValidatorUpdate{ 76 NodeId: nodeID, 77 VegaPubKey: vegaPublicKey, 78 VegaPubKeyIndex: vegaPublicKeyIndex, 79 EthereumAddress: ethAddress, 80 TmPubKey: tmPublicKey, 81 InfoUrl: infoURL, 82 Country: country, 83 Name: name, 84 AvatarUrl: avatarURL, 85 FromEpoch: fromEpoch, 86 Added: true, 87 EpochSeq: epochSeq, 88 } 89 90 assert.Equal(t, expected, vu.Proto()) 91 }) 92 93 t.Run("returns stream message with validator update", func(t *testing.T) { 94 ctx := context.Background() 95 vu := events.NewValidatorUpdateEvent(ctx, nodeID, vegaPublicKey, vegaPublicKeyIndex, ethAddress, tmPublicKey, infoURL, country, name, avatarURL, fromEpoch, true, epochSeq) 96 97 vuProto := eventspb.ValidatorUpdate{ 98 NodeId: nodeID, 99 VegaPubKey: vegaPublicKey, 100 VegaPubKeyIndex: vegaPublicKeyIndex, 101 EthereumAddress: ethAddress, 102 TmPubKey: tmPublicKey, 103 InfoUrl: infoURL, 104 Country: country, 105 Name: name, 106 AvatarUrl: avatarURL, 107 FromEpoch: fromEpoch, 108 Added: true, 109 EpochSeq: epochSeq, 110 } 111 112 expectedUpdate := &eventspb.BusEvent_ValidatorUpdate{ 113 ValidatorUpdate: &vuProto, 114 } 115 116 expectedType := eventspb.BusEventType_BUS_EVENT_TYPE_VALIDATOR_UPDATE 117 118 sm := vu.StreamMessage() 119 120 assert.Equal(t, expectedUpdate, sm.Event) 121 assert.Equal(t, expectedType, sm.Type) 122 }) 123 }