Sort received atts by sig (#4287)

This commit is contained in:
terence tsao
2019-12-14 08:51:27 -08:00
committed by Preston Van Loon
parent 89e1200b73
commit 8724dcd41b

View File

@@ -1,8 +1,10 @@
package kv
import (
"encoding/binary"
"math"
"reflect"
"sort"
"strings"
"testing"
"time"
@@ -30,8 +32,8 @@ func TestKV_Unaggregated_CanSaveRetrieve(t *testing.T) {
data := &ethpb.AttestationData{Slot: 100, CommitteeIndex: 99}
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{}, AggregationBits: bitfield.Bitlist{0b101}}
att2 := &ethpb.Attestation{Data: data, Signature: []byte{'A'}, AggregationBits: bitfield.Bitlist{0b110}}
att3 := &ethpb.Attestation{Data: data, Signature: []byte{'B'}, AggregationBits: bitfield.Bitlist{0b110}}
att2 := &ethpb.Attestation{Data: data, Signature: []byte{0,0}, AggregationBits: bitfield.Bitlist{0b110}}
att3 := &ethpb.Attestation{Data: data, Signature: []byte{0,1}, AggregationBits: bitfield.Bitlist{0b110}}
atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts {
@@ -41,8 +43,11 @@ func TestKV_Unaggregated_CanSaveRetrieve(t *testing.T) {
}
returned := cache.UnaggregatedAttestation(data.Slot, data.CommitteeIndex)
wanted := []*ethpb.Attestation{att2, att3}
sort.Slice(returned, func(i, j int) bool {
return binary.BigEndian.Uint16(returned[i].Signature) < binary.BigEndian.Uint16(returned[j].Signature)
})
wanted := []*ethpb.Attestation{att2, att3}
if !reflect.DeepEqual(wanted, returned) {
t.Error("Did not receive correct unaggregated atts")
}