Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions integration_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/create_new_wallet_test.dart \

flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/load_wallet_test.dart \
38 changes: 38 additions & 0 deletions integration_test/create_new_wallet_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:bdk_wallet/core/constants/enums.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:bdk_wallet/main.dart' as app;

void main() {
group('Create wallet test', () {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
testWidgets('full cycle test', (tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 3));

final createNewWalletButton = find.byKey(const Key('create_new_wallet'));
await tester.tap(createNewWalletButton);
await tester.pumpAndSettle();
// create wallet page;
final createWalletSubmitButton =
find.byKey(const Key('create_wallet_button'));
final genSeedButton = find.byKey(const Key('gen_seed_button'));
final passwordField = find.byKey(const Key('password_textfield'));
final bitcoinUrlField = find.byKey(const Key('bitcoin_url_textfield'));
await tester.tap(genSeedButton);
await tester.pumpAndSettle();
await tester.enterText(passwordField, 'password');
await tester.pumpAndSettle();
await tester.enterText(
bitcoinUrlField, 'ssl://electrum.blockstream.info:60002');
await tester.pumpAndSettle();
await tester.tap(createWalletSubmitButton);
await tester.pumpAndSettle();
// dashboard page;
final syncButton = find.byKey(const Key('sync_button'));
await tester.tap(syncButton);
});
});
}
46 changes: 46 additions & 0 deletions integration_test/load_wallet_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:bdk_wallet/main.dart' as app;

void main() {
group('Load wallet test', () {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
testWidgets('full cycle test', (tester) async {
app.main();
await tester.pumpAndSettle(const Duration(seconds: 3));

final createNewWalletButton = find.byKey(const Key('create_new_wallet'));
await tester.tap(createNewWalletButton);
await tester.pumpAndSettle();
// create wallet page;
final createWalletSubmitButton =
find.byKey(const Key('create_wallet_button'));
final mnemonicField = find.byKey(const Key('mnemonic_textfield'));
await tester.enterText(mnemonicField,
'puppy interest whip tonight dad never sudden response push zone pig patch');
await tester.pumpAndSettle();
await tester.tap(createWalletSubmitButton);
await tester.pumpAndSettle();
// dashboard page;
final syncButton = find.byKey(const Key('sync_button'));
await tester.tap(syncButton);
await tester.pumpAndSettle(const Duration(seconds: 6));
final sendBottomBarItem = find.byKey(const Key('Send'));
await tester.tap(sendBottomBarItem);
await tester.pumpAndSettle(const Duration(seconds: 4));
// send page;
final addressField = find.byKey(const Key('address_text_field'));
final amountField = find.byKey(const Key('amount_text_field'));
final sendBtcButton = find.byKey(const Key('send_btc_button'));
await tester.enterText(
addressField, "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB");
await tester.pumpAndSettle();
await tester.enterText(amountField, '1000');
await tester.pumpAndSettle();
await tester.tap(sendBtcButton);
await tester.pumpAndSettle(const Duration(seconds: 6));
});
});
}
7 changes: 7 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
end
end
end
end
12 changes: 9 additions & 3 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
PODS:
- bdk_flutter (0.3.0):
- bdk_flutter (0.28.1):
- Flutter
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
- Flutter (1.0.0)
- integration_test (0.0.1):
- Flutter
- path_provider_ios (0.0.1):
- Flutter
- ReachabilitySwift (5.0.0)
Expand All @@ -13,6 +15,7 @@ DEPENDENCIES:
- bdk_flutter (from `.symlinks/plugins/bdk_flutter/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- Flutter (from `Flutter`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)

SPEC REPOS:
Expand All @@ -26,16 +29,19 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/connectivity_plus/ios"
Flutter:
:path: Flutter
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"

SPEC CHECKSUMS:
bdk_flutter: 9d3a8e3759b7accafdec05390ee4d61e2bd6b150
bdk_flutter: e571a4dff5d36cab3068c804bde44fbd521a0972
connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
PODFILE CHECKSUM: 7ed12c9564b62b763e516c5fa465dc960f533e28

COCOAPODS: 1.11.3
4 changes: 3 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -222,6 +222,7 @@
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -236,6 +237,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
7 changes: 0 additions & 7 deletions lib/application/connectivity/connectivity_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:bloc/bloc.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import 'package:meta/meta.dart';

import '../../core/constants/enums.dart';
import '../../domain/connectivity/i_connectivity_service.dart';
Expand Down Expand Up @@ -33,10 +32,4 @@ class ConnectivityCubit extends Cubit<ConnectivityState> {
void emitConnected(ConnectionType type) => emit(Connected(type));

void emitDisconnected() => emit(Disconnected());

@override
Future<void> close() {
connectivitySubscription.cancel();
return super.close();
}
}
3 changes: 2 additions & 1 deletion lib/infrastructure/blockchain/blockchain_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class BlockchainService extends IBlockchainService {
Future<Either<BlockchainFailure, Unit>> broadcastTransaction(
{required PartiallySignedTransaction psbt}) async {
try {
await _blockchain!.broadcast(psbt);
final tx = await psbt.extractTx();
await _blockchain!.broadcast(tx);
return const Right(unit);
} on Exception catch (_) {
return const Left(BlockchainFailure.unexpected());
Expand Down
68 changes: 40 additions & 28 deletions lib/infrastructure/wallet/wallet_service.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import 'dart:convert';

import 'package:bdk_flutter/bdk_flutter.dart';
import 'package:bdk_wallet/domain/wallet/failure/wallet_failure.dart';
import 'package:bdk_wallet/domain/wallet/interface/i_wallet_Service.dart';
import 'package:bdk_wallet/infrastructure/wallet/dto/wallet_dto.dart';
import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';

import '../core/source/local.dart';

@LazySingleton(as: IWalletService)
class WalletService extends IWalletService {
Wallet? _wallet;

Future<List<WalletDto>> checkIfWalletSaved(WalletDto walletDto) async{
Future<List<WalletDto>> checkIfWalletSaved(WalletDto walletDto) async {
final wallets = await getAllWallets();
final res = wallets.map((e) => e.mnemonic).toList();
if(res.contains(walletDto.mnemonic)){
final res = wallets.map((e) => e.mnemonic).toList();
if (res.contains(walletDto.mnemonic)) {
return wallets;
} else{
} else {
wallets.add(walletDto);
return wallets;
}
}

@override
Future<Either<WalletFailure, Wallet>> createWallet({required WalletDto walletDto}) async {
Future<Either<WalletFailure, Wallet>> createWallet(
{required WalletDto walletDto}) async {
try {
final descriptor = await createDescriptorSecret(walletDto, KeychainKind.External );
final changeDescriptor = await createDescriptorSecret(walletDto,KeychainKind.Internal );
final descriptor =
await createDescriptorSecret(walletDto, KeychainKind.External);
final changeDescriptor =
await createDescriptorSecret(walletDto, KeychainKind.Internal);
final wallets = await checkIfWalletSaved(walletDto);
await writeWallet(wallets);
_wallet = await Wallet.create(
Expand All @@ -38,12 +44,13 @@ class WalletService extends IWalletService {
return const Left(WalletFailure.unexpected());
}
}

Future<bool> writeWallet(List<WalletDto> walletDtos) async {
final wallets = [];
for ( var e in walletDtos){
for (var e in walletDtos) {
wallets.add(jsonEncode(e.toJson()));
}
final res = await Persist().writeToFile("${wallets.toString()}", "wallets");
final res = await Persist().writeToFile("${wallets.toString()}", "wallets");
return res;
}

Expand All @@ -54,16 +61,20 @@ class WalletService extends IWalletService {

@override
Future<List<WalletDto>> getAllWallets() async {
final res = await Persist().readFromFile("wallets") ;
if(res==''){
final res = await Persist().readFromFile("wallets");
if (res == '') {
return [];
} else{
} else {
final wallets = jsonDecode(res) as List;
final walletMaps = wallets.cast<Map<String, dynamic>>().map((map) => map.cast<String, String>()).toList();
final walletDtos= walletMaps.map((e) => WalletDto.fromJson(e)).toList();
final walletMaps = wallets
.cast<Map<String, dynamic>>()
.map((map) => map.cast<String, String>())
.toList();
final walletDtos = walletMaps.map((e) => WalletDto.fromJson(e)).toList();
return walletDtos;
}
}

@override
Future<Either<WalletFailure, String>> genSeed() async {
try {
Expand All @@ -87,9 +98,9 @@ class WalletService extends IWalletService {

@override
Future<Either<WalletFailure, List<TransactionDetails>>>
getConfirmedTransactions() async {
getConfirmedTransactions() async {
try {
final response = await _wallet!.listTransactions();
final response = await _wallet!.listTransactions(true);
return Right(response);
} on Exception catch (e) {
return const Left(WalletFailure.noTransactions());
Expand All @@ -100,7 +111,7 @@ class WalletService extends IWalletService {
Future<Either<WalletFailure, String>> getNewAddress() async {
try {
final response =
await _wallet!.getAddress(addressIndex: AddressIndex.New);
await _wallet!.getAddress(addressIndex: const AddressIndex());
return Right(response.address);
} on Exception catch (_) {
return const Left(WalletFailure.unexpected());
Expand All @@ -109,9 +120,9 @@ class WalletService extends IWalletService {

@override
Future<Either<WalletFailure, List<TransactionDetails>>>
getPendingTransactions() async {
getPendingTransactions() async {
try {
final response = await _wallet!.listTransactions();
final response = await _wallet!.listTransactions(true);
return Right(response);
} on Exception catch (e) {
return const Left(WalletFailure.noTransactions());
Expand All @@ -131,8 +142,8 @@ class WalletService extends IWalletService {
@override
Future<Either<WalletFailure, String>> getLastUsedAddress() async {
try {
final response =
await _wallet!.getAddress(addressIndex: AddressIndex.LastUnused);
final response = await _wallet!
.getAddress(addressIndex: const AddressIndex.lastUnused());
return Right(response.address);
} on Exception catch (_) {
return const Left(WalletFailure.unexpected());
Expand All @@ -149,23 +160,24 @@ class WalletService extends IWalletService {
.addRecipient(script, amount)
.feeRate(1.5)
.finish(_wallet!);
final response = await _wallet!.sign(sbt);
final response = await _wallet!.sign(psbt: sbt.psbt);
return Right(response.psbtBase64);
} on Exception catch (_) {
return const Left(WalletFailure.unexpected());
}
}
}


Future<Descriptor> createDescriptorSecret(WalletDto walletDto, KeychainKind keyChainKind) async {
Future<Descriptor> createDescriptorSecret(
WalletDto walletDto, KeychainKind keyChainKind) async {
final mnemonic = await Mnemonic.fromString(walletDto.mnemonic);
final descriptorSecretKey = await DescriptorSecretKey.create(
network: walletDto.network,
mnemonic: mnemonic,
password: walletDto.password
);
final descriptor = await Descriptor.newBip84(secretKey: descriptorSecretKey.asString(), network: walletDto.network, keyChainKind: keyChainKind);
password: walletDto.password);
final descriptor = await Descriptor.newBip84(
secretKey: descriptorSecretKey,
network: walletDto.network,
keychain: keyChainKind);
return descriptor;
}

8 changes: 2 additions & 6 deletions lib/presentaition/core/page_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ class _PageWrapperState extends State<PageWrapper> {
controller: pageController,
physics: const NeverScrollableScrollPhysics(),
onPageChanged: pageChanged,
children: const [
Home(),
Send(),
Receive(),
LoadBdkWallet()
],
children: const [Home(), Send(), Receive(), LoadBdkWallet()],
),
),
floatingActionButton: FloatingActionButton(
Expand Down Expand Up @@ -130,6 +125,7 @@ class _PageWrapperState extends State<PageWrapper> {
Widget bottomAppBarItem(
String label, int index, int selectedIndex, Icon? icon) {
return GestureDetector(
key: Key(label),
onTap: () {
bottomTapped(index);
},
Expand Down
Loading