'Test the creating, opening, transactions and balance query of a Bitcoin wallet'

@deferred(timeout=20)
def test_btc_wallet(self):

    wallet = BitcoinWallet(self.session_base_dir, testnet=True)
    def on_wallet_transactions(transactions):
        self.assertFalse(transactions)
        wallet.get_transactions = (lambda : succeed([{'id': 'abc'}]))
        return wallet.monitor_transaction('abc')
    def on_wallet_balance(balance):
        self.assertDictEqual(balance, {'available': 0, 'pending': 0, 'currency': 'BTC'})
        return wallet.get_transactions().addCallback(on_wallet_transactions)
    def on_wallet_created(_):
        self.assertIsNotNone(wallet.wallet)
        self.assertTrue(wallet.get_address())
        _ = BitcoinWallet(self.session_base_dir, testnet=True)
        wallet.set_wallet_password('abc')
        self.assertRaises(Exception, BitcoinWallet, self.session_base_dir, testnet=True)
        return wallet.get_balance().addCallback(on_wallet_balance)
    return wallet.create_wallet('tribler').addCallback(on_wallet_created)
