mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
ba07ccb484
* slasher/beaconclient tests * slasher/db/kv tests * Merge branch 'master' into apply-testutils-assertions-to-slasher * fix build * slasher/detection tests * rest of the tests * misc tests * tools tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * agg tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * updates aggregated_test * beacon-chain/operations/attestations/kv/* tests updated * beacon-chain/operations/attestations tests updated * beacon-chain/operations/slashings tests updated * Merge branch 'master' into apply-testutils-assertions-misc * gazelle * beacon-chain/core tests updated * fixes test * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/rpc tests updated * beacon-chain/sync/initial-sync tests * misc tests * optimizes error message parsing in testutils * Merge branch 'assertutils-optimize-processing' into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * endtoend tests * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * beacon-chain/blockchain tests updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/state/stategen tests updated * beacon-chain all left-over tests are done * Merge refs/heads/master into apply-testutils-assertions-misc * validator tests updated * slasher tests * Merge branch 'master' into apply-testutils-assertions-misc * gofmt * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * shared upd * end2end tests deps fixed * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * misc * all tests are updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc
175 lines
5.5 KiB
Go
175 lines
5.5 KiB
Go
package kv
|
|
|
|
import (
|
|
"testing"
|
|
|
|
c "github.com/patrickmn/go-cache"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestKV_Unaggregated_SaveUnaggregatedAttestation(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
att *ethpb.Attestation
|
|
count int
|
|
wantErrString string
|
|
}{
|
|
{
|
|
name: "nil attestation",
|
|
att: nil,
|
|
},
|
|
{
|
|
name: "already aggregated",
|
|
att: ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b10101}},
|
|
wantErrString: "attestation is aggregated",
|
|
},
|
|
{
|
|
name: "invalid hash",
|
|
att: ðpb.Attestation{
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: []byte{0b0},
|
|
},
|
|
},
|
|
wantErrString: "incorrect fixed bytes marshalling",
|
|
},
|
|
{
|
|
name: "normal save",
|
|
att: ðpb.Attestation{
|
|
Data: ðpb.AttestationData{
|
|
Slot: 100,
|
|
},
|
|
AggregationBits: bitfield.Bitlist{0b0001},
|
|
},
|
|
count: 1,
|
|
},
|
|
{
|
|
name: "already seen",
|
|
att: ðpb.Attestation{
|
|
Data: ðpb.AttestationData{
|
|
Slot: 100,
|
|
},
|
|
AggregationBits: bitfield.Bitlist{0b10000001},
|
|
},
|
|
count: 0,
|
|
},
|
|
}
|
|
r, err := hashFn(ðpb.AttestationData{
|
|
Slot: 100,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
cache.seenAtt.Set(string(r[:]), []bitfield.Bitlist{{0xff}}, c.DefaultExpiration)
|
|
assert.Equal(t, 0, len(cache.unAggregatedAtt), "Invalid start pool, atts: %d", len(cache.unAggregatedAtt))
|
|
|
|
err := cache.SaveUnaggregatedAttestation(tt.att)
|
|
if tt.wantErrString != "" {
|
|
assert.ErrorContains(t, tt.wantErrString, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
assert.Equal(t, tt.count, len(cache.unAggregatedAtt), "Wrong attestation count")
|
|
assert.Equal(t, tt.count, cache.UnaggregatedAttestationCount(), "Wrong attestation count")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestKV_Unaggregated_SaveUnaggregatedAttestations(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
atts []*ethpb.Attestation
|
|
count int
|
|
wantErrString string
|
|
}{
|
|
{
|
|
name: "unaggregated only",
|
|
atts: []*ethpb.Attestation{
|
|
{Data: ðpb.AttestationData{Slot: 1}},
|
|
{Data: ðpb.AttestationData{Slot: 2}},
|
|
{Data: ðpb.AttestationData{Slot: 3}},
|
|
},
|
|
count: 3,
|
|
},
|
|
{
|
|
name: "has aggregated",
|
|
atts: []*ethpb.Attestation{
|
|
{Data: ðpb.AttestationData{Slot: 1}},
|
|
{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}},
|
|
{Data: ðpb.AttestationData{Slot: 3}},
|
|
},
|
|
wantErrString: "attestation is aggregated",
|
|
count: 1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
assert.Equal(t, 0, len(cache.unAggregatedAtt), "Invalid start pool, atts: %d", len(cache.unAggregatedAtt))
|
|
|
|
err := cache.SaveUnaggregatedAttestations(tt.atts)
|
|
if tt.wantErrString != "" {
|
|
assert.ErrorContains(t, tt.wantErrString, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
assert.Equal(t, tt.count, len(cache.unAggregatedAtt), "Wrong attestation count")
|
|
assert.Equal(t, tt.count, cache.UnaggregatedAttestationCount(), "Wrong attestation count")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
|
|
t.Run("nil attestation", func(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
assert.NoError(t, cache.DeleteUnaggregatedAttestation(nil))
|
|
})
|
|
|
|
t.Run("aggregated attestation", func(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b1111}, Data: ðpb.AttestationData{Slot: 2}}
|
|
err := cache.DeleteUnaggregatedAttestation(att)
|
|
assert.ErrorContains(t, "attestation is aggregated", err)
|
|
})
|
|
|
|
t.Run("successful deletion", func(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}}
|
|
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
require.NoError(t, cache.SaveUnaggregatedAttestations(atts))
|
|
for _, att := range atts {
|
|
assert.NoError(t, cache.DeleteUnaggregatedAttestation(att))
|
|
}
|
|
returned, err := cache.UnaggregatedAttestations()
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, []*ethpb.Attestation{}, returned)
|
|
})
|
|
}
|
|
|
|
func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b101}}
|
|
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 2}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
require.NoError(t, cache.SaveUnaggregatedAttestation(att))
|
|
}
|
|
|
|
returned := cache.UnaggregatedAttestationsBySlotIndex(1, 1)
|
|
assert.DeepEqual(t, []*ethpb.Attestation{att1}, returned)
|
|
returned = cache.UnaggregatedAttestationsBySlotIndex(1, 2)
|
|
assert.DeepEqual(t, []*ethpb.Attestation{att2}, returned)
|
|
returned = cache.UnaggregatedAttestationsBySlotIndex(2, 1)
|
|
assert.DeepEqual(t, []*ethpb.Attestation{att3}, returned)
|
|
}
|