Unit tests and refactor

Working on adding unit tests and getting a good test coverage.

On the way, I'm trying to unify some duplicate code especially related to launching btcd/btcwallet and connecting rpc client.
It actually doesn't.  If you're preempted between the select and the close, you can end up double closing the channel.  Same problem if you put the close under the default case.