Fix two bugs in adapter.get_code
Add tests for get_code