Skip to content

Commit

Permalink
integration test added
Browse files Browse the repository at this point in the history
  • Loading branch information
BitcoinZavior committed Nov 8, 2024
1 parent 59962f2 commit 8016d69
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
63 changes: 63 additions & 0 deletions example/integration_test /full_cycle_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'dart:typed_data';

import 'package:bdk_flutter/bdk_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Descriptor & Wallet', () {
setUp(() async {});
testWidgets('generating psbt using a muti-sig wallet', (_) async {
final externalDescriptor = await Descriptor.create(
descriptor:
"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))))",
network: Network.signet);
final internalDescriptor = await Descriptor.create(
descriptor:
"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))))",
network: Network.signet);

final wallet = await Wallet.create(
descriptor: externalDescriptor,
changeDescriptor: internalDescriptor,
network: Network.signet,
databaseConfig: const DatabaseConfig.memory());
final blockchain = await Blockchain.createMutinynet();
wallet.sync(blockchain: blockchain);
debugPrint("Wallet balance: ${wallet.getBalance().total}");
final toAddress = wallet
.getAddress(addressIndex: const AddressIndex.increase())
.address;
debugPrint("Wallet address: ${toAddress.toString()}");
final externalWalletPolicy = wallet.policies(KeychainKind.externalChain);
final ineternalWalletPolicy = wallet.policies(KeychainKind.internalChain);
if (externalWalletPolicy != null && ineternalWalletPolicy != null) {
// Construct external and internal policy paths
final extPath = {
ineternalWalletPolicy.id(): Uint32List.fromList([0, 1])
};
debugPrint("External Policy path: $extPath\n");

final intPath = {
ineternalWalletPolicy.id(): Uint32List.fromList([0, 1])
};
debugPrint("Internal Policy Path: $intPath\n");

// Build the transaction
final txBuilder = TxBuilder()
.addRecipient(
toAddress.scriptPubkey(),
BigInt.from(1000),
)
.doNotSpendChange()
.policyPath(KeychainKind.internalChain, intPath)
.policyPath(KeychainKind.externalChain, extPath);

final (psbt, _) = await txBuilder.finish(wallet);
debugPrint("Transaction serialized: ${psbt.toString()}\n");
}
});
});
}
47 changes: 47 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_driver:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -210,6 +215,11 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.2"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
glob:
dependency: transitive
description:
Expand All @@ -218,6 +228,11 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
integration_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -314,6 +329,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
platform:
dependency: transitive
description:
name: platform
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
url: "https://pub.dev"
source: hosted
version: "3.1.5"
process:
dependency: transitive
description:
name: process
sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
pub_semver:
dependency: transitive
description:
Expand Down Expand Up @@ -375,6 +406,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
sync_http:
dependency: transitive
description:
name: sync_http
sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
term_glyph:
dependency: transitive
description:
Expand Down Expand Up @@ -439,6 +478,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.1"
webdriver:
dependency: transitive
description:
name: webdriver
sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
yaml:
dependency: transitive
description:
Expand Down
5 changes: 4 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter

integration_test:
sdk: flutter
flutter_driver:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
Expand Down

0 comments on commit 8016d69

Please sign in to comment.