A goodness-of-fit test for stochastic block models