Skip to content

Commit a5a62f9

Browse files
authored
fix: remove unutilized 'msg' from handleRequestNext() (#734)
Signed-off-by: Ales Verbic <[email protected]>
1 parent bcf8d62 commit a5a62f9

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

protocol/chainsync/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (s *Server) messageHandler(msg protocol.Message) error {
110110
var err error
111111
switch msg.Type() {
112112
case MessageTypeRequestNext:
113-
err = s.handleRequestNext(msg)
113+
err = s.handleRequestNext()
114114
case MessageTypeFindIntersect:
115115
err = s.handleFindIntersect(msg)
116116
case MessageTypeDone:
@@ -125,7 +125,7 @@ func (s *Server) messageHandler(msg protocol.Message) error {
125125
return err
126126
}
127127

128-
func (s *Server) handleRequestNext(msg protocol.Message) error {
128+
func (s *Server) handleRequestNext() error {
129129
if s.config == nil || s.config.RequestNextFunc == nil {
130130
return fmt.Errorf(
131131
"received chain-sync RequestNext message but no callback function is defined",

protocol/chainsync/server_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2024 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package chainsync
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
)
22+
23+
func TestHandleRequestNext_Callback(t *testing.T) {
24+
called := false
25+
server := &Server{
26+
config: &Config{
27+
RequestNextFunc: func(ctx CallbackContext) error {
28+
called = true
29+
return nil
30+
},
31+
},
32+
callbackContext: CallbackContext{},
33+
}
34+
35+
err := server.handleRequestNext()
36+
37+
assert.NoError(t, err, "expected no error")
38+
assert.True(t, called, "expected RequestNextFunc to be called")
39+
}
40+
41+
func TestHandleRequestNext_NilCallback(t *testing.T) {
42+
server := &Server{
43+
config: &Config{
44+
RequestNextFunc: nil,
45+
},
46+
callbackContext: CallbackContext{},
47+
}
48+
49+
err := server.handleRequestNext()
50+
expectedError := "received chain-sync RequestNext message but no callback function is defined"
51+
52+
assert.Error(t, err, "expected an error due to nil callback")
53+
assert.EqualError(t, err, expectedError)
54+
}

0 commit comments

Comments
 (0)