From efdcbdeaef8b043e6625d0aff5c3affd8dfce835 Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Tue, 12 Oct 2021 21:17:21 -0700 Subject: [PATCH] Add test for check payment point with success (#1591) --- tests/core/test_squeak_core.py | 51 ++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/core/test_squeak_core.py b/tests/core/test_squeak_core.py index 2b1e19e9..c3568d24 100644 --- a/tests/core/test_squeak_core.py +++ b/tests/core/test_squeak_core.py @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import pytest +from squeak.core.elliptic import payment_point_bytes_from_scalar_bytes from squeaknode.bitcoin.bitcoin_client import BitcoinClient from squeaknode.bitcoin.block_info import BlockInfo @@ -60,6 +61,11 @@ def preimage(secret_key, nonce): yield add_tweak(secret_key, nonce) +@pytest.fixture +def payment_point(secret_key): + yield payment_point_bytes_from_scalar_bytes(secret_key) + + @pytest.fixture def payment_hash(preimage): # TODO: When PTLC is used, this should be the payment point of preimage. @@ -128,6 +134,26 @@ def invoice(payment_request, price_msat, creation_date, expiry): @pytest.fixture def pay_req( + payment_hash, + payment_point, + price_msat, + payment_request, + seller_pubkey, + timestamp, + expiry, +): + yield PayReq( + payment_hash=payment_hash, + payment_point=payment_point, + num_msat=price_msat, + destination=seller_pubkey, + timestamp=timestamp, + expiry=expiry, + ) + + +@pytest.fixture +def pay_req_with_no_payment_point( payment_hash, price_msat, payment_request, @@ -243,6 +269,11 @@ def lightning_client_with_no_uris(info_with_no_uris, invoice, pay_req, failed_pa return MockLightningClient(info_with_no_uris, invoice, pay_req, failed_payment) +@pytest.fixture +def lightning_client_with_no_payment_point(info, invoice, pay_req_with_no_payment_point, successful_payment): + return MockLightningClient(info, invoice, pay_req_with_no_payment_point, successful_payment) + + @pytest.fixture def squeak_core(bitcoin_client, lightning_client): yield SqueakCore(bitcoin_client, lightning_client) @@ -258,6 +289,11 @@ def squeak_core_with_no_uris(bitcoin_client, lightning_client_with_no_uris): yield SqueakCore(bitcoin_client, lightning_client_with_no_uris) +@pytest.fixture +def squeak_core_with_no_payment_point(bitcoin_client, lightning_client_with_no_payment_point): + yield SqueakCore(bitcoin_client, lightning_client_with_no_payment_point) + + @pytest.fixture def peer_address(): yield PeerAddress( @@ -298,6 +334,7 @@ def unpacked_offer(squeak_core, squeak, packaged_offer, seller_peer_address): squeak, packaged_offer, seller_peer_address, + check_payment_point=True, ) @@ -436,9 +473,9 @@ def test_unpack_offer_invalid_squeak_hash(squeak_core, other_squeak, packaged_of assert "does not match squeak hash" in str(excinfo.value) -def test_unpacked_offer_bad_payment_point(squeak_core, squeak, packaged_offer, seller_peer_address): +def test_unpacked_offer_bad_payment_point(squeak_core_with_no_payment_point, squeak, packaged_offer, seller_peer_address): with pytest.raises(Exception) as excinfo: - squeak_core.unpack_offer( + squeak_core_with_no_payment_point.unpack_offer( squeak, packaged_offer, seller_peer_address, @@ -447,6 +484,16 @@ def test_unpacked_offer_bad_payment_point(squeak_core, squeak, packaged_offer, s assert "Invalid payment point." in str(excinfo.value) +def test_unpacked_offer_bad_payment_point_skip_check(squeak_core_with_no_payment_point, squeak, packaged_offer, seller_peer_address): + unpacked_offer = squeak_core_with_no_payment_point.unpack_offer( + squeak, + packaged_offer, + seller_peer_address, + ) + + assert unpacked_offer is not None + + def test_sent_payment(sent_payment, squeak, price_msat, secret_key, seller_pubkey): assert sent_payment.squeak_hash == get_hash(squeak)