Add test for get multiple received payments db method (#1700)

This commit is contained in:
Jonathan Zernik 2021-10-23 10:16:09 -05:00 committed by GitHub
parent 4c71be584a
commit 773b38de2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 0 deletions

View file

@ -29,6 +29,7 @@ from squeaknode.db.squeak_db import SqueakDb
from tests.utils import gen_address
from tests.utils import gen_contact_profile
from tests.utils import gen_random_hash
from tests.utils import gen_received_payment
from tests.utils import gen_sent_payment
from tests.utils import gen_signing_key
from tests.utils import gen_signing_profile
@ -362,6 +363,33 @@ def paid_sent_offer_id(squeak_db, inserted_sent_offer_id, payment_hash):
yield inserted_sent_offer_id
@pytest.fixture
def inserted_received_payment_id(squeak_db, received_payment):
yield squeak_db.insert_received_payment(received_payment)
@pytest.fixture
def inserted_received_payment_ids(
squeak_db,
peer_address,
squeak_hash,
secret_key,
price_msat,
):
ret = []
for i in range(100):
received_payment = gen_received_payment(
peer_address,
squeak_hash,
price_msat,
settle_index=i,
)
received_payment_id = squeak_db.insert_received_payment(
received_payment)
ret.append(received_payment_id)
yield ret
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:
@ -1402,3 +1430,24 @@ def test_get_sent_offer_not_paid(squeak_db, inserted_sent_offer_id, payment_hash
)
assert not retrieved_sent_offer.paid
def test_get_single_received_payment(squeak_db, inserted_received_payment_id, received_payment):
received_payments = squeak_db.get_received_payments(
limit=10,
last_received_payment=None,
)
assert received_payments[0]._replace(
received_payment_id=None,
created_time_ms=None,
) == received_payment
def test_get_received_payments(squeak_db, inserted_received_payment_ids):
received_payments = squeak_db.get_received_payments(
limit=1000,
last_received_payment=None,
)
assert len(received_payments) == len(inserted_received_payment_ids)

View file

@ -33,6 +33,7 @@ from squeaknode.core.peer_address import PeerAddress
from squeaknode.core.peers import create_saved_peer
from squeaknode.core.profiles import create_contact_profile
from squeaknode.core.profiles import create_signing_profile
from squeaknode.core.received_payment import ReceivedPayment
from squeaknode.core.sent_payment import SentPayment
from squeaknode.core.squeaks import HASH_LENGTH
from squeaknode.core.squeaks import make_squeak_with_block
@ -138,3 +139,16 @@ def gen_sent_payment(peer_address, squeak_hash, secret_key, price_msat, seller_p
node_pubkey=seller_pubkey,
valid=True,
)
def gen_received_payment(peer_address, squeak_hash, price_msat, settle_index):
payment_hash = gen_random_hash()
return ReceivedPayment(
received_payment_id=None,
created_time_ms=None,
squeak_hash=squeak_hash,
payment_hash=payment_hash,
price_msat=price_msat,
settle_index=settle_index,
peer_address=peer_address,
)