Add test for set received offer paid db method (#1678)

This commit is contained in:
Jonathan Zernik 2021-10-22 19:16:37 -05:00 committed by GitHub
parent e320c9b497
commit 3fc34c8965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 3 deletions

View file

@ -40,3 +40,4 @@ class ReceivedOffer(NamedTuple):
destination: str
lightning_address: LightningAddressHostPort
peer_address: PeerAddress
paid: bool

View file

@ -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:

View file

@ -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:

View file

@ -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(

View file

@ -397,6 +397,7 @@ def received_offer(
destination=seller_pubkey,
lightning_address=lightning_address,
peer_address=peer_address,
paid=False,
)

View file

@ -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