mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
02966e64d8
* Add Wrapper to LRU Cache to handle Invalid Parameters #9461 * Regenerate BUILD.bazel and simplify tests using lru.Cache * Fix: fuzz_exports.go build error * Fix: block_fuzz.go * Revert lru.Cache interface * Remove redundant err check in pending_attestations_queue_test.go * Add tests for lru wrapper * Use lru package in prysm/shared instead of lruwrpr * Fix: goimports * Fix: BUILD.bazel Co-authored-by: Nishant Das <nishdas93@gmail.com>
63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
lruwrpr "github.com/prysmaticlabs/prysm/shared/lru"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestBeaconAggregateProofSubscriber_CanSaveAggregatedAttestation(t *testing.T) {
|
|
r := &Service{
|
|
cfg: &Config{
|
|
AttPool: attestations.NewPool(),
|
|
OperationNotifier: (&mock.ChainService{}).OperationNotifier(),
|
|
},
|
|
seenUnAggregatedAttestationCache: lruwrpr.New(10),
|
|
}
|
|
|
|
a := ðpb.SignedAggregateAttestationAndProof{
|
|
Message: ðpb.AggregateAttestationAndProof{
|
|
Aggregate: testutil.HydrateAttestation(ðpb.Attestation{
|
|
AggregationBits: bitfield.Bitlist{0x07},
|
|
}),
|
|
AggregatorIndex: 100,
|
|
},
|
|
Signature: make([]byte, 96),
|
|
}
|
|
require.NoError(t, r.beaconAggregateProofSubscriber(context.Background(), a))
|
|
assert.DeepSSZEqual(t, []*ethpb.Attestation{a.Message.Aggregate}, r.cfg.AttPool.AggregatedAttestations(), "Did not save aggregated attestation")
|
|
}
|
|
|
|
func TestBeaconAggregateProofSubscriber_CanSaveUnaggregatedAttestation(t *testing.T) {
|
|
r := &Service{
|
|
cfg: &Config{
|
|
AttPool: attestations.NewPool(),
|
|
OperationNotifier: (&mock.ChainService{}).OperationNotifier(),
|
|
},
|
|
seenUnAggregatedAttestationCache: lruwrpr.New(10),
|
|
}
|
|
|
|
a := ðpb.SignedAggregateAttestationAndProof{
|
|
Message: ðpb.AggregateAttestationAndProof{
|
|
Aggregate: testutil.HydrateAttestation(ðpb.Attestation{
|
|
AggregationBits: bitfield.Bitlist{0x03},
|
|
Signature: make([]byte, 96),
|
|
}),
|
|
AggregatorIndex: 100,
|
|
},
|
|
}
|
|
require.NoError(t, r.beaconAggregateProofSubscriber(context.Background(), a))
|
|
|
|
atts, err := r.cfg.AttPool.UnaggregatedAttestations()
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, []*ethpb.Attestation{a.Message.Aggregate}, atts, "Did not save unaggregated attestation")
|
|
}
|