1 package neutrino
2 3 import (
4 "testing"
5 6 "git.smesh.lol/nostrino/pkg/btcwire"
7 )
8 9 // TestAFilterRequestNeverExceedsTheNodeLimit: a node treats a getcfilters spanning a thousand
10 // blocks as misbehaviour and resets the connection. The failure shows up as a reset on the next
11 // write, which looks like a transport fault rather than a request that was too large.
12 func TestAFilterRequestNeverExceedsTheNodeLimit(t *testing.T) {
13 for _, max := range []int{0, 1, 2, 499, 500, 501, 1000, 1001, 2000, 100000} {
14 batch := filterBatchSize(max)
15 16 if batch < 1 {
17 t.Fatalf("max %d produced a batch of %d", max, batch)
18 }
19 20 if batch > btcwire.MaxCFiltersPerMsg {
21 t.Fatalf("max %d produced a batch of %d, the node allows %d filters per request",
22 max, batch, btcwire.MaxCFiltersPerMsg)
23 }
24 25 // The node's rule is on the difference between the stop and start heights.
26 if batch-1 >= btcwire.MaxCFiltersPerMsg {
27 t.Fatalf("a batch of %d spans %d blocks; the node closes the connection at %d",
28 batch, batch-1, btcwire.MaxCFiltersPerMsg)
29 }
30 31 if max > 0 && batch > max {
32 t.Fatalf("max %d produced a batch of %d", max, batch)
33 }
34 }
35 36 if btcwire.MaxCFiltersPerMsg != 1000 {
37 t.Fatalf("the node's limit is 1000, not %d", btcwire.MaxCFiltersPerMsg)
38 }
39 }
40