fix bugs in hd_wallet and create tests