Skip to content

Commit

Permalink
chore: some quick deepsource fixes (#3602)
Browse files Browse the repository at this point in the history
- removed unused digest handler arg from `createCoreService`
- fixed the suspicious `b := &tt.verifier`
  • Loading branch information
kishansagathiya authored Nov 22, 2023
1 parent 26f1611 commit dd12623
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 53 deletions.
8 changes: 4 additions & 4 deletions dot/mock_node_builder_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type nodeBuilderIface interface {
createBlockVerifier(st *state.Service) *babe.VerificationManager
createDigestHandler(st *state.Service) (*digest.Handler, error)
createCoreService(config *cfg.Config, ks *keystore.GlobalKeystore, st *state.Service, net *network.Service,
dh *digest.Handler) (*core.Service, error)
) (*core.Service, error)
createGRANDPAService(config *cfg.Config, st *state.Service, ks KeyStore,
net *network.Service, telemetryMailer Telemetry) (*grandpa.Service, error)
newSyncService(config *cfg.Config, st *state.Service, finalityGadget BlockJustificationVerifier,
Expand Down Expand Up @@ -367,7 +367,7 @@ func newNode(config *cfg.Config,
}
nodeSrvcs = append(nodeSrvcs, dh)

coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc, dh)
coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc)
if err != nil {
return nil, fmt.Errorf("failed to create core service: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestNewNode(t *testing.T) {
m.EXPECT().createDigestHandler(gomock.AssignableToTypeOf(&state.Service{})).
Return(&digest.Handler{}, nil)
m.EXPECT().createCoreService(initConfig, ks, gomock.AssignableToTypeOf(&state.Service{}),
gomock.AssignableToTypeOf(&network.Service{}), &digest.Handler{}).
gomock.AssignableToTypeOf(&network.Service{})).
Return(&core.Service{}, nil)
m.EXPECT().createGRANDPAService(initConfig, gomock.AssignableToTypeOf(&state.Service{}),
ks.Gran, gomock.AssignableToTypeOf(&network.Service{}),
Expand Down
2 changes: 1 addition & 1 deletion dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (nodeBuilder) createBABEServiceWithBuilder(config *cfg.Config, st *state.Se

// createCoreService creates the core service from the provided core configuration
func (nodeBuilder) createCoreService(config *cfg.Config, ks *keystore.GlobalKeystore,
st *state.Service, net *network.Service, dh *digest.Handler) (
st *state.Service, net *network.Service) (
*core.Service, error) {
logger.Debug("creating core service" +
asAuthority(config.Core.Role == common.AuthorityRole) +
Expand Down
28 changes: 6 additions & 22 deletions dot/services_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
cfg "github.com/ChainSafe/gossamer/config"

core "github.com/ChainSafe/gossamer/dot/core"
digest "github.com/ChainSafe/gossamer/dot/digest"
"github.com/ChainSafe/gossamer/dot/network"
rpc "github.com/ChainSafe/gossamer/dot/rpc"
"github.com/ChainSafe/gossamer/dot/state"
Expand Down Expand Up @@ -135,7 +134,6 @@ func Test_nodeBuilder_createCoreService(t *testing.T) {
type args struct {
ks *keystore.GlobalKeystore
net *network.Service
dh *digest.Handler
}
tests := []struct {
name string
Expand Down Expand Up @@ -163,7 +161,7 @@ func Test_nodeBuilder_createCoreService(t *testing.T) {
stateSrvc := newStateService(t, ctrl)

builder := nodeBuilder{}
got, err := builder.createCoreService(config, tt.args.ks, stateSrvc, tt.args.net, tt.args.dh)
got, err := builder.createCoreService(config, tt.args.ks, stateSrvc, tt.args.net)

assert.ErrorIs(t, err, tt.err)

Expand Down Expand Up @@ -508,10 +506,8 @@ func TestCreateCoreService(t *testing.T) {
networkSrvc := &network.Service{}

builder := nodeBuilder{}
dh, err := builder.createDigestHandler(stateSrvc)
require.NoError(t, err)

coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc, dh)
coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc)
require.NoError(t, err)
require.NotNil(t, coreSrvc)
}
Expand Down Expand Up @@ -554,16 +550,13 @@ func TestCreateSyncService(t *testing.T) {

ver := builder.createBlockVerifier(stateSrvc)

dh, err := builder.createDigestHandler(stateSrvc)
require.NoError(t, err)

networkService, err := network.NewService(&network.Config{
BlockState: stateSrvc.Block,
BasePath: config.BasePath,
})
require.NoError(t, err)

coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkService, dh)
coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkService)
require.NoError(t, err)

_, err = builder.newSyncService(config, stateSrvc, &grandpa.Service{}, ver, coreSrvc, networkService, nil)
Expand Down Expand Up @@ -615,10 +608,7 @@ func TestCreateRPCService(t *testing.T) {
err = builder.loadRuntime(config, ns, stateSrvc, ks, networkSrvc)
require.NoError(t, err)

dh, err := builder.createDigestHandler(stateSrvc)
require.NoError(t, err)

coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc, dh)
coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc)
require.NoError(t, err)

systemInfo := &types.SystemInfo{
Expand Down Expand Up @@ -665,10 +655,7 @@ func TestCreateBABEService_Integration(t *testing.T) {
err = builder.loadRuntime(config, ns, stateSrvc, ks, &network.Service{})
require.NoError(t, err)

dh, err := builder.createDigestHandler(stateSrvc)
require.NoError(t, err)

coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, &network.Service{}, dh)
coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, &network.Service{})
require.NoError(t, err)

bs, err := builder.createBABEService(config, stateSrvc, ks.Babe, coreSrvc, nil)
Expand Down Expand Up @@ -774,10 +761,7 @@ func TestNewWebSocketServer(t *testing.T) {
err = builder.loadRuntime(config, ns, stateSrvc, ks, networkSrvc)
require.NoError(t, err)

dh, err := builder.createDigestHandler(stateSrvc)
require.NoError(t, err)

coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc, dh)
coreSrvc, err := builder.createCoreService(config, ks, stateSrvc, networkSrvc)
require.NoError(t, err)

systemInfo := &types.SystemInfo{
Expand Down
2 changes: 1 addition & 1 deletion dot/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestCreateJSONRawFile(t *testing.T) {
name: "working_example",
args: args{
bs: &BuildSpec{genesis: NewTestGenesis(t)},
fp: filepath.Join(t.TempDir(), "/test.json"),
fp: filepath.Join(t.TempDir(), "test.json"),
},
expectedHash: "f7f1b82c0ba16b20e36bfb462d7899af2c76728918f639f5c5ef0e91ff3e7077",
},
Expand Down
2 changes: 1 addition & 1 deletion internal/pprof/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Test_Server(t *testing.T) {
for _, pathToCheck := range pathsToCheck {
url := "http://" + serverAddress + "/" + pathToCheck

request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
require.NoError(t, err)

go func(client *http.Client, request *http.Request, results chan<- httpResult) {
Expand Down
35 changes: 14 additions & 21 deletions lib/babe/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ func Test_verifier_verifyPrimarySlotWinner(t *testing.T) {
}

mockSlotState := NewMockSlotState(nil)
v := newVerifier(mockBlockState, mockSlotState, 1, vi, time.Second)
v1 := newVerifier(mockBlockState, mockSlotState, 1, vi1, time.Second)

output, proof, err := kp.VrfSign(makeTranscript(Randomness{}, uint64(1), 1))
assert.NoError(t, err)
Expand All @@ -252,7 +250,7 @@ func Test_verifier_verifyPrimarySlotWinner(t *testing.T) {
}{
{
name: "Over threshold",
verifier: *v,
verifier: *newVerifier(mockBlockState, mockSlotState, 1, vi, time.Second),
args: args{
slot: 1,
vrfOutput: [32]byte{},
Expand All @@ -262,7 +260,7 @@ func Test_verifier_verifyPrimarySlotWinner(t *testing.T) {
},
{
name: "VRF not verified",
verifier: *v1,
verifier: *newVerifier(mockBlockState, mockSlotState, 1, vi1, time.Second),
args: args{
slot: 1,
vrfOutput: [32]byte{},
Expand All @@ -271,7 +269,7 @@ func Test_verifier_verifyPrimarySlotWinner(t *testing.T) {
},
{
name: "VRF verified",
verifier: *v1,
verifier: *newVerifier(mockBlockState, mockSlotState, 1, vi1, time.Second),
args: args{
slot: 1,
vrfOutput: output,
Expand All @@ -281,9 +279,10 @@ func Test_verifier_verifyPrimarySlotWinner(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
b := &tt.verifier
res, err := b.verifyPrimarySlotWinner(tt.args.authorityIndex, tt.args.slot, tt.args.vrfOutput, tt.args.vrfProof)
res, err := tt.verifier.verifyPrimarySlotWinner(tt.args.authorityIndex, tt.args.slot,
tt.args.vrfOutput, tt.args.vrfProof)
if tt.expErr != nil {
assert.EqualError(t, err, tt.expErr.Error())
} else {
Expand Down Expand Up @@ -363,9 +362,6 @@ func Test_verifier_verifyPreRuntimeDigest(t *testing.T) {
secondarySlots: true,
}

vVRFSec := newVerifier(mockBlockState, mockSlotState, 1, viVRFSec, testSlotDuration)
vVRFSec2 := newVerifier(mockBlockState, mockSlotState, 1, viVRFSec2, testSlotDuration)

//BabeSecondaryPlainPreDigest case
secDigest := types.BabeSecondaryPlainPreDigest{AuthorityIndex: 0, SlotNumber: uint64(1)}
prd, err := secDigest.ToPreRuntimeDigest()
Expand All @@ -383,9 +379,6 @@ func Test_verifier_verifyPreRuntimeDigest(t *testing.T) {
secondarySlots: true,
}

vSec := newVerifier(mockBlockState, mockSlotState, 1, viSec, testSlotDuration)
vSec2 := newVerifier(mockBlockState, mockSlotState, 1, viSec2, testSlotDuration)

type args struct {
digest *types.PreRuntimeDigest
}
Expand Down Expand Up @@ -433,33 +426,33 @@ func Test_verifier_verifyPreRuntimeDigest(t *testing.T) {
},
{
name: "BabeSecondaryPlainPreDigest SecondarySlot false",
verifier: *vSec,
verifier: *newVerifier(mockBlockState, mockSlotState, 1, viSec, testSlotDuration),
args: args{prd},
expErr: ErrBadSlotClaim,
},
{
name: "BabeSecondaryPlainPreDigest invalid claim",
verifier: *vSec2,
verifier: *newVerifier(mockBlockState, mockSlotState, 1, viSec2, testSlotDuration),
args: args{prd},
expErr: errors.New("invalid secondary slot claim"),
},
{
name: "BabeSecondaryVRFPreDigest SecondarySlot false",
verifier: *vVRFSec,
verifier: *newVerifier(mockBlockState, mockSlotState, 1, viVRFSec, testSlotDuration),
args: args{babePRD},
expErr: ErrBadSlotClaim,
},
{
name: "BabeSecondaryVRFPreDigest invalid claim",
verifier: *vVRFSec2,
verifier: *newVerifier(mockBlockState, mockSlotState, 1, viVRFSec2, testSlotDuration),
args: args{babePRD},
expErr: errors.New("invalid secondary slot claim"),
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
b := &tt.verifier
res, err := b.verifyPreRuntimeDigest(tt.args.digest)
res, err := tt.verifier.verifyPreRuntimeDigest(tt.args.digest)
if tt.expErr != nil {
assert.EqualError(t, err, tt.expErr.Error())
} else {
Expand Down Expand Up @@ -668,9 +661,9 @@ func Test_verifier_verifyAuthorshipRight(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
b := &tt.verifier
err := b.verifyAuthorshipRight(tt.header)
err := tt.verifier.verifyAuthorshipRight(tt.header)
if tt.expErr != nil {
assert.EqualError(t, err, tt.expErr.Error())
} else {
Expand Down

0 comments on commit dd12623

Please sign in to comment.