mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
34178aff2a
* Verify attestations before putting them into the pool * use existing method * Validate aggregated ones too * Revert "Validate aggregated ones too" This reverts commit a55646d131813c3e65e0539ef5b2e5bda19a5e91. * Merge branch 'master' of github.com:prysmaticlabs/prysm into verify-all-atts * Add feature flag * The remaining shared reference fields with conditional copy on write * Merge branch 'master' into better-copy-2 * Merge branch 'better-copy-2' of github.com:prysmaticlabs/prysm into verify-all-atts * gaz * fix build, put into validate * lint * Merge branch 'master' of github.com:prysmaticlabs/prysm into verify-all-atts * why does goland do this to me * revert unrelated change * fix tests * Update shared/featureconfig/config.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Merge refs/heads/master into verify-all-atts * Update beacon-chain/blockchain/testing/mock.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * gofmt
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
|
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
|
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
|
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
|
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
)
|
|
|
|
func TestService_committeeIndexBeaconAttestationSubscriber_ValidMessage(t *testing.T) {
|
|
p := p2ptest.NewTestP2P(t)
|
|
|
|
ctx := context.Background()
|
|
db := dbtest.SetupDB(t)
|
|
defer dbtest.TeardownDB(t, db)
|
|
s, sKeys := testutil.DeterministicGenesisState(t, 64 /*validators*/)
|
|
if err := s.SetGenesisTime(uint64(time.Now().Unix())); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
blk, err := testutil.GenerateFullBlock(s, sKeys, nil, 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
root, err := ssz.HashTreeRoot(blk.Block)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := db.SaveBlock(ctx, blk); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := &Service{
|
|
attPool: attestations.NewPool(),
|
|
chain: &mock.ChainService{
|
|
State: s,
|
|
Genesis: time.Now(),
|
|
ValidAttestation: true,
|
|
},
|
|
chainStarted: true,
|
|
p2p: p,
|
|
db: db,
|
|
ctx: ctx,
|
|
stateNotifier: (&mock.ChainService{}).StateNotifier(),
|
|
initialSync: &mockSync.Sync{IsSyncing: false},
|
|
}
|
|
r.registerSubscribers()
|
|
r.stateNotifier.StateFeed().Send(&feed.Event{
|
|
Type: statefeed.Initialized,
|
|
Data: &statefeed.InitializedData{
|
|
StartTime: time.Now(),
|
|
},
|
|
})
|
|
|
|
att := ð.Attestation{
|
|
Data: ð.AttestationData{
|
|
Slot: 0,
|
|
BeaconBlockRoot: root[:],
|
|
},
|
|
AggregationBits: bitfield.Bitlist{0b0101},
|
|
Signature: sKeys[0].Sign([]byte("foo"), 0).Marshal(),
|
|
}
|
|
|
|
p.ReceivePubSub("/eth2/committee_index0_beacon_attestation", att)
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
ua := r.attPool.UnaggregatedAttestations()
|
|
if len(ua) == 0 {
|
|
t.Error("No attestations put into pool")
|
|
}
|
|
}
|