Ejemplo n.º 1
0
    async def test_transfer_wallet_enough(self):
        """
        Attempt XMR transfer in case wallet exists and enough XMR available.
        """
        w = self.new_wallet()
        succeed_backend()
        await w.create_wallet()

        mock_wallet = MockObject()
        mock_wallet.refresh = lambda *_: None
        mock_wallet.balance = lambda unlocked: 20.2

        mock_transaction = MockObject()
        mock_transaction.hash = TEST_HASH

        mock_wallet.transfer = lambda *_, **__: succeed(mock_transaction)

        w.wallet = mock_wallet

        result = await w.transfer(20.1, 'test_address',
                                  payment_id='test_id',
                                  priority=1,
                                  unlock_time=0)
        self.assertEqual(TEST_HASH, result.result())
        w.cancel_all_pending_tasks()
Ejemplo n.º 2
0
    async def test_transfer_multiple_wallet_not_enough(self):
        """
        Make multiple transfers at once, but not enough balance.
        """
        w = self.new_wallet()

        transfers = [
            (TEST_ADDRESS, Decimal('20.2')),
            (TEST_ADDRESS, Decimal('7.8'))
        ]

        mock_wallet = MockObject()
        mock_wallet.refresh = lambda: None
        mock_wallet.balance = lambda **_: 21.3
        w.wallet = mock_wallet

        self.assertAsyncRaises(InsufficientFunds, await w.transfer_multiple(transfers, priority=3))
        w.cancel_all_pending_tasks()
Ejemplo n.º 3
0
    async def test_get_balance_wallet(self):
        """
        Check balance in case wallet connection exists.
        """
        w = self.new_wallet()
        mock_wallet = MockObject()
        mock_wallet.refresh = lambda *_: None
        mock_wallet.balance = lambda unlocked: 20.2

        w.wallet = mock_wallet

        self.assertDictEqual({
            'available': 20.2,
            'pending': 0,
            'currency': self.identifier,
            'precision': 12
        }, await w.get_balance())
        w.cancel_all_pending_tasks()
Ejemplo n.º 4
0
    async def test_transfer_wallet_not_enough(self):
        """
        Attempt XMR transfer in case not enough XMR available.
        """
        w = self.new_wallet()
        succeed_backend()
        await w.create_wallet()

        mock_wallet = MockObject()
        mock_wallet.refresh = lambda *_: None
        mock_wallet.balance = lambda unlocked: 20.2

        w.wallet = mock_wallet

        self.assertAsyncRaises(InsufficientFunds, await w.transfer(47.8, 'test_address',
                                                                   payment_id='test_id',
                                                                   priority=1,
                                                                   unlock_time=0))
        w.cancel_all_pending_tasks()
Ejemplo n.º 5
0
    async def test_transfer_multiple_wallet(self):
        """
        Make multiple transfers at once, enough balance.
        """
        w = self.new_wallet()

        transfers = [
            (TEST_ADDRESS, Decimal('20.2')),
            (TEST_ADDRESS, Decimal('7.8'))
        ]

        mock_wallet = MockObject()
        mock_wallet.refresh = lambda: None
        mock_wallet.balance = lambda **_: 57.3
        mock_wallet.transfer_multiple = \
            lambda *_, **__: succeed([(Transaction(hash=TEST_HASH), Decimal('20.2')),
                                      (Transaction(hash=TEST_HASH), Decimal('7.8'))])

        w.wallet = mock_wallet

        hashes = await w.transfer_multiple(transfers, priority=3)
        self.assertEqual(2, len(hashes.result()))
        w.cancel_all_pending_tasks()