mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-20 13:28:20 +02:00
Add test for set received offer paid db method (#1678)
This commit is contained in:
parent
e320c9b497
commit
3fc34c8965
6 changed files with 29 additions and 3 deletions
|
|
@ -40,3 +40,4 @@ class ReceivedOffer(NamedTuple):
|
|||
destination: str
|
||||
lightning_address: LightningAddressHostPort
|
||||
peer_address: PeerAddress
|
||||
paid: bool
|
||||
|
|
|
|||
|
|
@ -287,6 +287,7 @@ class SqueakCore:
|
|||
destination=destination,
|
||||
lightning_address=lightning_address,
|
||||
peer_address=peer_address,
|
||||
paid=False,
|
||||
)
|
||||
|
||||
def pay_offer(self, received_offer: ReceivedOffer) -> SentPayment:
|
||||
|
|
|
|||
|
|
@ -1086,11 +1086,11 @@ class SqueakDb:
|
|||
# with self.get_connection() as connection:
|
||||
# connection.execute(s)
|
||||
|
||||
def set_received_offer_paid(self, payment_hash: bytes, paid: bool) -> None:
|
||||
def set_received_offer_paid(self, received_offer_id: int, paid: bool) -> None:
|
||||
""" Set a received offer is paid. """
|
||||
stmt = (
|
||||
self.received_offers.update()
|
||||
.where(self.received_offers.c.payment_hash == payment_hash)
|
||||
.where(self.received_offers.c.received_offer_id == received_offer_id)
|
||||
.values(paid=paid)
|
||||
)
|
||||
with self.get_connection() as connection:
|
||||
|
|
@ -1472,6 +1472,7 @@ class SqueakDb:
|
|||
host=row["peer_host"],
|
||||
port=row["peer_port"],
|
||||
),
|
||||
paid=row["paid"],
|
||||
)
|
||||
|
||||
def _parse_sent_payment(self, row) -> SentPayment:
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ class SqueakController:
|
|||
# self.squeak_db.delete_offer(sent_payment.payment_hash)
|
||||
# Mark the received offer as paid
|
||||
self.squeak_db.set_received_offer_paid(
|
||||
sent_payment.payment_hash,
|
||||
received_offer_id,
|
||||
paid=True,
|
||||
)
|
||||
self.unlock_squeak(
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ def received_offer(
|
|||
destination=seller_pubkey,
|
||||
lightning_address=lightning_address,
|
||||
peer_address=peer_address,
|
||||
paid=False,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -316,6 +316,12 @@ def duplicate_inserted_received_offer_id(squeak_db, inserted_received_offer_id,
|
|||
yield squeak_db.insert_received_offer(received_offer)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def paid_received_offer_id(squeak_db, inserted_received_offer_id):
|
||||
squeak_db.set_received_offer_paid(inserted_received_offer_id, True)
|
||||
yield inserted_received_offer_id
|
||||
|
||||
|
||||
def test_init_with_retries(squeak_db):
|
||||
with mock.patch.object(squeak_db, 'init', autospec=True) as mock_init, \
|
||||
mock.patch('squeaknode.db.squeak_db.time.sleep', autospec=True) as mock_sleep:
|
||||
|
|
@ -1166,3 +1172,19 @@ def test_delete_expired_received_offers_none(squeak_db, inserted_received_offer_
|
|||
num_deleted = squeak_db.delete_expired_received_offers()
|
||||
|
||||
assert num_deleted == 0
|
||||
|
||||
|
||||
def test_get_received_offer_paid(squeak_db, paid_received_offer_id):
|
||||
retrieved_received_offer = squeak_db.get_received_offer(
|
||||
paid_received_offer_id,
|
||||
)
|
||||
|
||||
assert retrieved_received_offer.paid
|
||||
|
||||
|
||||
def test_get_received_offer_not_paid(squeak_db, inserted_received_offer_id):
|
||||
retrieved_received_offer = squeak_db.get_received_offer(
|
||||
inserted_received_offer_id,
|
||||
)
|
||||
|
||||
assert not retrieved_received_offer.paid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue