mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
9bf80219c9
* slasher/beaconclient tests * slasher/db/kv tests * Merge branch 'master' into apply-testutils-assertions-to-slasher * fix build * slasher/detection tests * rest of the tests * misc tests * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Update slasher/db/kv/spanner_test.go Co-authored-by: Shay Zluf <thezluf@gmail.com> * Update slasher/node/node_test.go Co-authored-by: Shay Zluf <thezluf@gmail.com> * Merge refs/heads/master into apply-testutils-assertions-to-slasher * Update slasher/db/kv/spanner_test.go * Merge refs/heads/master into apply-testutils-assertions-to-slasher
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package beaconclient
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/mock"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestService_ChainHead(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
client := mock.NewMockBeaconChainClient(ctrl)
|
|
|
|
bs := Service{
|
|
beaconClient: client,
|
|
}
|
|
wanted := ðpb.ChainHead{
|
|
HeadSlot: 4,
|
|
HeadEpoch: 0,
|
|
HeadBlockRoot: make([]byte, 32),
|
|
}
|
|
client.EXPECT().GetChainHead(gomock.Any(), gomock.Any()).Return(wanted, nil)
|
|
res, err := bs.ChainHead(context.Background())
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, wanted, res)
|
|
}
|
|
|
|
func TestService_GenesisValidatorsRoot(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
client := mock.NewMockNodeClient(ctrl)
|
|
bs := Service{
|
|
nodeClient: client,
|
|
}
|
|
wanted := ðpb.Genesis{
|
|
GenesisValidatorsRoot: []byte("I am genesis"),
|
|
}
|
|
client.EXPECT().GetGenesis(gomock.Any(), gomock.Any()).Return(wanted, nil)
|
|
res, err := bs.GenesisValidatorsRoot(context.Background())
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, wanted.GenesisValidatorsRoot, res, "Wanted %#x, received %#x", wanted.GenesisValidatorsRoot, res)
|
|
// test next fetch uses memory and not the rpc call.
|
|
res, err = bs.GenesisValidatorsRoot(context.Background())
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, wanted.GenesisValidatorsRoot, res, "Wanted %#x, received %#x", wanted.GenesisValidatorsRoot, res)
|
|
}
|
|
|
|
func TestService_QuerySyncStatus(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
client := mock.NewMockNodeClient(ctrl)
|
|
|
|
bs := Service{
|
|
nodeClient: client,
|
|
}
|
|
syncStatusPollingInterval = time.Millisecond
|
|
client.EXPECT().GetSyncStatus(gomock.Any(), gomock.Any()).Return(ðpb.SyncStatus{
|
|
Syncing: true,
|
|
}, nil)
|
|
client.EXPECT().GetSyncStatus(gomock.Any(), gomock.Any()).Return(ðpb.SyncStatus{
|
|
Syncing: false,
|
|
}, nil)
|
|
bs.querySyncStatus(context.Background())
|
|
require.LogsContain(t, hook, "Waiting for beacon node to be fully synced...")
|
|
require.LogsContain(t, hook, "Beacon node is fully synced")
|
|
}
|