2020-06-23 04:00:38 +00:00
|
|
|
package attestations
|
2020-06-18 20:56:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
2020-06-23 04:00:38 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/aggregation"
|
2020-07-18 16:31:42 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
2020-06-18 20:56:23 +00:00
|
|
|
)
|
|
|
|
|
2020-06-23 04:00:38 +00:00
|
|
|
func TestAggregateAttestations_MaxCover_NewMaxCover(t *testing.T) {
|
2020-06-18 20:56:23 +00:00
|
|
|
type args struct {
|
|
|
|
atts []*ethpb.Attestation
|
|
|
|
}
|
|
|
|
tests := []struct {
|
2020-08-25 15:23:06 +00:00
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want *aggregation.MaxCoverProblem
|
|
|
|
wantedErr string
|
2020-06-18 20:56:23 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil attestations",
|
|
|
|
args: args{
|
|
|
|
atts: nil,
|
|
|
|
},
|
2020-08-25 15:23:06 +00:00
|
|
|
wantedErr: ErrInvalidAttestationCount.Error(),
|
2020-06-18 20:56:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no attestations",
|
|
|
|
args: args{
|
|
|
|
atts: []*ethpb.Attestation{},
|
|
|
|
},
|
2020-08-25 15:23:06 +00:00
|
|
|
wantedErr: ErrInvalidAttestationCount.Error(),
|
2020-06-18 20:56:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "attestations of different bitlist length",
|
|
|
|
args: args{
|
|
|
|
atts: []*ethpb.Attestation{
|
|
|
|
{AggregationBits: bitfield.NewBitlist(64)},
|
|
|
|
{AggregationBits: bitfield.NewBitlist(128)},
|
|
|
|
},
|
|
|
|
},
|
2020-08-25 15:23:06 +00:00
|
|
|
wantedErr: aggregation.ErrBitsDifferentLen.Error(),
|
2020-06-18 20:56:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single attestation",
|
|
|
|
args: args{
|
|
|
|
atts: []*ethpb.Attestation{
|
|
|
|
{AggregationBits: bitfield.Bitlist{0b00001010, 0b1}},
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 04:00:38 +00:00
|
|
|
want: &aggregation.MaxCoverProblem{
|
|
|
|
Candidates: aggregation.MaxCoverCandidates{
|
|
|
|
aggregation.NewMaxCoverCandidate(0, &bitfield.Bitlist{0b00001010, 0b1}),
|
2020-06-18 20:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple attestations",
|
|
|
|
args: args{
|
|
|
|
atts: []*ethpb.Attestation{
|
|
|
|
{AggregationBits: bitfield.Bitlist{0b00001010, 0b1}},
|
|
|
|
{AggregationBits: bitfield.Bitlist{0b00101010, 0b1}},
|
|
|
|
{AggregationBits: bitfield.Bitlist{0b11111010, 0b1}},
|
|
|
|
{AggregationBits: bitfield.Bitlist{0b00000010, 0b1}},
|
|
|
|
{AggregationBits: bitfield.Bitlist{0b00000001, 0b1}},
|
|
|
|
},
|
|
|
|
},
|
2020-06-23 04:00:38 +00:00
|
|
|
want: &aggregation.MaxCoverProblem{
|
|
|
|
Candidates: aggregation.MaxCoverCandidates{
|
|
|
|
aggregation.NewMaxCoverCandidate(0, &bitfield.Bitlist{0b00001010, 0b1}),
|
|
|
|
aggregation.NewMaxCoverCandidate(1, &bitfield.Bitlist{0b00101010, 0b1}),
|
|
|
|
aggregation.NewMaxCoverCandidate(2, &bitfield.Bitlist{0b11111010, 0b1}),
|
|
|
|
aggregation.NewMaxCoverCandidate(3, &bitfield.Bitlist{0b00000010, 0b1}),
|
|
|
|
aggregation.NewMaxCoverCandidate(4, &bitfield.Bitlist{0b00000001, 0b1}),
|
2020-06-18 20:56:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-06-23 04:00:38 +00:00
|
|
|
got, err := NewMaxCover(tt.args.atts)
|
2020-08-25 15:23:06 +00:00
|
|
|
if tt.wantedErr != "" {
|
|
|
|
assert.ErrorContains(t, tt.wantedErr, err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.DeepEqual(t, tt.want, got)
|
2020-06-18 20:56:23 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|