unit test for chain closing contexts

closes #812 (and #810)