github.com/electroneum/electroneum-sc@v0.0.0-20230105223411-3bc1d078281e/consensus/istanbul/validator/proposerpolicy_test.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package validator 18 19 import ( 20 "testing" 21 22 "github.com/electroneum/electroneum-sc/common" 23 "github.com/electroneum/electroneum-sc/consensus/istanbul" 24 "github.com/stretchr/testify/assert" 25 ) 26 27 func TestProposerPolicy(t *testing.T) { 28 addr1 := common.HexToAddress("0xc53f2189bf6d7bf56722731787127f90d319e112") 29 addr2 := common.HexToAddress("0xed2d479591fe2c5626ce09bca4ed2a62e00e5bc2") 30 addr3 := common.HexToAddress("0xc8417f834995aaeb35f342a67a4961e19cd4735c") 31 addr4 := common.HexToAddress("0x784ae51f5013b51c8360afdf91c6bc5a16f586ea") 32 addr5 := common.HexToAddress("0xecf0974e6f0630fd91ea4da8399cdb3f59e5220f") 33 addr6 := common.HexToAddress("0x411c4d11acd714b82a5242667e36de14b9e1d10b") 34 35 addrSet := []common.Address{addr1, addr2, addr3, addr4, addr5, addr6} 36 addressSortedByByte := []common.Address{addr6, addr4, addr1, addr3, addr5, addr2} 37 addressSortedByString := []common.Address{addr6, addr4, addr1, addr2, addr5, addr3} 38 39 pp := istanbul.NewRoundRobinProposerPolicy() 40 pp.Use(istanbul.ValidatorSortByByte()) 41 42 valSet := NewSet(addrSet, pp) 43 valList := valSet.List() 44 45 for i := 0; i < 6; i++ { 46 assert.Equal(t, addressSortedByByte[i].Hex(), valList[i].String(), "validatorSet not byte sorted") 47 } 48 49 pp.Use(istanbul.ValidatorSortByString()) 50 for i := 0; i < 6; i++ { 51 assert.Equal(t, addressSortedByString[i].Hex(), valList[i].String(), "validatorSet not string sorted") 52 } 53 }