Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Feb 23, 2024
1 parent 1108205 commit 3edce6a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
19 changes: 19 additions & 0 deletions api/grpcserver/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,25 @@ func TestSmesherService(t *testing.T) {
require.Equal(t, int32(code.Code_OK), res.Status.Code)
})

t.Run("StartSmeshingMultiSetup", func(t *testing.T) {
t.Parallel()
opts := &pb.PostSetupOpts{}
opts.DataDir = t.TempDir()
opts.NumUnits = 1
opts.MaxFileSize = 1024

coinbase := &pb.AccountId{Address: addr1.String()}

c, ctx := setupSmesherService(t, nil) // in multi smeshing setup the node id is nil and start smeshing should fail
res, err := c.StartSmeshing(ctx, &pb.StartSmeshingRequest{
Opts: opts,
Coinbase: coinbase,
})
require.Equal(t, codes.FailedPrecondition, status.Code(err))
require.ErrorContains(t, err, "node is not configured for supervised smeshing")
require.Nil(t, res)
})

t.Run("StopSmeshing", func(t *testing.T) {
t.Parallel()
c, ctx := setupSmesherService(t, nil)
Expand Down
40 changes: 39 additions & 1 deletion api/grpcserver/smesher_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestStartSmeshingPassesCorrectSmeshingOpts(t *testing.T) {
ctrl := gomock.NewController(t)
smeshingProvider := activation.NewMockSmeshingProvider(ctrl)
postSupervisor := grpcserver.NewMockpostSupervisor(ctrl)
nodeID := types.RandomNodeID() // TODO (mafa): add test where nodeID is not available
nodeID := types.RandomNodeID()
svc := grpcserver.NewSmesherService(
smeshingProvider,
postSupervisor,
Expand Down Expand Up @@ -92,6 +92,44 @@ func TestStartSmeshingPassesCorrectSmeshingOpts(t *testing.T) {
require.NoError(t, err)
}

func TestStartSmeshingFailsMultiSmeshing(t *testing.T) {
ctrl := gomock.NewController(t)
smeshingProvider := activation.NewMockSmeshingProvider(ctrl)
postSupervisor := grpcserver.NewMockpostSupervisor(ctrl)
svc := grpcserver.NewSmesherService(
smeshingProvider,
postSupervisor,
time.Second,
nil, // no nodeID in multi smesher setup
activation.DefaultPostSetupOpts(),
)

types.SetNetworkHRP("stest")
providerID := uint32(7)
opts := activation.PostSetupOpts{
DataDir: "data-dir",
NumUnits: 1,
MaxFileSize: 1024,
Throttle: true,
Scrypt: config.DefaultLabelParams(),
ComputeBatchSize: config.DefaultComputeBatchSize,
}
opts.ProviderID.SetUint32(providerID)

_, err := svc.StartSmeshing(context.Background(), &pb.StartSmeshingRequest{
Coinbase: &pb.AccountId{Address: "stest1qqqqqqrs60l66w5uksxzmaznwq6xnhqfv56c28qlkm4a5"},
Opts: &pb.PostSetupOpts{
DataDir: "data-dir",
NumUnits: 1,
MaxFileSize: 1024,
ProviderId: &providerID,
Throttle: true,
},
})
require.Equal(t, codes.FailedPrecondition, status.Code(err))
require.ErrorContains(t, err, "node is not configured for supervised smeshing")
}

func TestSmesherService_PostSetupProviders(t *testing.T) {
ctrl := gomock.NewController(t)
smeshingProvider := activation.NewMockSmeshingProvider(ctrl)
Expand Down

0 comments on commit 3edce6a

Please sign in to comment.