Skip to content

Commit 8016d69

Browse files
committed
integration test added
1 parent 59962f2 commit 8016d69

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import 'dart:typed_data';
2+
3+
import 'package:bdk_flutter/bdk_flutter.dart';
4+
import 'package:flutter/foundation.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:integration_test/integration_test.dart';
7+
8+
void main() {
9+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
10+
group('Descriptor & Wallet', () {
11+
setUp(() async {});
12+
testWidgets('generating psbt using a muti-sig wallet', (_) async {
13+
final externalDescriptor = await Descriptor.create(
14+
descriptor:
15+
"wsh(thresh(2,pk(tpubD6NzVbkrYhZ4XJBfEJ6gt9DiVdfWJijsQTCE3jtXByW3Tk6AVGQ3vL1NNxg3SjB7QkJAuutACCQjrXD8zdZSM1ZmBENszCqy49ECEHmD6rf/0/*),sj:and_v(v:pk(tpubD6NzVbkrYhZ4YfAr3jCBRk4SpqB9L1Hh442y83njwfMaker7EqZd7fHMqyTWrfRYJ1e5t2ue6BYjW5i5yQnmwqbzY1a3kfqNxog1AFcD1aE/0/*),n:older(6)),snj:and_v(v:pk(tprv8ZgxMBicQKsPeitVUz3s6cfyCECovNP7t82FaKPa4UKqV1kssWcXgLkMDjzDbgG9GWoza4pL7z727QitfzkiwX99E1Has3T3a1MKHvYWmQZ/0/*),after(630000))))",
16+
network: Network.signet);
17+
final internalDescriptor = await Descriptor.create(
18+
descriptor:
19+
"wsh(thresh(2,pk(tpubD6NzVbkrYhZ4XJBfEJ6gt9DiVdfWJijsQTCE3jtXByW3Tk6AVGQ3vL1NNxg3SjB7QkJAuutACCQjrXD8zdZSM1ZmBENszCqy49ECEHmD6rf/1/*),sj:and_v(v:pk(tpubD6NzVbkrYhZ4YfAr3jCBRk4SpqB9L1Hh442y83njwfMaker7EqZd7fHMqyTWrfRYJ1e5t2ue6BYjW5i5yQnmwqbzY1a3kfqNxog1AFcD1aE/1/*),n:older(6)),snj:and_v(v:pk(tprv8ZgxMBicQKsPeitVUz3s6cfyCECovNP7t82FaKPa4UKqV1kssWcXgLkMDjzDbgG9GWoza4pL7z727QitfzkiwX99E1Has3T3a1MKHvYWmQZ/1/*),after(630000))))",
20+
network: Network.signet);
21+
22+
final wallet = await Wallet.create(
23+
descriptor: externalDescriptor,
24+
changeDescriptor: internalDescriptor,
25+
network: Network.signet,
26+
databaseConfig: const DatabaseConfig.memory());
27+
final blockchain = await Blockchain.createMutinynet();
28+
wallet.sync(blockchain: blockchain);
29+
debugPrint("Wallet balance: ${wallet.getBalance().total}");
30+
final toAddress = wallet
31+
.getAddress(addressIndex: const AddressIndex.increase())
32+
.address;
33+
debugPrint("Wallet address: ${toAddress.toString()}");
34+
final externalWalletPolicy = wallet.policies(KeychainKind.externalChain);
35+
final ineternalWalletPolicy = wallet.policies(KeychainKind.internalChain);
36+
if (externalWalletPolicy != null && ineternalWalletPolicy != null) {
37+
// Construct external and internal policy paths
38+
final extPath = {
39+
ineternalWalletPolicy.id(): Uint32List.fromList([0, 1])
40+
};
41+
debugPrint("External Policy path: $extPath\n");
42+
43+
final intPath = {
44+
ineternalWalletPolicy.id(): Uint32List.fromList([0, 1])
45+
};
46+
debugPrint("Internal Policy Path: $intPath\n");
47+
48+
// Build the transaction
49+
final txBuilder = TxBuilder()
50+
.addRecipient(
51+
toAddress.scriptPubkey(),
52+
BigInt.from(1000),
53+
)
54+
.doNotSpendChange()
55+
.policyPath(KeychainKind.internalChain, intPath)
56+
.policyPath(KeychainKind.externalChain, extPath);
57+
58+
final (psbt, _) = await txBuilder.finish(wallet);
59+
debugPrint("Transaction serialized: ${psbt.toString()}\n");
60+
}
61+
});
62+
});
63+
}

example/pubspec.lock

+47
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ packages:
181181
description: flutter
182182
source: sdk
183183
version: "0.0.0"
184+
flutter_driver:
185+
dependency: "direct dev"
186+
description: flutter
187+
source: sdk
188+
version: "0.0.0"
184189
flutter_lints:
185190
dependency: "direct dev"
186191
description:
@@ -210,6 +215,11 @@ packages:
210215
url: "https://pub.dev"
211216
source: hosted
212217
version: "2.4.2"
218+
fuchsia_remote_debug_protocol:
219+
dependency: transitive
220+
description: flutter
221+
source: sdk
222+
version: "0.0.0"
213223
glob:
214224
dependency: transitive
215225
description:
@@ -218,6 +228,11 @@ packages:
218228
url: "https://pub.dev"
219229
source: hosted
220230
version: "2.1.2"
231+
integration_test:
232+
dependency: "direct dev"
233+
description: flutter
234+
source: sdk
235+
version: "0.0.0"
221236
json_annotation:
222237
dependency: transitive
223238
description:
@@ -314,6 +329,22 @@ packages:
314329
url: "https://pub.dev"
315330
source: hosted
316331
version: "1.9.0"
332+
platform:
333+
dependency: transitive
334+
description:
335+
name: platform
336+
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
337+
url: "https://pub.dev"
338+
source: hosted
339+
version: "3.1.5"
340+
process:
341+
dependency: transitive
342+
description:
343+
name: process
344+
sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32"
345+
url: "https://pub.dev"
346+
source: hosted
347+
version: "5.0.2"
317348
pub_semver:
318349
dependency: transitive
319350
description:
@@ -375,6 +406,14 @@ packages:
375406
url: "https://pub.dev"
376407
source: hosted
377408
version: "1.2.0"
409+
sync_http:
410+
dependency: transitive
411+
description:
412+
name: sync_http
413+
sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961"
414+
url: "https://pub.dev"
415+
source: hosted
416+
version: "0.3.1"
378417
term_glyph:
379418
dependency: transitive
380419
description:
@@ -439,6 +478,14 @@ packages:
439478
url: "https://pub.dev"
440479
source: hosted
441480
version: "0.5.1"
481+
webdriver:
482+
dependency: transitive
483+
description:
484+
name: webdriver
485+
sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e"
486+
url: "https://pub.dev"
487+
source: hosted
488+
version: "3.0.3"
442489
yaml:
443490
dependency: transitive
444491
description:

example/pubspec.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ dependencies:
3232
dev_dependencies:
3333
flutter_test:
3434
sdk: flutter
35-
35+
integration_test:
36+
sdk: flutter
37+
flutter_driver:
38+
sdk: flutter
3639
# The "flutter_lints" package below contains a set of recommended lints to
3740
# encourage good coding practices. The lint set provided by the package is
3841
# activated in the `analysis_options.yaml` file located at the root of your

0 commit comments

Comments
 (0)