mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 02:02:18 +00:00
d53539499c
* Update kv aggregated_test.go * Update block_test.go * Update forkchoice_test.go * Update unaggregated_test.go * Update prepare_forkchoice_test.go * Update prune_expired_test.go * Update atts service_test.go * Update service_attester_test.go * Update service_proposer_test.go * Upate exit service_test.go * Gaz * Merge branch 'master' of github.com:prysmaticlabs/prysm * Move averageBalance from log.go to info.go * Move avg balance from log.go to info.go * Add info test * Remove unused logEpochData in log.go * Gaz * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * aggregation tests * attestation util tests * bench util tests * block util tests * herumi tests * bytesutil tests * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Update shared/aggregation/attestations/attestations_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Merge branch 'master' of github.com:prysmaticlabs/prysm into testutil-shared * Fixed ordering * Merge branch 'testutil-shared' of github.com:prysmaticlabs/prysm into testutil-shared * Update shared/aggregation/attestations/attestations_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update shared/bytesutil/bytes_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
102 lines
2.7 KiB
Go
102 lines
2.7 KiB
Go
package attestations
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/prysm/shared/aggregation"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
)
|
|
|
|
func TestAggregateAttestations_MaxCover_NewMaxCover(t *testing.T) {
|
|
type args struct {
|
|
atts []*ethpb.Attestation
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *aggregation.MaxCoverProblem
|
|
wantErr bool
|
|
expectedErr error
|
|
}{
|
|
{
|
|
name: "nil attestations",
|
|
args: args{
|
|
atts: nil,
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
expectedErr: ErrInvalidAttestationCount,
|
|
},
|
|
{
|
|
name: "no attestations",
|
|
args: args{
|
|
atts: []*ethpb.Attestation{},
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
expectedErr: ErrInvalidAttestationCount,
|
|
},
|
|
{
|
|
name: "attestations of different bitlist length",
|
|
args: args{
|
|
atts: []*ethpb.Attestation{
|
|
{AggregationBits: bitfield.NewBitlist(64)},
|
|
{AggregationBits: bitfield.NewBitlist(128)},
|
|
},
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
expectedErr: aggregation.ErrBitsDifferentLen,
|
|
},
|
|
{
|
|
name: "single attestation",
|
|
args: args{
|
|
atts: []*ethpb.Attestation{
|
|
{AggregationBits: bitfield.Bitlist{0b00001010, 0b1}},
|
|
},
|
|
},
|
|
want: &aggregation.MaxCoverProblem{
|
|
Candidates: aggregation.MaxCoverCandidates{
|
|
aggregation.NewMaxCoverCandidate(0, &bitfield.Bitlist{0b00001010, 0b1}),
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
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}},
|
|
},
|
|
},
|
|
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}),
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NewMaxCover(tt.args.atts)
|
|
if (err != nil) != tt.wantErr || !errors.Is(err, tt.expectedErr) {
|
|
t.Errorf("NewMaxCoverProblem() unexpected error, got: %v, want: %v", err, tt.expectedErr)
|
|
return
|
|
}
|
|
assert.DeepEqual(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|