Ejemplo n.º 1
0
    def test_process_withdraw_transactions(self):
        self.wallet.withdraw_to_address('mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB',
                                        Decimal('0.1'))
        self.wallet.withdraw_to_address('mkYAsS9QLYo5mXVjuvxKkZUhQJxiMLX5Xk',
                                        Decimal('0.1'))
        self.wallet.withdraw_to_address('mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB',
                                        Decimal('0.1'))
        self.wallet.withdraw_to_address('mvfNqn5AoVWrsJGuKrdPuoQhYs71CR9uFA',
                                        Decimal('0.1'))

        with patch('cc.tasks.AuthServiceProxy', self.mock):
            tasks.process_withdraw_transactions(ticker=self.currency.ticker)

        self.mock.gettransaction.assert_called_once_with(self.txid)
        self.mock.sendmany.assert_called_once_with(
            '', {
                'mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB': Decimal('0.2'),
                'mkYAsS9QLYo5mXVjuvxKkZUhQJxiMLX5Xk': Decimal('0.1'),
                'mvfNqn5AoVWrsJGuKrdPuoQhYs71CR9uFA': Decimal('0.1')
            })

        wallet = Wallet.objects.get(id=self.wallet.id)
        self.assertEqual(wallet.holded, Decimal('0'))
        self.assertEqual(wallet.balance, Decimal('0.5999'))

        fee_operation = Operation.objects.get(wallet=wallet,
                                              description='Network fee')
        self.assertEqual(fee_operation.balance, Decimal('-0.0001'))
        self.assertEqual(fee_operation.holded, Decimal('-0.4'))
Ejemplo n.º 2
0
    def test_withdraw_error(self):
        wallet_before = Wallet.objects.create(currency=self.currency, balance=Decimal('21000000'))
        wallet_before.withdraw_to_address('mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB', Decimal('21000000'))

        try:
            tasks.process_withdraw_transactions('tbtc')
        except JSONRPCException:
            pass

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0'))
        self.assertEqual(wallet_after1.holded, Decimal('21000000'))

        wtx = WithdrawTransaction.objects.last()

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wtx.state, wtx.ERROR)
Ejemplo n.º 3
0
    def test_withdraw(self):
        wallet_before = Wallet.objects.create(currency=self.currency, balance=Decimal('1.0'))
        wallet_before.withdraw_to_address('mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB', Decimal('0.1'))
        wallet_before.withdraw_to_address('mkYAsS9QLYo5mXVjuvxKkZUhQJxiMLX5Xk', Decimal('0.1'))
        wallet_before.withdraw_to_address('mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB', Decimal('0.1'))

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0.7'))
        self.assertEqual(wallet_after1.holded, Decimal('0.3'))
        tasks.process_withdraw_transactions('tbtc')
        self.coin.generate(2)

        wtx = WithdrawTransaction.objects.last()
        tx = self.coin.gettransaction(wtx.txid)

        wallet_after2 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after2.balance, Decimal('0.7') + tx['fee'])
        self.assertEqual(wallet_after2.holded, Decimal('0'))
Ejemplo n.º 4
0
    def test_withdraw_error(self):
        wallet_before = Wallet.objects.create(currency=self.currency,
                                              balance=Decimal('21000000'))
        wallet_before.withdraw_to_address('QfMAfiiLioTdkWmSG9v6VjDot9LH1d1nJo',
                                          Decimal('21000000'))

        try:
            tasks.process_withdraw_transactions('tbtc')
        except JSONRPCException:
            pass

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0'))
        self.assertEqual(wallet_after1.holded, Decimal('21000000'))

        wtx = WithdrawTransaction.objects.last()

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wtx.state, wtx.ERROR)
Ejemplo n.º 5
0
    def test_withdraw_error(self):
        wallet_before = Wallet.objects.create(currency=self.currency,
                                              balance=Decimal('21000000'))
        wallet_before.withdraw_to_address(
            'tmGa4dwQrtw6ctnijug586PwXt9h8JExguc', Decimal('21000000'))

        try:
            tasks.process_withdraw_transactions('tzec')
        except JSONRPCException:
            pass

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0'))
        self.assertEqual(wallet_after1.holded, Decimal('21000000'))

        wtx = WithdrawTransaction.objects.last()

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wtx.state, wtx.ERROR)
Ejemplo n.º 6
0
    def test_withdraw_error(self):
        wallet_before = Wallet.objects.create(currency=self.currency,
                                              balance=Decimal('21000000'))
        wallet_before.withdraw_to_address('yT58gFY67LNSb1wG9TYsvMx4W4wt93cej9',
                                          Decimal('21000000'))

        try:
            tasks.process_withdraw_transactions('tdsh')
        except JSONRPCException:
            pass

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0'))
        self.assertEqual(wallet_after1.holded, Decimal('21000000'))

        wtx = WithdrawTransaction.objects.last()

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wtx.state, wtx.ERROR)
Ejemplo n.º 7
0
    def test_process_withdraw_transactions(self):
        self.wallet.withdraw_to_address('mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB',
                                        Decimal('1'))
        self.wallet.withdraw_to_address('mvfNqn5AoVWrsJGuKrdPuoQhYs71CR9uFA',
                                        Decimal('0.00000001'))

        with patch('cc.tasks.AuthServiceProxy', self.mock):
            tasks.process_withdraw_transactions(ticker=self.currency.ticker)

        self.mock.sendmany.assert_called_once_with(
            '', {'mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB': Decimal('1')})

        wallet = Wallet.objects.get(id=self.wallet.id)
        self.assertEqual(wallet.balance, Decimal('0.99989999'))

        wt1 = WithdrawTransaction.objects.get(
            address='mvEnyQ9b9iTA11QMHAwSVtHUrtD4CTfiDB')
        wt2 = WithdrawTransaction.objects.get(
            address='mvfNqn5AoVWrsJGuKrdPuoQhYs71CR9uFA')
        self.assertEqual(wt1.txid, self.txid)
        self.assertIsNone(wt2.txid)
Ejemplo n.º 8
0
    def test_withdraw(self):
        wallet_before = Wallet.objects.create(currency=self.currency,
                                              balance=Decimal('1.0'))
        wallet_before.withdraw_to_address('QfMAfiiLioTdkWmSG9v6VjDot9LH1d1nJo',
                                          Decimal('0.1'))
        wallet_before.withdraw_to_address('QfiFeWcRV5txjDXS5wzzj1t8dD2hRXR78t',
                                          Decimal('0.1'))
        wallet_before.withdraw_to_address('QfMAfiiLioTdkWmSG9v6VjDot9LH1d1nJo',
                                          Decimal('0.1'))

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0.7'))
        self.assertEqual(wallet_after1.holded, Decimal('0.3'))
        tasks.process_withdraw_transactions('tbtc')
        self.coin.generate(2)

        wtx = WithdrawTransaction.objects.last()
        tx = self.coin.gettransaction(wtx.txid)

        wallet_after2 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after2.balance, Decimal('0.7') + tx['fee'])
        self.assertEqual(wallet_after2.holded, Decimal('0'))
Ejemplo n.º 9
0
    def test_withdraw(self):
        wallet_before = Wallet.objects.create(currency=self.currency,
                                              balance=Decimal('1.0'))
        wallet_before.withdraw_to_address(
            'tmGa4dwQrtw6ctnijug586PwXt9h8JExguc', Decimal('0.1'))
        wallet_before.withdraw_to_address(
            'tmEHsxHvPS5inmcDYPDocFPmynGCz5PLYf3', Decimal('0.1'))
        wallet_before.withdraw_to_address(
            'tmGa4dwQrtw6ctnijug586PwXt9h8JExguc', Decimal('0.1'))

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0.7'))
        self.assertEqual(wallet_after1.holded, Decimal('0.3'))
        tasks.process_withdraw_transactions('tzec')
        self.coin.generate(2)

        wtx = WithdrawTransaction.objects.last()
        tx = self.coin.gettransaction(wtx.txid)

        wallet_after2 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after2.balance, Decimal('0.7') + tx['fee'])
        self.assertEqual(wallet_after2.holded, Decimal('0'))
Ejemplo n.º 10
0
    def test_withdraw(self):
        wallet_before = Wallet.objects.create(currency=self.currency,
                                              balance=Decimal('1.0'))
        wallet_before.withdraw_to_address('yT58gFY67LNSb1wG9TYsvMx4W4wt93cej9',
                                          Decimal('0.1'))
        wallet_before.withdraw_to_address('ye4AYzjG8DuWzk1YTKG3cCUTumwC4Z2JQD',
                                          Decimal('0.1'))
        wallet_before.withdraw_to_address('yT58gFY67LNSb1wG9TYsvMx4W4wt93cej9',
                                          Decimal('0.1'))

        wallet_after1 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after1.balance, Decimal('0.7'))
        self.assertEqual(wallet_after1.holded, Decimal('0.3'))
        tasks.process_withdraw_transactions('tdsh')
        self.coin.generate(2)

        wtx = WithdrawTransaction.objects.last()
        tx = self.coin.gettransaction(wtx.txid)

        wallet_after2 = Wallet.objects.get(id=wallet_before.id)
        self.assertEqual(wallet_after2.balance, Decimal('0.7') + tx['fee'])
        self.assertEqual(wallet_after2.holded, Decimal('0'))