From 5014761cf1160cec2baa7586d97da0910c8f7c79 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 13 Apr 2026 16:56:09 +0200 Subject: [PATCH] eth/txtracker: strengthen TestNotifyReceived assertions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original assertions read stats["peerA"].Finalized and .RecentIncluded, both of which return zero for a missing key — so the test would pass even if NotifyAccepted were a complete no-op, contradicting its stated purpose. Assert that exactly one peer entry exists, peerA is present, and the internal txs map and FIFO order slice are populated as NotifyAccepted is meant to do. --- eth/txtracker/tracker_test.go | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/eth/txtracker/tracker_test.go b/eth/txtracker/tracker_test.go index 9274e70d26..7b337a9c69 100644 --- a/eth/txtracker/tracker_test.go +++ b/eth/txtracker/tracker_test.go @@ -113,15 +113,41 @@ func TestNotifyReceived(t *testing.T) { defer tr.Stop() txs := []*types.Transaction{makeTx(1), makeTx(2), makeTx(3)} - tr.NotifyAccepted("peerA", hashTxs(txs)) + hashes := hashTxs(txs) + tr.NotifyAccepted("peerA", hashes) - // No chain events yet — peer entry exists but with zero stats. + // Public surface: peer entry was created with zero stats before any + // chain events. Map lookups would return a zero value for a missing + // key, so assert presence explicitly. stats := tr.GetAllPeerStats() - if stats["peerA"].Finalized != 0 { - t.Fatalf("expected zero Finalized before chain events, got %d", stats["peerA"].Finalized) + if len(stats) != 1 { + t.Fatalf("expected 1 peer entry, got %d", len(stats)) } - if stats["peerA"].RecentIncluded != 0 { - t.Fatalf("expected zero RecentIncluded before chain events, got %f", stats["peerA"].RecentIncluded) + ps, ok := stats["peerA"] + if !ok { + t.Fatal("expected peerA entry, not found") + } + if ps.Finalized != 0 || ps.RecentIncluded != 0 { + t.Fatalf("expected zero stats before chain events, got %+v", ps) + } + + // Internal state: all tx→deliverer mappings recorded, insertion order + // preserved in the FIFO slice. + tr.mu.Lock() + defer tr.mu.Unlock() + if len(tr.txs) != 3 { + t.Fatalf("expected 3 tracked txs, got %d", len(tr.txs)) + } + if len(tr.order) != 3 { + t.Fatalf("expected order length 3, got %d", len(tr.order)) + } + for i, h := range hashes { + if got := tr.txs[h]; got != "peerA" { + t.Fatalf("tx %d: expected deliverer=peerA, got %q", i, got) + } + if tr.order[i] != h { + t.Fatalf("order[%d] mismatch", i) + } } }