Esempio n. 1
0
    def test_wrongvalue(self, mock_sendtoaddress, mock_sleep):
        # balance in Miner table is higher then the real balance
        send_autopayments("test")

        miner1 = Miner.objects.get(pk=self.miner1.id)
        self.assertEqual(miner1.balance, 4)

        self.assertEqual(Transaction.objects.filter(category='TX').count(), 0)
Esempio n. 2
0
    def test_outdated_value(self, mock_sendtoaddress, mock_sleep):
        # balance is high enough, but not right

        Transaction(miner=self.miner1, amount=10, network="test").save()

        send_autopayments("test")

        miner1 = Miner.objects.get(pk=self.miner1.id)
        self.assertEqual(miner1.balance, 0)

        self.assertEqual(Transaction.objects.filter(category='TX').count(), 1)

        tx = Transaction.objects.get(category='TX')
        self.assertEqual(tx.amount, -14)
        self.assertEqual(tx.miner.id, miner1.id)
        self.assertEqual(tx.network, "test")
Esempio n. 3
0
    def test_process_failed(self, mock_sendtoaddress):
        mock_sendtoaddress.side_effect = Exception()

        # a successfull run

        Transaction(miner=self.miner1, amount=30, network="test").save()

        self.miner1.update_balance()
        self.miner1.save()

        Transaction(miner=self.miner1, amount=10, network="test").save()

        send_autopayments("test")

        miner1 = Miner.objects.get(pk=self.miner1.id)
        self.assertEqual(miner1.balance, 34)  # transaction wasn't done

        self.assertEqual(Transaction.objects.filter(category='TX').count(), 0)

        self.assertEqual(TransactionError.objects.all().count(), 1)
Esempio n. 4
0
    def test_process(self, mock_sendtoaddress, mock_sleep):
        # a successfull run

        Transaction(miner=self.miner1, amount=30, network="test").save()

        self.miner1.update_balance()
        self.miner1.save()

        Transaction(miner=self.miner1, amount=10, network="test").save()

        send_autopayments("test")

        miner1 = Miner.objects.get(pk=self.miner1.id)
        self.assertEqual(miner1.balance, 0)

        self.assertEqual(Transaction.objects.filter(category='TX').count(), 1)

        tx = Transaction.objects.get(category='TX')
        self.assertEqual(tx.amount, -44)
        self.assertEqual(tx.miner.id, miner1.id)
        self.assertEqual(tx.network, "test")

        # even with a new balance, should not pay again, as we do not pay so early again
        Transaction(miner=self.miner1, amount=16, network="test").save()

        self.miner1.update_balance()
        self.miner1.save()

        send_autopayments("test")

        miner1 = Miner.objects.get(pk=self.miner1.id)
        self.assertEqual(miner1.balance, 16)

        self.assertEqual(Transaction.objects.filter(category='TX').count(), 1)

        tx = Transaction.objects.get(category='TX')
        self.assertEqual(tx.amount, -44)
        self.assertEqual(tx.miner.id, miner1.id)
        self.assertEqual(tx.network, "test")

        # but if first_trans is older, then the second one should be paid
        tx.inserted_at = timezone.now() - datetime.timedelta(hours=18)
        tx.save()

        send_autopayments("test")

        miner1 = Miner.objects.get(pk=self.miner1.id)
        self.assertEqual(miner1.balance, 0)

        self.assertEqual(Transaction.objects.filter(category='TX').count(), 2)

        tx = Transaction.objects.filter(category='TX').order_by('-id')[0]
        self.assertEqual(tx.amount, -16)
        self.assertEqual(tx.miner.id, miner1.id)
        self.assertEqual(tx.network, "test")
Esempio n. 5
0
    def test_error_on_send(self, mock_sendtoaddress):
        mock_sendtoaddress.side_effect = Exception()

        Transaction(miner=self.miner1, amount=10, network="test").save()

        send_autopayments("test")