package neutrino import ( "testing" "git.smesh.lol/nostrino/pkg/btcwire" ) // TestAFilterRequestNeverExceedsTheNodeLimit: a node treats a getcfilters spanning a thousand // blocks as misbehaviour and resets the connection. The failure shows up as a reset on the next // write, which looks like a transport fault rather than a request that was too large. func TestAFilterRequestNeverExceedsTheNodeLimit(t *testing.T) { for _, max := range []int{0, 1, 2, 499, 500, 501, 1000, 1001, 2000, 100000} { batch := filterBatchSize(max) if batch < 1 { t.Fatalf("max %d produced a batch of %d", max, batch) } if batch > btcwire.MaxCFiltersPerMsg { t.Fatalf("max %d produced a batch of %d, the node allows %d filters per request", max, batch, btcwire.MaxCFiltersPerMsg) } // The node's rule is on the difference between the stop and start heights. if batch-1 >= btcwire.MaxCFiltersPerMsg { t.Fatalf("a batch of %d spans %d blocks; the node closes the connection at %d", batch, batch-1, btcwire.MaxCFiltersPerMsg) } if max > 0 && batch > max { t.Fatalf("max %d produced a batch of %d", max, batch) } } if btcwire.MaxCFiltersPerMsg != 1000 { t.Fatalf("the node's limit is 1000, not %d", btcwire.MaxCFiltersPerMsg) } }