Skip to content

Commit 28ddb62

Browse files
test: add payment request parsing tests for BIP21 and HTTPS URIs
1 parent 4a3928e commit 28ddb62

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Run with: fvm flutter test test/core_test/utils/payment_request_test.dart
2+
// Requires native FFI (bdk) — use `flutter test`, not `dart test`.
3+
// The HTTPS/LNAddress test (needs boltz FFI + network) lives in
4+
// integration_test/payment_request_test.dart.
5+
6+
import 'package:bb_mobile/core/utils/payment_request.dart';
7+
import 'package:bb_mobile/core/wallet/domain/entities/wallet.dart';
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
const btcAddress = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq';
12+
13+
const lnurlStr =
14+
'lnurl1dp68gurn8ghj7um9wfmxjcm99e3k7mf0v9cxj0m385ekvcenxc6r2c35xvukxefcv5'
15+
'mkvv34x5ekzd3ev56nyd3hxqurzepexejxxepnxscrvwfnv9nxzcn9xq6xyefhvgcxxcmyxy'
16+
'mnserxfq5fns';
17+
18+
const bolt11Invoice =
19+
'lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypq'
20+
'dq5xysxxatsyp3k7enxv4jsxqzpuaztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2aw'
21+
'hz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspfj9srp';
22+
23+
group('PaymentRequest.parse', () {
24+
// bitcoin: URI whose lightning param is a LNURL with extra query params
25+
// (label, message). The parser must return bip21 with the bare lnurl string
26+
// in lightning — not the whole "lnurl1…&label=…" fragment.
27+
test('BIP21 with LNURL lightning param, label, and message', () async {
28+
final input =
29+
'bitcoin:$btcAddress?lightning=$lnurlStr&label=Donation&message=Thanks';
30+
final result = await PaymentRequest.parse(input);
31+
expect(result, isA<Bip21PaymentRequest>());
32+
final bip21 = result as Bip21PaymentRequest;
33+
expect(bip21.address.toLowerCase(), btcAddress);
34+
expect(bip21.lightning, lnurlStr);
35+
expect(bip21.label, 'Donation');
36+
expect(bip21.message, 'Thanks');
37+
expect(bip21.network, Network.bitcoinMainnet);
38+
});
39+
40+
// bitcoin: URI whose lightning param is a standard Bolt11 invoice
41+
// (2500u = 0.0025 BTC = 250 000 sats).
42+
test('BIP21 with Bolt11 lightning param', () async {
43+
final input = 'bitcoin:$btcAddress?lightning=$bolt11Invoice';
44+
final result = await PaymentRequest.parse(input);
45+
expect(result, isA<Bip21PaymentRequest>());
46+
final bip21 = result as Bip21PaymentRequest;
47+
expect(bip21.address.toLowerCase(), btcAddress);
48+
expect(bip21.lightning, bolt11Invoice);
49+
expect(bip21.network, Network.bitcoinMainnet);
50+
});
51+
});
52+
}

0 commit comments

Comments
 (0)