proposerpolicy_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. package validator
  17. import (
  18. "testing"
  19. "github.com/ethereum/go-ethereum/common"
  20. "github.com/ethereum/go-ethereum/consensus/istanbul"
  21. "github.com/stretchr/testify/assert"
  22. )
  23. func TestProposerPolicy(t *testing.T) {
  24. addr1 := common.HexToAddress("0xc53f2189bf6d7bf56722731787127f90d319e112")
  25. addr2 := common.HexToAddress("0xed2d479591fe2c5626ce09bca4ed2a62e00e5bc2")
  26. addr3 := common.HexToAddress("0xc8417f834995aaeb35f342a67a4961e19cd4735c")
  27. addr4 := common.HexToAddress("0x784ae51f5013b51c8360afdf91c6bc5a16f586ea")
  28. addr5 := common.HexToAddress("0xecf0974e6f0630fd91ea4da8399cdb3f59e5220f")
  29. addr6 := common.HexToAddress("0x411c4d11acd714b82a5242667e36de14b9e1d10b")
  30. addrSet := []common.Address{addr1, addr2, addr3, addr4, addr5, addr6}
  31. addressSortedByByte := []common.Address{addr6, addr4, addr1, addr3, addr5, addr2}
  32. addressSortedByString := []common.Address{addr6, addr4, addr1, addr2, addr5, addr3}
  33. pp := istanbul.NewRoundRobinProposerPolicy()
  34. pp.Use(istanbul.ValidatorSortByByte())
  35. valSet := NewSet(addrSet, pp)
  36. valList := valSet.List()
  37. for i := 0; i < 6; i++ {
  38. assert.Equal(t, addressSortedByByte[i].Hex(), valList[i].String(), "validatorSet not byte sorted")
  39. }
  40. pp.Use(istanbul.ValidatorSortByString())
  41. for i := 0; i < 6; i++ {
  42. assert.Equal(t, addressSortedByString[i].Hex(), valList[i].String(), "validatorSet not string sorted")
  43. }
  44. }