mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
d143187b7e
* include fixes * rev * logrus * tests for query sync status and chain head * begin tests for indexed atts * test passing for requesting historical atts * Update slasher/beaconclient/chain_data_test.go * Update slasher/beaconclient/historical_data_retrieval.go * lint * fixed up wanted vs receied * fix mock * gazelle * fix broken build * tests pass * dep * gaz * add dep * tests pass Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
91 lines
2.3 KiB
Go
91 lines
2.3 KiB
Go
package beaconclient
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/event"
|
|
"github.com/prysmaticlabs/prysm/shared/mock"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestService_SubscribeDetectedProposerSlashings(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
client := mock.NewMockBeaconChainClient(ctrl)
|
|
|
|
bs := Service{
|
|
beaconClient: client,
|
|
proposerSlashingsFeed: new(event.Feed),
|
|
}
|
|
|
|
slashing := ðpb.ProposerSlashing{
|
|
ProposerIndex: 5,
|
|
Header_1: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: 5,
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
Header_2: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: 5,
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
}
|
|
|
|
exitRoutine := make(chan bool)
|
|
slashingsChan := make(chan *ethpb.ProposerSlashing)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
client.EXPECT().SubmitProposerSlashing(gomock.Any(), slashing)
|
|
go func(tt *testing.T) {
|
|
bs.subscribeDetectedProposerSlashings(ctx, slashingsChan)
|
|
<-exitRoutine
|
|
}(t)
|
|
slashingsChan <- slashing
|
|
cancel()
|
|
exitRoutine <- true
|
|
testutil.AssertLogsContain(t, hook, "Context canceled")
|
|
}
|
|
|
|
func TestService_SubscribeDetectedAttesterSlashings(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
client := mock.NewMockBeaconChainClient(ctrl)
|
|
|
|
bs := Service{
|
|
beaconClient: client,
|
|
attesterSlashingsFeed: new(event.Feed),
|
|
}
|
|
|
|
slashing := ðpb.AttesterSlashing{
|
|
Attestation_1: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{1, 2, 3},
|
|
Data: nil,
|
|
},
|
|
Attestation_2: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{3, 4, 5},
|
|
Data: nil,
|
|
},
|
|
}
|
|
|
|
exitRoutine := make(chan bool)
|
|
slashingsChan := make(chan *ethpb.AttesterSlashing)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
client.EXPECT().SubmitAttesterSlashing(gomock.Any(), slashing)
|
|
go func(tt *testing.T) {
|
|
bs.subscribeDetectedAttesterSlashings(ctx, slashingsChan)
|
|
<-exitRoutine
|
|
}(t)
|
|
slashingsChan <- slashing
|
|
cancel()
|
|
exitRoutine <- true
|
|
testutil.AssertLogsContain(t, hook, "Context canceled")
|
|
}
|