|
| 1 | +import 'package:flutter/cupertino.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:integration_test/integration_test.dart'; |
| 4 | +import 'package:ldk_node/ldk_node.dart' as ldk; |
| 5 | +import 'package:path_provider/path_provider.dart'; |
| 6 | + |
| 7 | +void main() { |
| 8 | + BigInt satsToMsats(int sats) => BigInt.from(sats * 1000); |
| 9 | + String mSatsToSats(BigInt mSats) => '${mSats.toInt() ~/ 1000}sats'; |
| 10 | + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 11 | + |
| 12 | + group('bolt11_&_bolt12', () { |
| 13 | + setUp(() async {}); |
| 14 | + testWidgets('bolt11_full_cycle', (WidgetTester tester) async { |
| 15 | + final directory = await getApplicationDocumentsDirectory(); |
| 16 | + final ldkCache = "${directory.path}/ldk_cache"; |
| 17 | + final aliceStoragePath = "$ldkCache/integration/alice"; |
| 18 | + debugPrint('Alice Storage Path: $aliceStoragePath'); |
| 19 | + final alice_builder = ldk.Builder.mutinynet() |
| 20 | + .setEntropyBip39Mnemonic( |
| 21 | + mnemonic: ldk.Mnemonic( |
| 22 | + seedPhrase: |
| 23 | + "replace force spring cruise nothing select glass erupt medal raise consider pull")) |
| 24 | + .setStorageDirPath(aliceStoragePath); |
| 25 | + final aliceNode = await alice_builder.build(); |
| 26 | + await aliceNode.start(); |
| 27 | + final bobStoragePath = "$ldkCache/integration/bob"; |
| 28 | + final bob_builder = ldk.Builder.mutinynet() |
| 29 | + .setEntropyBip39Mnemonic( |
| 30 | + mnemonic: ldk.Mnemonic( |
| 31 | + seedPhrase: |
| 32 | + "skin hospital fee risk health theory actor kiwi solution desert unhappy hello")) |
| 33 | + .setStorageDirPath(bobStoragePath); |
| 34 | + debugPrint('Bob Storage Path: $bobStoragePath'); |
| 35 | + final bobNode = await bob_builder.build(); |
| 36 | + await bobNode.start(); |
| 37 | + debugPrint("Manually syncing Alice's node"); |
| 38 | + await aliceNode.syncWallets(); |
| 39 | + debugPrint("Manually syncing Bob's node"); |
| 40 | + final aliceBalance = |
| 41 | + (await aliceNode.listBalances()).spendableOnchainBalanceSats; |
| 42 | + await bobNode.syncWallets(); |
| 43 | + expect(aliceBalance, 0); |
| 44 | + debugPrint("Alice's onChain balance ${aliceBalance.toString()}"); |
| 45 | + final bobBalance = |
| 46 | + (await bobNode.listBalances()).spendableOnchainBalanceSats; |
| 47 | + debugPrint("Bob's onChain balance ${bobBalance.toString()}"); |
| 48 | + |
| 49 | + final bobBolt11PaymentHandler = await bobNode.bolt11Payment(); |
| 50 | + final bobJitInvoice = await bobBolt11PaymentHandler.receiveViaJitChannel( |
| 51 | + amountMsat: satsToMsats(10000), |
| 52 | + description: 'test', |
| 53 | + expirySecs: 9000, |
| 54 | + ); |
| 55 | + debugPrint("Bob's onChain balance ${bobBalance.toString()}"); |
| 56 | + final aliceBolt11PaymentHandler = await aliceNode.bolt11Payment(); |
| 57 | + final aliceJitInvoice = |
| 58 | + await aliceBolt11PaymentHandler.receiveViaJitChannel( |
| 59 | + amountMsat: satsToMsats(10000), |
| 60 | + description: 'test', |
| 61 | + expirySecs: 9000, |
| 62 | + ); |
| 63 | + final aliceLBalance = |
| 64 | + (await aliceNode.listBalances()).totalLightningBalanceSats; |
| 65 | + debugPrint("Alice's Lightning balance ${aliceLBalance.toString()}"); |
| 66 | + final bobInvoice = await bobBolt11PaymentHandler.receive( |
| 67 | + amountMsat: satsToMsats(10000), |
| 68 | + description: 'test', |
| 69 | + expirySecs: 9000); |
| 70 | + final paymentId = |
| 71 | + await aliceBolt11PaymentHandler.send(invoice: bobInvoice); |
| 72 | + debugPrint("Alice's payment id ${paymentId.field0}"); |
| 73 | + }); |
| 74 | + }); |
| 75 | +} |
0 commit comments