mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Check empty list
This commit is contained in:
parent
152b564ef7
commit
0afd81cc40
2 changed files with 12 additions and 0 deletions
|
|
@ -447,6 +447,9 @@ func (c *Posv) verifyCascadingFields(chain consensus.ChainReader, header *types.
|
||||||
// compare 2 signers lists
|
// compare 2 signers lists
|
||||||
// return true if they are same elements, otherwise return false
|
// return true if they are same elements, otherwise return false
|
||||||
func compareSignersLists(list1 []common.Address, list2 []common.Address) bool {
|
func compareSignersLists(list1 []common.Address, list2 []common.Address) bool {
|
||||||
|
if len(list1) == 0 && len(list2) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
sort.Slice(list1, func(i, j int) bool {
|
sort.Slice(list1, func(i, j int) bool {
|
||||||
return list1[i].String() <= list1[j].String()
|
return list1[i].String() <= list1[j].String()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -72,4 +72,13 @@ func TestCompareSignersLists(t *testing.T) {
|
||||||
if compareSignersLists(list1, list3) {
|
if compareSignersLists(list1, list3) {
|
||||||
t.Error("list1 and list3 should not be same", "list1", list1, "list3", list3)
|
t.Error("list1 and list3 should not be same", "list1", list1, "list3", list3)
|
||||||
}
|
}
|
||||||
|
if !compareSignersLists([]common.Address{}, []common.Address{}) {
|
||||||
|
t.Error("Failed with empty list")
|
||||||
|
}
|
||||||
|
if !compareSignersLists([]common.Address{common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc")}, []common.Address{common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc")}) {
|
||||||
|
t.Error("Failed with list has only one signer")
|
||||||
|
}
|
||||||
|
if compareSignersLists([]common.Address{common.StringToAddress("aaaaaaaaaaaaaaaa")}, []common.Address{common.StringToAddress("cccccccccccccccccccccccccccccccccccccccc")}) {
|
||||||
|
t.Error("Failed with list has only one signer")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue