package neutrino import "testing" // TestFilterRangeNeverGoesBackwards: a limit that is already met must end the loop, not produce a // request whose stop is below its start. A node treats that as a bad request and closes the // connection, which looks like a transport failure at the next write. func TestFilterRangeNeverGoesBackwards(t *testing.T) { const tip = 1000 cases := []struct { start, batch, max, count int ok bool end uint32 }{ {start: 0, batch: 500, max: 0, count: 0, ok: true, end: 499}, {start: 900, batch: 500, max: 0, count: 0, ok: true, end: tip}, {start: 0, batch: 500, max: 20, count: 0, ok: true, end: 19}, {start: 0, batch: 500, max: 20, count: 20, ok: false}, {start: 100, batch: 500, max: 10, count: 10, ok: false}, {start: 100, batch: 1, max: 0, count: 0, ok: true, end: 100}, } for _, c := range cases { end, ok := filterRange(uint32(c.start), tip, c.batch, c.max, c.count) if ok != c.ok || (ok && end != c.end) { t.Fatalf("start=%d batch=%d max=%d count=%d: got (%d,%v), want (%d,%v)", c.start, c.batch, c.max, c.count, end, ok, c.end, c.ok) } } }