def test_tribler_wallet_constructor(self):
     r = walletcontroller.TriblerWallet()
     r.__init__()
     assert r.coin == 'BTC'
     o = walletcontroller.TriblerWallet(True)
     o.__init__(True)
     assert o.coin == 'TBTC'
Beispiel #2
0
def save_all_currency():
    """
    Sends leftover MB and (T)BTC to the predefined global wallet
    """
    wallet = wallet_controller.TriblerWallet(
        plebnet_settings.get_instance().wallets_testnet_created())
    wallet.pay(settings.wallets_btc_global(),
               satoshi_to_btc(wallet.get_balance()))
    def test_pay_error(self):
        self.balance = walletcontroller.TriblerWallet.get_balance
        walletcontroller.TriblerWallet.get_balance = MagicMock(return_value=50)

        r = walletcontroller.TriblerWallet()
        r.__init__()

        self.assertEquals(r.pay('address', 30), False)
        walletcontroller.TriblerWallet.get_balance = self.balance
    def test_get_balance2(self):
        self.market = marketcontroller.get_balance
        marketcontroller.get_balance = MagicMock(return_value=5)

        r = walletcontroller.TriblerWallet()
        r.__init__()

        self.assertEquals(r.get_balance(), 5)

        marketcontroller.get_balance = self.market
    def test_pay(self):
        self.true_balance = walletcontroller.TriblerWallet.get_balance
        walletcontroller.TriblerWallet.get_balance = MagicMock(
            return_value=300)

        r = walletcontroller.TriblerWallet()
        r.__init__()

        responses.add(responses.POST,
                      'http://localhost:8085/wallets/' + r.coin + '/transfer',
                      json={'txid': 'testID'})
        self.assertEquals(r.pay('address', 0.000003), 'testID')
        walletcontroller.TriblerWallet.get_balance = self.true_balance
Beispiel #6
0
    def test_pay_not_enough_balance(self):
        self.balance = walletcontroller.TriblerWallet.get_balance
        self.popen = subprocess.Popen.communicate
        walletcontroller.TriblerWallet.get_balance = MagicMock(return_value=0)
        subprocess.Popen.communicate = MagicMock()

        r = walletcontroller.TriblerWallet()
        r.pay('address', 30)
        walletcontroller.TriblerWallet.get_balance.assert_called_once()
        subprocess.Popen.communicate.assert_not_called()

        walletcontroller.TriblerWallet.get_balance = self.balance
        subprocess.Popen.communicate = self.popen
Beispiel #7
0
 def create_offer(self, amount_mb, timeout):
     """
     Retrieve the price of the chosen server to buy and make a new offer on the Tribler marketplace.
     :param amount_mb:
     :param timeout: offer to
     :return: None
     """
     if not self.config.get('chosen_provider'):
         return
     wallet = wallet_controller.TriblerWallet(plebnet_settings.get_instance().wallets_testnet_created())
     (provider, option, _) = self.config.get('chosen_provider')
     btc_balance = satoshi_to_btc(wallet.get_balance())
     btc_price = max(self.get_replication_price(provider, option) * self.target_vps_count - btc_balance, 0)
     self.place_offer(amount_mb, btc_price, timeout, self.config)
Beispiel #8
0
    def test_get_balance(self):
        self.popen = subprocess.Popen.communicate
        self.json = json.loads

        json.loads = MagicMock()
        subprocess.Popen.communicate = MagicMock()
        r = walletcontroller.TriblerWallet()

        r.get_balance()
        json.loads.assert_called_once()
        subprocess.Popen.communicate.assert_called_once()

        json.loads = self.json
        subprocess.Popen.communicate = self.popen
Beispiel #9
0
    def test_pay(self):
        self.balance = walletcontroller.TriblerWallet.get_balance
        self.popen = subprocess.Popen.communicate
        self.json = json.loads

        walletcontroller.TriblerWallet.get_balance = MagicMock(return_value=50)
        subprocess.Popen.communicate = MagicMock()
        json.loads = MagicMock(returun_value='test')

        r = walletcontroller.TriblerWallet()
        r.pay('address', 30)

        json.loads.assert_called_once()

        walletcontroller.TriblerWallet.get_balance = self.balance
        subprocess.Popen.communicate = self.popen
        json.loads = self.json
Beispiel #10
0
    def test_pay_no_response(self):
        self.balance = walletcontroller.TriblerWallet.get_balance
        self.popen = subprocess.Popen.communicate
        self.json = json.loads
        walletcontroller.TriblerWallet.get_balance = MagicMock(return_value=50)
        subprocess.Popen.communicate = MagicMock(
            return_value=self.MockResponse(False))
        json.loads = MagicMock()

        r = walletcontroller.TriblerWallet()
        r.pay('address', 30)

        walletcontroller.TriblerWallet.get_balance.assert_called_once()
        subprocess.Popen.communicate.assert_called_once()
        json.loads.assert_not_called()

        walletcontroller.TriblerWallet.get_balance = self.balance
        subprocess.Popen.communicate = self.popen
        json.loads = self.json
    def test_pay_transactions(self):
        self.true_balance = walletcontroller.TriblerWallet.get_balance
        walletcontroller.TriblerWallet.get_balance = MagicMock(
            return_value=300)

        r = walletcontroller.TriblerWallet(True)
        r.__init__(True)
        print(r.coin)

        responses.add(responses.POST,
                      'http://localhost:8085/wallets/' + r.coin + '/transfer',
                      json={'txid': None})
        responses.add(
            responses.GET,
            'http://localhost:8085/wallets/tbtc/transactions',
            json={"transactions": [{
                "id": "testID",
                "to": 'address'
            }]})

        self.assertEquals(r.pay('address', 0.000003), 'testID')
        walletcontroller.TriblerWallet.get_balance = self.true_balance