github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go (about) 1 package sync 2 3 import ( 4 "context" 5 "testing" 6 7 lru "github.com/hashicorp/golang-lru" 8 "github.com/prysmaticlabs/go-bitfield" 9 mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" 10 "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" 11 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 12 "github.com/prysmaticlabs/prysm/shared/testutil" 13 "github.com/prysmaticlabs/prysm/shared/testutil/assert" 14 "github.com/prysmaticlabs/prysm/shared/testutil/require" 15 ) 16 17 func TestBeaconAggregateProofSubscriber_CanSaveAggregatedAttestation(t *testing.T) { 18 c, err := lru.New(10) 19 require.NoError(t, err) 20 r := &Service{ 21 cfg: &Config{ 22 AttPool: attestations.NewPool(), 23 AttestationNotifier: (&mock.ChainService{}).OperationNotifier(), 24 }, 25 seenUnAggregatedAttestationCache: c, 26 } 27 28 a := ðpb.SignedAggregateAttestationAndProof{ 29 Message: ðpb.AggregateAttestationAndProof{ 30 Aggregate: testutil.HydrateAttestation(ðpb.Attestation{ 31 AggregationBits: bitfield.Bitlist{0x07}, 32 }), 33 AggregatorIndex: 100, 34 }, 35 Signature: make([]byte, 96), 36 } 37 require.NoError(t, r.beaconAggregateProofSubscriber(context.Background(), a)) 38 assert.DeepSSZEqual(t, []*ethpb.Attestation{a.Message.Aggregate}, r.cfg.AttPool.AggregatedAttestations(), "Did not save aggregated attestation") 39 } 40 41 func TestBeaconAggregateProofSubscriber_CanSaveUnaggregatedAttestation(t *testing.T) { 42 c, err := lru.New(10) 43 require.NoError(t, err) 44 r := &Service{ 45 cfg: &Config{ 46 AttPool: attestations.NewPool(), 47 AttestationNotifier: (&mock.ChainService{}).OperationNotifier(), 48 }, 49 seenUnAggregatedAttestationCache: c, 50 } 51 52 a := ðpb.SignedAggregateAttestationAndProof{ 53 Message: ðpb.AggregateAttestationAndProof{ 54 Aggregate: testutil.HydrateAttestation(ðpb.Attestation{ 55 AggregationBits: bitfield.Bitlist{0x03}, 56 Signature: make([]byte, 96), 57 }), 58 AggregatorIndex: 100, 59 }, 60 } 61 require.NoError(t, r.beaconAggregateProofSubscriber(context.Background(), a)) 62 63 atts, err := r.cfg.AttPool.UnaggregatedAttestations() 64 require.NoError(t, err) 65 assert.DeepEqual(t, []*ethpb.Attestation{a.Message.Aggregate}, atts, "Did not save unaggregated attestation") 66 }