mirror of
https://github.com/Such-Software/xmrcheckout.git
synced 2026-12-01 12:14:11 +01:00
The reconciler took the deepest single payment's confirmations as the invoice's. A tiny early payment could therefore make an unconfirmed top-up count as confirmed, and InvoiceSettled fired before the money was final. The invoice depth is now the depth at which payments, taken deepest first, cover the whole amount. It is 0 while the invoice is underpaid.
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import unittest
|
|
from dataclasses import dataclass
|
|
|
|
from app.payment_confirmations import effective_confirmations
|
|
|
|
|
|
@dataclass
|
|
class _Payment:
|
|
amount_atomic: int
|
|
confirmations: int
|
|
|
|
|
|
class EffectiveConfirmationTests(unittest.TestCase):
|
|
def test_a_deep_small_payment_does_not_confirm_an_unconfirmed_top_up(self):
|
|
payments = [_Payment(1, 30), _Payment(999, 0)]
|
|
self.assertEqual(effective_confirmations(payments, 1000), 0)
|
|
|
|
def test_depth_is_that_of_the_shallowest_payment_needed(self):
|
|
payments = [_Payment(400, 12), _Payment(600, 3)]
|
|
self.assertEqual(effective_confirmations(payments, 1000), 3)
|
|
|
|
def test_an_extra_unconfirmed_payment_does_not_lower_a_covered_invoice(self):
|
|
payments = [_Payment(1000, 10), _Payment(5, 0)]
|
|
self.assertEqual(effective_confirmations(payments, 1000), 10)
|
|
|
|
def test_an_underpaid_invoice_has_no_depth(self):
|
|
self.assertEqual(effective_confirmations([_Payment(500, 50)], 1000), 0)
|
|
|
|
def test_non_positive_amounts_are_ignored(self):
|
|
payments = [_Payment(-5, 40), _Payment(0, 40), _Payment(1000, 2)]
|
|
self.assertEqual(effective_confirmations(payments, 1000), 2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|