add a bunch of unit tests

- require testtools
- fix a couple of callback-related bugs found by the tests