prysm-pulse/beacon-chain/sync/subscriber_beacon_aggregate_proof_test.go
Victor Farazdagi c2615168d9
Applies assertion funcs to sync tests (#6603)
* applies assertion funcs to sync/initial-sync tests
* applies assertion funcs to sync/initial-sync tests
* gazelle
* Merge branch 'master' into sync-apply-testutils-assertions
* gazelle
* applies assertion funcs to sync/initial-sync tests
* applies assertion funcs to sync/initial-sync tests
* applies assertion funcs to sync/initial-sync tests
* applies assertion funcs to sync/initial-sync tests
* applies assertion funcs to sync/initial-sync tests
* Merge branch 'master' into sync-apply-testutils-assertions
2020-07-15 04:41:11 +00:00

43 lines
1.9 KiB
Go

package sync
import (
"context"
"testing"
lru "github.com/hashicorp/golang-lru"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield"
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestBeaconAggregateProofSubscriber_CanSaveAggregatedAttestation(t *testing.T) {
c, err := lru.New(10)
require.NoError(t, err)
r := &Service{
attPool: attestations.NewPool(),
seenAttestationCache: c,
attestationNotifier: (&mock.ChainService{}).OperationNotifier(),
}
a := &ethpb.SignedAggregateAttestationAndProof{Message: &ethpb.AggregateAttestationAndProof{Aggregate: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{}}, AggregationBits: bitfield.Bitlist{0x07}}, AggregatorIndex: 100}}
require.NoError(t, r.beaconAggregateProofSubscriber(context.Background(), a))
assert.DeepEqual(t, []*ethpb.Attestation{a.Message.Aggregate}, r.attPool.AggregatedAttestations(), "Did not save aggregated attestation")
}
func TestBeaconAggregateProofSubscriber_CanSaveUnaggregatedAttestation(t *testing.T) {
c, err := lru.New(10)
require.NoError(t, err)
r := &Service{
attPool: attestations.NewPool(),
seenAttestationCache: c,
attestationNotifier: (&mock.ChainService{}).OperationNotifier(),
}
a := &ethpb.SignedAggregateAttestationAndProof{Message: &ethpb.AggregateAttestationAndProof{Aggregate: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{}}, AggregationBits: bitfield.Bitlist{0x03}}, AggregatorIndex: 100}}
require.NoError(t, r.beaconAggregateProofSubscriber(context.Background(), a))
assert.DeepEqual(t, []*ethpb.Attestation{a.Message.Aggregate}, r.attPool.UnaggregatedAttestations(), "Did not save unaggregated attestation")
}