Add a test for block allocation and fix a bug it exposed.