Check empty list

This commit is contained in:
NguyenNguyen 2019-04-11 14:10:27 +07:00
parent 152b564ef7
commit 0afd81cc40
2 changed files with 12 additions and 0 deletions

View file

@ -447,6 +447,9 @@ func (c *Posv) verifyCascadingFields(chain consensus.ChainReader, header *types.
// compare 2 signers lists
// return true if they are same elements, otherwise return false
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 {
return list1[i].String() <= list1[j].String()
})

View file

@ -72,4 +72,13 @@ func TestCompareSignersLists(t *testing.T) {
if compareSignersLists(list1, 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")
}
}