|
| 1 | +import 'package:bb_mobile/core/utils/payment_request.dart'; |
| 2 | +import 'package:bb_mobile/core/wallet/domain/entities/wallet.dart'; |
| 3 | +import 'package:bb_mobile/main.dart'; |
| 4 | +import 'package:flutter_test/flutter_test.dart'; |
| 5 | + |
| 6 | +Future<void> main({bool isInitialized = false}) async { |
| 7 | + TestWidgetsFlutterBinding.ensureInitialized(); |
| 8 | + if (!isInitialized) await Bull.init(); |
| 9 | + |
| 10 | + const btcAddress = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq'; |
| 11 | + |
| 12 | + const lnurlStr = |
| 13 | + 'lnurl1dp68gurn8ghj7um9wfmxjcm99e3k7mf0v9cxj0m385ekvcenxc6r2c35xvukxefcv5' |
| 14 | + 'mkvv34x5ekzd3ev56nyd3hxqurzepexejxxepnxscrvwfnv9nxzcn9xq6xyefhvgcxxcmyxy' |
| 15 | + 'mnserxfq5fns'; |
| 16 | + |
| 17 | + const bolt11Invoice = |
| 18 | + 'lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypq' |
| 19 | + 'dq5xysxxatsyp3k7enxv4jsxqzpuaztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2aw' |
| 20 | + 'hz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspfj9srp'; |
| 21 | + |
| 22 | + group('PaymentRequest.parse', () { |
| 23 | + test('BIP21 with LNURL lightning param, label, and message', () async { |
| 24 | + final input = |
| 25 | + 'bitcoin:$btcAddress?lightning=$lnurlStr&label=Donation&message=Thanks'; |
| 26 | + final result = await PaymentRequest.parse(input); |
| 27 | + expect(result, isA<Bip21PaymentRequest>()); |
| 28 | + final bip21 = result as Bip21PaymentRequest; |
| 29 | + expect(bip21.address.toLowerCase(), btcAddress); |
| 30 | + expect(bip21.lightning, lnurlStr); |
| 31 | + expect(bip21.label, 'Donation'); |
| 32 | + expect(bip21.message, 'Thanks'); |
| 33 | + expect(bip21.network, Network.bitcoinMainnet); |
| 34 | + }); |
| 35 | + |
| 36 | + test('BIP21 with Bolt11 lightning param', () async { |
| 37 | + final input = 'bitcoin:$btcAddress?lightning=$bolt11Invoice'; |
| 38 | + final result = await PaymentRequest.parse(input); |
| 39 | + expect(result, isA<Bip21PaymentRequest>()); |
| 40 | + final bip21 = result as Bip21PaymentRequest; |
| 41 | + expect(bip21.address.toLowerCase(), btcAddress); |
| 42 | + expect(bip21.lightning, bolt11Invoice); |
| 43 | + expect(bip21.network, Network.bitcoinMainnet); |
| 44 | + }); |
| 45 | + |
| 46 | + test('HTTPS URL with percent-encoded LNAddress in lightning param', () async { |
| 47 | + const input = |
| 48 | + 'https://admin.bullbitcoin.com/abc' |
| 49 | + '?lightning=ishi%40walletofsatoshi.com&label=pleasefundme'; |
| 50 | + final result = await PaymentRequest.parse(input); |
| 51 | + expect(result, isA<LnAddressPaymentRequest>()); |
| 52 | + expect( |
| 53 | + (result as LnAddressPaymentRequest).address, |
| 54 | + 'ishi@walletofsatoshi.com', |
| 55 | + ); |
| 56 | + }); |
| 57 | + }); |
| 58 | +} |
0 commit comments