peer: add mock BestBlockView to test peer config
What changed, and why it matters
This commit fixes a flaky test in LND's peer package. The test helper that creates a fake peer was missing a mock object for BestBlockView. When a background ping timer fired during tests, it tried to call a method on the nil mock, causing random test panics. The change adds a trivial mock that returns empty values and wires it into the test config. There is no production code change and no security relevance.
No security action needed. Treat as normal test-quality improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies peer/test_utils.go only. It adds mockBestBlockView implementing chainntnfs.BestBlockView with BestHeight() and BestBlockHeader() returning zero/empty values, and assigns &mockBestBlockView{} to Config.BestBlockView in createTestPeer. This prevents nil-pointer panics when PingManager’s timer invokes BestBlockHeader during unit tests. It is a test-only reliability fix with no effect on runtime behavior or attack surface.
Changed components
peer/test_utils.gocreateTestPeer test helperInspect captured patch +16 / −1
diff --git a/peer/test_utils.go b/peer/test_utils.go
index a1061e3..670af09 100644
--- a/peer/test_utils.go
+++ b/peer/test_utils.go
@@ -559,6 +559,20 @@ func (m *mockMessageConn) Close() error {
return nil
}
+// mockBestBlockView is a mock implementation of chainntnfs.BestBlockView for
+// testing.
+type mockBestBlockView struct{}
+
+// BestHeight returns a dummy block height.
+func (m *mockBestBlockView) BestHeight() (uint32, error) {
+ return 0, nil
+}
+
+// BestBlockHeader returns a dummy block header.
+func (m *mockBestBlockView) BestBlockHeader() (*wire.BlockHeader, error) {
+ return &wire.BlockHeader{}, nil
+}
+
// createTestPeer creates a new peer for testing and returns a context struct
// containing necessary handles and mock objects for conducting tests on peer
// functionalities.
@@ -739,7 +753,8 @@ func createTestPeer(t *testing.T) *peerTestCtx {
return nil
},
- PongBuf: make([]byte, lnwire.MaxPongBytes),
+ PongBuf: make([]byte, lnwire.MaxPongBytes),
+ BestBlockView: &mockBestBlockView{},
FetchLastChanUpdate: func(chanID lnwire.ShortChannelID,
) (*lnwire.ChannelUpdate1, error) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.