mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
eth/txtracker: strengthen TestNotifyReceived assertions
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.
This commit is contained in:
parent
832f206275
commit
5014761cf1
1 changed files with 32 additions and 6 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue