mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
Merge remote-tracking branch 'cypherstack/ui-fixes' into simplex
This commit is contained in:
commit
c330cf973c
5 changed files with 646 additions and 640 deletions
|
@ -84,12 +84,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("get hashcode", () {
|
// test("get hashcode", () {
|
||||||
final adapter = LelantusCoinAdapter();
|
// final adapter = LelantusCoinAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 9);
|
// expect(result, 9);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("compare operator", () {
|
group("compare operator", () {
|
||||||
test("is equal one", () {
|
test("is equal one", () {
|
||||||
|
|
|
@ -52,12 +52,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("TransactionDataAdapter.hashcode", () {
|
// test("TransactionDataAdapter.hashcode", () {
|
||||||
final adapter = TransactionDataAdapter();
|
// final adapter = TransactionDataAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 1);
|
// expect(result, 1);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("TransactionDataAdapter compare operator", () {
|
group("TransactionDataAdapter compare operator", () {
|
||||||
test("TransactionDataAdapter is equal one", () {
|
test("TransactionDataAdapter is equal one", () {
|
||||||
|
@ -147,12 +147,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("TransactionChunkAdapter.hashcode", () {
|
// test("TransactionChunkAdapter.hashcode", () {
|
||||||
final adapter = TransactionChunkAdapter();
|
// final adapter = TransactionChunkAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 2);
|
// expect(result, 2);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("TransactionChunkAdapter compare operator", () {
|
group("TransactionChunkAdapter compare operator", () {
|
||||||
test("TransactionChunkAdapter is equal one", () {
|
test("TransactionChunkAdapter is equal one", () {
|
||||||
|
@ -377,12 +377,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("TransactionAdapter.hashcode", () {
|
// test("TransactionAdapter.hashcode", () {
|
||||||
final adapter = TransactionAdapter();
|
// final adapter = TransactionAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 3);
|
// expect(result, 3);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("TransactionAdapter compare operator", () {
|
group("TransactionAdapter compare operator", () {
|
||||||
test("TransactionAdapter is equal one", () {
|
test("TransactionAdapter is equal one", () {
|
||||||
|
@ -401,7 +401,7 @@ void main() {
|
||||||
expect(result, true);
|
expect(result, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("TransactionAdapteris not equal one", () {
|
test("TransactionAdapter is not equal one", () {
|
||||||
final a = TransactionAdapter();
|
final a = TransactionAdapter();
|
||||||
final b = TransactionDataAdapter();
|
final b = TransactionDataAdapter();
|
||||||
|
|
||||||
|
@ -517,12 +517,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("InputAdapter.hashcode", () {
|
// test("InputAdapter.hashcode", () {
|
||||||
final adapter = InputAdapter();
|
// final adapter = InputAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 4);
|
// expect(result, 4);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("InputAdapter compare operator", () {
|
group("InputAdapter compare operator", () {
|
||||||
test("InputAdapter is equal one", () {
|
test("InputAdapter is equal one", () {
|
||||||
|
@ -633,12 +633,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("OutputAdapter.hashcode", () {
|
// test("OutputAdapter.hashcode", () {
|
||||||
final adapter = OutputAdapter();
|
// final adapter = OutputAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 5);
|
// expect(result, 5);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("OutputAdapter compare operator", () {
|
group("OutputAdapter compare operator", () {
|
||||||
test("OutputAdapter is equal one", () {
|
test("OutputAdapter is equal one", () {
|
||||||
|
|
|
@ -87,12 +87,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("UtxoDataAdapter.hashcode", () {
|
// test("UtxoDataAdapter.hashcode", () {
|
||||||
final adapter = UtxoDataAdapter();
|
// final adapter = UtxoDataAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 6);
|
// expect(result, 6);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("UtxoDataAdapter compare operator", () {
|
group("UtxoDataAdapter compare operator", () {
|
||||||
test("UtxoDataAdapter is equal one", () {
|
test("UtxoDataAdapter is equal one", () {
|
||||||
|
@ -238,12 +238,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("UtxoObjectAdapter.hashcode", () {
|
// test("UtxoObjectAdapter.hashcode", () {
|
||||||
final adapter = UtxoObjectAdapter();
|
// final adapter = UtxoObjectAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 7);
|
// expect(result, 7);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("UtxoObjectAdapter compare operator", () {
|
group("UtxoObjectAdapter compare operator", () {
|
||||||
test("UtxoObjectAdapter is equal one", () {
|
test("UtxoObjectAdapter is equal one", () {
|
||||||
|
@ -359,12 +359,12 @@ void main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("StatusAdapter.hashcode", () {
|
// test("StatusAdapter.hashcode", () {
|
||||||
final adapter = StatusAdapter();
|
// final adapter = StatusAdapter();
|
||||||
|
//
|
||||||
final result = adapter.hashCode;
|
// final result = adapter.hashCode;
|
||||||
expect(result, 8);
|
// expect(result, 8);
|
||||||
});
|
// });
|
||||||
|
|
||||||
group("StatusAdapter compare operator", () {
|
group("StatusAdapter compare operator", () {
|
||||||
test("StatusAdapter is equal one", () {
|
test("StatusAdapter is equal one", () {
|
||||||
|
|
|
@ -1,228 +1,231 @@
|
||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
import 'dart:io';
|
// import 'dart:io';
|
||||||
import 'dart:math';
|
// import 'dart:math';
|
||||||
|
//
|
||||||
import 'package:cw_core/node.dart';
|
// TODO: move these tests to libmonero
|
||||||
import 'package:cw_core/unspent_coins_info.dart';
|
// TODO: use temp dir for wallets testing and not production location
|
||||||
import 'package:cw_core/wallet_base.dart';
|
//
|
||||||
import 'package:cw_core/wallet_credentials.dart';
|
// import 'package:cw_core/node.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
// import 'package:cw_core/unspent_coins_info.dart';
|
||||||
import 'package:cw_core/wallet_service.dart';
|
// import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
// import 'package:cw_core/wallet_credentials.dart';
|
||||||
import 'package:cw_monero/monero_wallet.dart';
|
// import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:flutter_libmonero/core/key_service.dart';
|
// import 'package:cw_core/wallet_service.dart';
|
||||||
import 'package:flutter_libmonero/core/wallet_creation_service.dart';
|
// import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:flutter_libmonero/monero/monero.dart';
|
// import 'package:cw_monero/monero_wallet.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
// import 'package:flutter_libmonero/core/key_service.dart';
|
||||||
import 'package:hive/hive.dart';
|
// import 'package:flutter_libmonero/core/wallet_creation_service.dart';
|
||||||
import 'package:hive_test/hive_test.dart';
|
// import 'package:flutter_libmonero/monero/monero.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
// import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:stackwallet/services/wallets.dart';
|
// import 'package:hive/hive.dart';
|
||||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
// import 'package:hive_test/hive_test.dart';
|
||||||
|
// import 'package:path_provider/path_provider.dart';
|
||||||
import 'monero_wallet_test_data.dart';
|
// import 'package:stackwallet/services/wallets.dart';
|
||||||
|
// import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
FakeSecureStorage? storage;
|
//
|
||||||
WalletService? walletService;
|
// import 'monero_wallet_test_data.dart';
|
||||||
KeyService? keysStorage;
|
//
|
||||||
MoneroWalletBase? walletBase;
|
// FakeSecureStorage? storage;
|
||||||
late WalletCreationService _walletCreationService;
|
// WalletService? walletService;
|
||||||
dynamic _walletInfoSource;
|
// KeyService? keysStorage;
|
||||||
Wallets? walletsService;
|
// MoneroWalletBase? walletBase;
|
||||||
|
// late WalletCreationService _walletCreationService;
|
||||||
String path = '';
|
// dynamic _walletInfoSource;
|
||||||
|
// Wallets? walletsService;
|
||||||
String name = 'namee${Random().nextInt(10000000)}';
|
//
|
||||||
int nettype = 0;
|
// String path = '';
|
||||||
WalletType type = WalletType.monero;
|
//
|
||||||
|
// String name = 'namee${Random().nextInt(10000000)}';
|
||||||
|
// int nettype = 0;
|
||||||
|
// WalletType type = WalletType.monero;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
storage = FakeSecureStorage();
|
// storage = FakeSecureStorage();
|
||||||
keysStorage = KeyService(storage!);
|
// keysStorage = KeyService(storage!);
|
||||||
WalletInfo walletInfo = WalletInfo.external(
|
// WalletInfo walletInfo = WalletInfo.external(
|
||||||
id: '',
|
// id: '',
|
||||||
name: '',
|
// name: '',
|
||||||
type: type,
|
// type: type,
|
||||||
isRecovery: false,
|
// isRecovery: false,
|
||||||
restoreHeight: 0,
|
// restoreHeight: 0,
|
||||||
date: DateTime.now(),
|
// date: DateTime.now(),
|
||||||
path: '',
|
// path: '',
|
||||||
address: '',
|
// address: '',
|
||||||
dirPath: '');
|
// dirPath: '');
|
||||||
late WalletCredentials credentials;
|
// late WalletCredentials credentials;
|
||||||
|
//
|
||||||
monero.onStartup();
|
// monero.onStartup();
|
||||||
|
//
|
||||||
bool hiveAdaptersRegistered = false;
|
// bool hiveAdaptersRegistered = false;
|
||||||
|
//
|
||||||
group("Mainnet tests", () {
|
// group("Mainnet tests", () {
|
||||||
setUp(() async {
|
// setUp(() async {
|
||||||
await setUpTestHive();
|
// await setUpTestHive();
|
||||||
if (!hiveAdaptersRegistered) {
|
// if (!hiveAdaptersRegistered) {
|
||||||
hiveAdaptersRegistered = true;
|
// hiveAdaptersRegistered = true;
|
||||||
|
//
|
||||||
Hive.registerAdapter(NodeAdapter());
|
// Hive.registerAdapter(NodeAdapter());
|
||||||
Hive.registerAdapter(WalletInfoAdapter());
|
// Hive.registerAdapter(WalletInfoAdapter());
|
||||||
Hive.registerAdapter(WalletTypeAdapter());
|
// Hive.registerAdapter(WalletTypeAdapter());
|
||||||
Hive.registerAdapter(UnspentCoinsInfoAdapter());
|
// Hive.registerAdapter(UnspentCoinsInfoAdapter());
|
||||||
|
//
|
||||||
final wallets = await Hive.openBox<dynamic>('wallets');
|
// final wallets = await Hive.openBox<dynamic>('wallets');
|
||||||
await wallets.put('currentWalletName', name);
|
// await wallets.put('currentWalletName', name);
|
||||||
|
//
|
||||||
_walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
// _walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
||||||
walletService = monero
|
// walletService = monero
|
||||||
.createMoneroWalletService(_walletInfoSource as Box<WalletInfo>);
|
// .createMoneroWalletService(_walletInfoSource as Box<WalletInfo>);
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// if (name?.isEmpty ?? true) {
|
|
||||||
// name = await generateName();
|
|
||||||
// }
|
// }
|
||||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
//
|
||||||
path = await pathForWallet(name: name, type: type);
|
// try {
|
||||||
credentials =
|
// // if (name?.isEmpty ?? true) {
|
||||||
// // creating a new wallet
|
// // name = await generateName();
|
||||||
// monero.createMoneroNewWalletCredentials(
|
// // }
|
||||||
// name: name, language: "English");
|
// final dirPath = await pathForWalletDir(name: name, type: type);
|
||||||
// restoring a previous wallet
|
// path = await pathForWallet(name: name, type: type);
|
||||||
monero.createMoneroRestoreWalletFromSeedCredentials(
|
// credentials =
|
||||||
name: name, height: 2580000, mnemonic: testMnemonic);
|
// // // creating a new wallet
|
||||||
|
// // monero.createMoneroNewWalletCredentials(
|
||||||
walletInfo = WalletInfo.external(
|
// // name: name, language: "English");
|
||||||
id: WalletBase.idFor(name, type),
|
// // restoring a previous wallet
|
||||||
name: name,
|
// monero.createMoneroRestoreWalletFromSeedCredentials(
|
||||||
type: type,
|
// name: name, height: 2580000, mnemonic: testMnemonic);
|
||||||
isRecovery: false,
|
//
|
||||||
restoreHeight: credentials.height ?? 0,
|
// walletInfo = WalletInfo.external(
|
||||||
date: DateTime.now(),
|
// id: WalletBase.idFor(name, type),
|
||||||
path: path,
|
// name: name,
|
||||||
address: "",
|
// type: type,
|
||||||
dirPath: dirPath);
|
// isRecovery: false,
|
||||||
credentials.walletInfo = walletInfo;
|
// restoreHeight: credentials.height ?? 0,
|
||||||
|
// date: DateTime.now(),
|
||||||
_walletCreationService = WalletCreationService(
|
// path: path,
|
||||||
secureStorage: storage,
|
// address: "",
|
||||||
walletService: walletService,
|
// dirPath: dirPath);
|
||||||
keyService: keysStorage,
|
// credentials.walletInfo = walletInfo;
|
||||||
);
|
//
|
||||||
_walletCreationService.changeWalletType();
|
// _walletCreationService = WalletCreationService(
|
||||||
} catch (e, s) {
|
// secureStorage: storage,
|
||||||
print(e);
|
// walletService: walletService,
|
||||||
print(s);
|
// keyService: keysStorage,
|
||||||
}
|
// );
|
||||||
});
|
// _walletCreationService.changeWalletType();
|
||||||
|
// } catch (e, s) {
|
||||||
test("Test mainnet address generation from seed", () async {
|
// print(e);
|
||||||
final wallet = await
|
// print(s);
|
||||||
// _walletCreationService.create(credentials);
|
// }
|
||||||
_walletCreationService.restoreFromSeed(credentials);
|
// });
|
||||||
walletInfo.address = wallet.walletAddresses.address;
|
//
|
||||||
//print(walletInfo.address);
|
// test("Test mainnet address generation from seed", () async {
|
||||||
|
// final wallet = await
|
||||||
await _walletInfoSource.add(walletInfo);
|
// // _walletCreationService.create(credentials);
|
||||||
walletBase?.close();
|
// _walletCreationService.restoreFromSeed(credentials);
|
||||||
walletBase = wallet as MoneroWalletBase;
|
// walletInfo.address = wallet.walletAddresses.address;
|
||||||
//print("${walletBase?.seed}");
|
// //print(walletInfo.address);
|
||||||
|
//
|
||||||
expect(await walletBase!.validateAddress(walletInfo.address ?? ''), true);
|
// await _walletInfoSource.add(walletInfo);
|
||||||
|
// walletBase?.close();
|
||||||
// print(walletBase);
|
// walletBase = wallet as MoneroWalletBase;
|
||||||
// loggerPrint(walletBase.toString());
|
// //print("${walletBase?.seed}");
|
||||||
// loggerPrint("name: ${walletBase!.name} seed: ${walletBase!.seed} id: "
|
//
|
||||||
// "${walletBase!.id} walletinfo: ${toStringForinfo(walletBase!.walletInfo)} type: ${walletBase!.type} balance: "
|
// expect(await walletBase!.validateAddress(walletInfo.address ?? ''), true);
|
||||||
// "${walletBase!.balance.entries.first.value.available} currency: ${walletBase!.currency}");
|
//
|
||||||
|
// // print(walletBase);
|
||||||
expect(walletInfo.address, mainnetTestData[0][0]);
|
// // loggerPrint(walletBase.toString());
|
||||||
expect(walletBase!.getTransactionAddress(0, 0), mainnetTestData[0][0]);
|
// // loggerPrint("name: ${walletBase!.name} seed: ${walletBase!.seed} id: "
|
||||||
expect(walletBase!.getTransactionAddress(0, 1), mainnetTestData[0][1]);
|
// // "${walletBase!.id} walletinfo: ${toStringForinfo(walletBase!.walletInfo)} type: ${walletBase!.type} balance: "
|
||||||
expect(walletBase!.getTransactionAddress(0, 2), mainnetTestData[0][2]);
|
// // "${walletBase!.balance.entries.first.value.available} currency: ${walletBase!.currency}");
|
||||||
expect(walletBase!.getTransactionAddress(1, 0), mainnetTestData[1][0]);
|
//
|
||||||
expect(walletBase!.getTransactionAddress(1, 1), mainnetTestData[1][1]);
|
// expect(walletInfo.address, mainnetTestData[0][0]);
|
||||||
expect(walletBase!.getTransactionAddress(1, 2), mainnetTestData[1][2]);
|
// expect(walletBase!.getTransactionAddress(0, 0), mainnetTestData[0][0]);
|
||||||
|
// expect(walletBase!.getTransactionAddress(0, 1), mainnetTestData[0][1]);
|
||||||
expect(walletBase!.validateAddress(''), false);
|
// expect(walletBase!.getTransactionAddress(0, 2), mainnetTestData[0][2]);
|
||||||
expect(
|
// expect(walletBase!.getTransactionAddress(1, 0), mainnetTestData[1][0]);
|
||||||
walletBase!.validateAddress(
|
// expect(walletBase!.getTransactionAddress(1, 1), mainnetTestData[1][1]);
|
||||||
'4AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'),
|
// expect(walletBase!.getTransactionAddress(1, 2), mainnetTestData[1][2]);
|
||||||
true);
|
//
|
||||||
expect(
|
// expect(walletBase!.validateAddress(''), false);
|
||||||
walletBase!.validateAddress(
|
// expect(
|
||||||
'4asdfkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gpjkl'),
|
// walletBase!.validateAddress(
|
||||||
false);
|
// '4AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'),
|
||||||
expect(
|
// true);
|
||||||
walletBase!.validateAddress(
|
// expect(
|
||||||
'8AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'),
|
// walletBase!.validateAddress(
|
||||||
false);
|
// '4asdfkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gpjkl'),
|
||||||
expect(
|
// false);
|
||||||
walletBase!.validateAddress(
|
// expect(
|
||||||
'84kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'),
|
// walletBase!.validateAddress(
|
||||||
true);
|
// '8AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'),
|
||||||
expect(
|
// false);
|
||||||
walletBase!.validateAddress(
|
// expect(
|
||||||
'8asdfuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenjkl'),
|
// walletBase!.validateAddress(
|
||||||
false);
|
// '84kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'),
|
||||||
expect(
|
// true);
|
||||||
walletBase!.validateAddress(
|
// expect(
|
||||||
'44kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'),
|
// walletBase!.validateAddress(
|
||||||
false);
|
// '8asdfuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenjkl'),
|
||||||
});
|
// false);
|
||||||
});
|
// expect(
|
||||||
/*
|
// walletBase!.validateAddress(
|
||||||
// Not needed; only folder created, wallet files not saved yet. TODO test saving and deleting wallet files and make sure to clean up leftover folder afterwards
|
// '44kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'),
|
||||||
group("Mainnet wallet deletion test", () {
|
// false);
|
||||||
test("Test mainnet wallet existence", () {
|
// });
|
||||||
expect(monero_wallet_manager.isWalletExistSync(path: path), true);
|
// });
|
||||||
});
|
// /*
|
||||||
|
// // Not needed; only folder created, wallet files not saved yet. TODO test saving and deleting wallet files and make sure to clean up leftover folder afterwards
|
||||||
test("Test mainnet wallet deletion", () {
|
// group("Mainnet wallet deletion test", () {
|
||||||
// Remove wallet from wallet service
|
// test("Test mainnet wallet existence", () {
|
||||||
walletService?.remove(name);
|
// expect(monero_wallet_manager.isWalletExistSync(path: path), true);
|
||||||
walletsService?.removeWallet(walletId: name);
|
// });
|
||||||
expect(monero_wallet_manager.isWalletExistSync(path: path), false);
|
//
|
||||||
});
|
// test("Test mainnet wallet deletion", () {
|
||||||
});
|
// // Remove wallet from wallet service
|
||||||
|
// walletService?.remove(name);
|
||||||
group("Mainnet node tests", () {
|
// walletsService?.removeWallet(walletId: name);
|
||||||
test("Test mainnet node connection", () async {
|
// expect(monero_wallet_manager.isWalletExistSync(path: path), false);
|
||||||
await walletBase?.connectToNode(
|
// });
|
||||||
node: Node(
|
// });
|
||||||
uri: "monero-stagenet.stackwallet.com:38081",
|
//
|
||||||
type: WalletType.moneroStageNet));
|
// group("Mainnet node tests", () {
|
||||||
await walletBase!.rescan(
|
// test("Test mainnet node connection", () async {
|
||||||
height:
|
// await walletBase?.connectToNode(
|
||||||
credentials.height); // Probably shouldn't be rescanning from 0...
|
// node: Node(
|
||||||
await walletBase!.getNodeHeight();
|
// uri: "monero-stagenet.stackwallet.com:38081",
|
||||||
int height = await walletBase!.getNodeHeight();
|
// type: WalletType.moneroStageNet));
|
||||||
print('height: $height');
|
// await walletBase!.rescan(
|
||||||
bool connected = await walletBase!.isConnected();
|
// height:
|
||||||
print('connected: $connected');
|
// credentials.height); // Probably shouldn't be rescanning from 0...
|
||||||
|
// await walletBase!.getNodeHeight();
|
||||||
//expect...
|
// int height = await walletBase!.getNodeHeight();
|
||||||
});
|
// print('height: $height');
|
||||||
});
|
// bool connected = await walletBase!.isConnected();
|
||||||
*/
|
// print('connected: $connected');
|
||||||
|
//
|
||||||
// TODO test deletion of wallets ... and delete them
|
// //expect...
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// */
|
||||||
|
//
|
||||||
|
// // TODO test deletion of wallets ... and delete them
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> pathForWalletDir(
|
// Future<String> pathForWalletDir(
|
||||||
{required String name, required WalletType type}) async {
|
// {required String name, required WalletType type}) async {
|
||||||
Directory root = (await getApplicationDocumentsDirectory());
|
// Directory root = (await getApplicationDocumentsDirectory());
|
||||||
if (Platform.isIOS) {
|
// if (Platform.isIOS) {
|
||||||
root = (await getLibraryDirectory());
|
// root = (await getLibraryDirectory());
|
||||||
}
|
// }
|
||||||
final prefix = walletTypeToString(type).toLowerCase();
|
// final prefix = walletTypeToString(type).toLowerCase();
|
||||||
final walletsDir = Directory('${root.path}/wallets');
|
// final walletsDir = Directory('${root.path}/wallets');
|
||||||
final walletDire = Directory('${walletsDir.path}/$prefix/$name');
|
// final walletDire = Directory('${walletsDir.path}/$prefix/$name');
|
||||||
|
//
|
||||||
if (!walletDire.existsSync()) {
|
// if (!walletDire.existsSync()) {
|
||||||
walletDire.createSync(recursive: true);
|
// walletDire.createSync(recursive: true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return walletDire.path;
|
// return walletDire.path;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future<String> pathForWallet(
|
// Future<String> pathForWallet(
|
||||||
{required String name, required WalletType type}) async =>
|
// {required String name, required WalletType type}) async =>
|
||||||
await pathForWalletDir(name: name, type: type)
|
// await pathForWalletDir(name: name, type: type)
|
||||||
.then((path) => '$path/$name');
|
// .then((path) => '$path/$name');
|
||||||
|
|
|
@ -1,367 +1,370 @@
|
||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
import 'dart:io';
|
// import 'dart:io';
|
||||||
import 'dart:math';
|
// import 'dart:math';
|
||||||
|
//
|
||||||
import 'package:cw_core/node.dart';
|
// TODO: move these tests to libmonero
|
||||||
import 'package:cw_core/unspent_coins_info.dart';
|
// TODO: use temp dir for wallets testing and not production location
|
||||||
import 'package:cw_core/wallet_base.dart';
|
//
|
||||||
import 'package:cw_core/wallet_credentials.dart';
|
// import 'package:cw_core/node.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
// import 'package:cw_core/unspent_coins_info.dart';
|
||||||
import 'package:cw_core/wallet_service.dart';
|
// import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
// import 'package:cw_core/wallet_credentials.dart';
|
||||||
import 'package:cw_wownero/wownero_wallet.dart';
|
// import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:flutter_libmonero/core/key_service.dart';
|
// import 'package:cw_core/wallet_service.dart';
|
||||||
import 'package:flutter_libmonero/core/wallet_creation_service.dart';
|
// import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:flutter_libmonero/wownero/wownero.dart';
|
// import 'package:cw_wownero/wownero_wallet.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
// import 'package:flutter_libmonero/core/key_service.dart';
|
||||||
import 'package:hive/hive.dart';
|
// import 'package:flutter_libmonero/core/wallet_creation_service.dart';
|
||||||
import 'package:hive_test/hive_test.dart';
|
// import 'package:flutter_libmonero/wownero/wownero.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
// import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
// import 'package:hive/hive.dart';
|
||||||
|
// import 'package:hive_test/hive_test.dart';
|
||||||
import 'wownero_wallet_test_data.dart';
|
// import 'package:path_provider/path_provider.dart';
|
||||||
|
// import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
FakeSecureStorage? storage;
|
//
|
||||||
WalletService? walletService;
|
// import 'wownero_wallet_test_data.dart';
|
||||||
KeyService? keysStorage;
|
//
|
||||||
WowneroWalletBase? walletBase;
|
// FakeSecureStorage? storage;
|
||||||
late WalletCreationService _walletCreationService;
|
// WalletService? walletService;
|
||||||
dynamic _walletInfoSource;
|
// KeyService? keysStorage;
|
||||||
|
// WowneroWalletBase? walletBase;
|
||||||
String path = '';
|
// late WalletCreationService _walletCreationService;
|
||||||
|
// dynamic _walletInfoSource;
|
||||||
String name = '';
|
//
|
||||||
int nettype = 0;
|
// String path = '';
|
||||||
WalletType type = WalletType.wownero;
|
//
|
||||||
|
// String name = '';
|
||||||
|
// int nettype = 0;
|
||||||
|
// WalletType type = WalletType.wownero;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
storage = FakeSecureStorage();
|
// storage = FakeSecureStorage();
|
||||||
keysStorage = KeyService(storage!);
|
// keysStorage = KeyService(storage!);
|
||||||
WalletInfo walletInfo = WalletInfo.external(
|
// WalletInfo walletInfo = WalletInfo.external(
|
||||||
id: '',
|
// id: '',
|
||||||
name: '',
|
// name: '',
|
||||||
type: type,
|
// type: type,
|
||||||
isRecovery: false,
|
// isRecovery: false,
|
||||||
restoreHeight: 0,
|
// restoreHeight: 0,
|
||||||
date: DateTime.now(),
|
// date: DateTime.now(),
|
||||||
path: '',
|
// path: '',
|
||||||
address: '',
|
// address: '',
|
||||||
dirPath: '');
|
// dirPath: '');
|
||||||
late WalletCredentials credentials;
|
// late WalletCredentials credentials;
|
||||||
|
//
|
||||||
wownero.onStartup();
|
// wownero.onStartup();
|
||||||
|
//
|
||||||
bool hiveAdaptersRegistered = false;
|
// bool hiveAdaptersRegistered = false;
|
||||||
|
//
|
||||||
group("Wownero 14 word seed generation", () {
|
// group("Wownero 14 word seed generation", () {
|
||||||
setUp(() async {
|
// setUp(() async {
|
||||||
await setUpTestHive();
|
// await setUpTestHive();
|
||||||
if (!hiveAdaptersRegistered) {
|
// if (!hiveAdaptersRegistered) {
|
||||||
hiveAdaptersRegistered = true;
|
// hiveAdaptersRegistered = true;
|
||||||
|
//
|
||||||
Hive.registerAdapter(NodeAdapter());
|
// Hive.registerAdapter(NodeAdapter());
|
||||||
Hive.registerAdapter(WalletInfoAdapter());
|
// Hive.registerAdapter(WalletInfoAdapter());
|
||||||
Hive.registerAdapter(WalletTypeAdapter());
|
// Hive.registerAdapter(WalletTypeAdapter());
|
||||||
Hive.registerAdapter(UnspentCoinsInfoAdapter());
|
// Hive.registerAdapter(UnspentCoinsInfoAdapter());
|
||||||
|
//
|
||||||
final wallets = await Hive.openBox<dynamic>('wallets');
|
// final wallets = await Hive.openBox<dynamic>('wallets');
|
||||||
await wallets.put('currentWalletName', name);
|
// await wallets.put('currentWalletName', name);
|
||||||
|
//
|
||||||
_walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
// _walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
||||||
walletService = wownero
|
// walletService = wownero
|
||||||
.createWowneroWalletService(_walletInfoSource as Box<WalletInfo>);
|
// .createWowneroWalletService(_walletInfoSource as Box<WalletInfo>);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
name = 'namee${Random().nextInt(10000000)}';
|
// name = 'namee${Random().nextInt(10000000)}';
|
||||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
// final dirPath = await pathForWalletDir(name: name, type: type);
|
||||||
path = await pathForWallet(name: name, type: type);
|
// path = await pathForWallet(name: name, type: type);
|
||||||
credentials = wownero.createWowneroNewWalletCredentials(
|
// credentials = wownero.createWowneroNewWalletCredentials(
|
||||||
name: name,
|
// name: name,
|
||||||
language: "English",
|
// language: "English",
|
||||||
seedWordsLength: 14); // TODO catch failure
|
// seedWordsLength: 14); // TODO catch failure
|
||||||
|
//
|
||||||
walletInfo = WalletInfo.external(
|
// walletInfo = WalletInfo.external(
|
||||||
id: WalletBase.idFor(name, type),
|
// id: WalletBase.idFor(name, type),
|
||||||
name: name,
|
// name: name,
|
||||||
type: type,
|
// type: type,
|
||||||
isRecovery: false,
|
// isRecovery: false,
|
||||||
restoreHeight: credentials.height ?? 0,
|
// restoreHeight: credentials.height ?? 0,
|
||||||
date: DateTime.now(),
|
// date: DateTime.now(),
|
||||||
path: path,
|
// path: path,
|
||||||
address: "",
|
// address: "",
|
||||||
dirPath: dirPath);
|
// dirPath: dirPath);
|
||||||
credentials.walletInfo = walletInfo;
|
// credentials.walletInfo = walletInfo;
|
||||||
|
//
|
||||||
_walletCreationService = WalletCreationService(
|
// _walletCreationService = WalletCreationService(
|
||||||
secureStorage: storage,
|
// secureStorage: storage,
|
||||||
walletService: walletService,
|
// walletService: walletService,
|
||||||
keyService: keysStorage,
|
// keyService: keysStorage,
|
||||||
);
|
// );
|
||||||
_walletCreationService.changeWalletType();
|
// _walletCreationService.changeWalletType();
|
||||||
} catch (e, s) {
|
// } catch (e, s) {
|
||||||
print(e);
|
// print(e);
|
||||||
print(s);
|
// print(s);
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
test("Wownero 14 word seed address generation", () async {
|
// test("Wownero 14 word seed address generation", () async {
|
||||||
final wallet = await _walletCreationService.create(credentials);
|
// final wallet = await _walletCreationService.create(credentials);
|
||||||
// TODO validate mnemonic
|
// // TODO validate mnemonic
|
||||||
walletInfo.address = wallet.walletAddresses.address;
|
// walletInfo.address = wallet.walletAddresses.address;
|
||||||
|
//
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
await _walletInfoSource.add(walletInfo);
|
// await _walletInfoSource.add(walletInfo);
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
|
//
|
||||||
expect(
|
// expect(
|
||||||
await walletBase!
|
// await walletBase!
|
||||||
.validateAddress(wallet.walletAddresses.address ?? ''),
|
// .validateAddress(wallet.walletAddresses.address ?? ''),
|
||||||
true);
|
// true);
|
||||||
} catch (_) {
|
// } catch (_) {
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
|
//
|
||||||
// Address validation
|
// // Address validation
|
||||||
expect(walletBase!.validateAddress(''), false);
|
// expect(walletBase!.validateAddress(''), false);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.validateAddress(
|
// walletBase!.validateAddress(
|
||||||
'Wo3jmHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmsEi'),
|
// 'Wo3jmHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmsEi'),
|
||||||
true);
|
// true);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.validateAddress(
|
// walletBase!.validateAddress(
|
||||||
'WasdfHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmjkl'),
|
// 'WasdfHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmjkl'),
|
||||||
false);
|
// false);
|
||||||
|
//
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
// TODO delete left over wallet file with name: name
|
// // TODO delete left over wallet file with name: name
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
group("Wownero 14 word seed restoration", () {
|
// group("Wownero 14 word seed restoration", () {
|
||||||
setUp(() async {
|
// setUp(() async {
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
name = 'namee${Random().nextInt(10000000)}';
|
// name = 'namee${Random().nextInt(10000000)}';
|
||||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
// final dirPath = await pathForWalletDir(name: name, type: type);
|
||||||
path = await pathForWallet(name: name, type: type);
|
// path = await pathForWallet(name: name, type: type);
|
||||||
credentials = wownero.createWowneroRestoreWalletFromSeedCredentials(
|
// credentials = wownero.createWowneroRestoreWalletFromSeedCredentials(
|
||||||
name: name,
|
// name: name,
|
||||||
height: 465760,
|
// height: 465760,
|
||||||
mnemonic: testMnemonic14); // TODO catch failure
|
// mnemonic: testMnemonic14); // TODO catch failure
|
||||||
|
//
|
||||||
walletInfo = WalletInfo.external(
|
// walletInfo = WalletInfo.external(
|
||||||
id: WalletBase.idFor(name, type),
|
// id: WalletBase.idFor(name, type),
|
||||||
name: name,
|
// name: name,
|
||||||
type: type,
|
// type: type,
|
||||||
isRecovery: false,
|
// isRecovery: false,
|
||||||
restoreHeight: credentials.height ?? 0,
|
// restoreHeight: credentials.height ?? 0,
|
||||||
date: DateTime.now(),
|
// date: DateTime.now(),
|
||||||
path: path,
|
// path: path,
|
||||||
address: "",
|
// address: "",
|
||||||
dirPath: dirPath);
|
// dirPath: dirPath);
|
||||||
credentials.walletInfo = walletInfo;
|
// credentials.walletInfo = walletInfo;
|
||||||
|
//
|
||||||
_walletCreationService = WalletCreationService(
|
// _walletCreationService = WalletCreationService(
|
||||||
secureStorage: storage,
|
// secureStorage: storage,
|
||||||
walletService: walletService,
|
// walletService: walletService,
|
||||||
keyService: keysStorage,
|
// keyService: keysStorage,
|
||||||
);
|
// );
|
||||||
_walletCreationService.changeWalletType();
|
// _walletCreationService.changeWalletType();
|
||||||
} catch (e, s) {
|
// } catch (e, s) {
|
||||||
print(e);
|
// print(e);
|
||||||
print(s);
|
// print(s);
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
test("Wownero 14 word seed address generation", () async {
|
// test("Wownero 14 word seed address generation", () async {
|
||||||
final wallet = await _walletCreationService.restoreFromSeed(credentials);
|
// final wallet = await _walletCreationService.restoreFromSeed(credentials);
|
||||||
walletInfo.address = wallet.walletAddresses.address;
|
// walletInfo.address = wallet.walletAddresses.address;
|
||||||
|
//
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
await _walletInfoSource.add(walletInfo);
|
// await _walletInfoSource.add(walletInfo);
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
|
//
|
||||||
expect(walletInfo.address, mainnetTestData14[0][0]);
|
// expect(walletInfo.address, mainnetTestData14[0][0]);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.getTransactionAddress(0, 0), mainnetTestData14[0][0]);
|
// walletBase!.getTransactionAddress(0, 0), mainnetTestData14[0][0]);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.getTransactionAddress(0, 1), mainnetTestData14[0][1]);
|
// walletBase!.getTransactionAddress(0, 1), mainnetTestData14[0][1]);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.getTransactionAddress(0, 2), mainnetTestData14[0][2]);
|
// walletBase!.getTransactionAddress(0, 2), mainnetTestData14[0][2]);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.getTransactionAddress(1, 0), mainnetTestData14[1][0]);
|
// walletBase!.getTransactionAddress(1, 0), mainnetTestData14[1][0]);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.getTransactionAddress(1, 1), mainnetTestData14[1][1]);
|
// walletBase!.getTransactionAddress(1, 1), mainnetTestData14[1][1]);
|
||||||
expect(
|
// expect(
|
||||||
walletBase!.getTransactionAddress(1, 2), mainnetTestData14[1][2]);
|
// walletBase!.getTransactionAddress(1, 2), mainnetTestData14[1][2]);
|
||||||
} catch (_) {
|
// } catch (_) {
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
|
//
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
// TODO delete left over wallet file with name: name
|
// // TODO delete left over wallet file with name: name
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
group("Wownero 25 word seed generation", () {
|
// group("Wownero 25 word seed generation", () {
|
||||||
setUp(() async {
|
// setUp(() async {
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
name = 'namee${Random().nextInt(10000000)}';
|
// name = 'namee${Random().nextInt(10000000)}';
|
||||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
// final dirPath = await pathForWalletDir(name: name, type: type);
|
||||||
path = await pathForWallet(name: name, type: type);
|
// path = await pathForWallet(name: name, type: type);
|
||||||
credentials = wownero.createWowneroNewWalletCredentials(
|
// credentials = wownero.createWowneroNewWalletCredentials(
|
||||||
name: name,
|
// name: name,
|
||||||
language: "English",
|
// language: "English",
|
||||||
seedWordsLength: 25); // TODO catch failure
|
// seedWordsLength: 25); // TODO catch failure
|
||||||
|
//
|
||||||
walletInfo = WalletInfo.external(
|
// walletInfo = WalletInfo.external(
|
||||||
id: WalletBase.idFor(name, type),
|
// id: WalletBase.idFor(name, type),
|
||||||
name: name,
|
// name: name,
|
||||||
type: type,
|
// type: type,
|
||||||
isRecovery: false,
|
// isRecovery: false,
|
||||||
restoreHeight: credentials.height ?? 0,
|
// restoreHeight: credentials.height ?? 0,
|
||||||
date: DateTime.now(),
|
// date: DateTime.now(),
|
||||||
path: path,
|
// path: path,
|
||||||
address: "",
|
// address: "",
|
||||||
dirPath: dirPath);
|
// dirPath: dirPath);
|
||||||
credentials.walletInfo = walletInfo;
|
// credentials.walletInfo = walletInfo;
|
||||||
|
//
|
||||||
_walletCreationService = WalletCreationService(
|
// _walletCreationService = WalletCreationService(
|
||||||
secureStorage: storage,
|
// secureStorage: storage,
|
||||||
walletService: walletService,
|
// walletService: walletService,
|
||||||
keyService: keysStorage,
|
// keyService: keysStorage,
|
||||||
);
|
// );
|
||||||
_walletCreationService.changeWalletType();
|
// _walletCreationService.changeWalletType();
|
||||||
} catch (e, s) {
|
// } catch (e, s) {
|
||||||
print(e);
|
// print(e);
|
||||||
print(s);
|
// print(s);
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
test("Wownero 25 word seed address generation", () async {
|
// test("Wownero 25 word seed address generation", () async {
|
||||||
final wallet = await _walletCreationService.create(credentials);
|
// final wallet = await _walletCreationService.create(credentials);
|
||||||
// TODO validate mnemonic
|
// // TODO validate mnemonic
|
||||||
walletInfo.address = wallet.walletAddresses.address;
|
// walletInfo.address = wallet.walletAddresses.address;
|
||||||
|
//
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
await _walletInfoSource.add(walletInfo);
|
// await _walletInfoSource.add(walletInfo);
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
|
//
|
||||||
// TODO validate
|
// // TODO validate
|
||||||
//expect(walletInfo.address, mainnetTestData14[0][0]);
|
// //expect(walletInfo.address, mainnetTestData14[0][0]);
|
||||||
} catch (_) {
|
// } catch (_) {
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
|
//
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
// TODO delete left over wallet file with name: name
|
// // TODO delete left over wallet file with name: name
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
group("Wownero 25 word seed restoration", () {
|
// group("Wownero 25 word seed restoration", () {
|
||||||
setUp(() async {
|
// setUp(() async {
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
name = 'namee${Random().nextInt(10000000)}';
|
// name = 'namee${Random().nextInt(10000000)}';
|
||||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
// final dirPath = await pathForWalletDir(name: name, type: type);
|
||||||
path = await pathForWallet(name: name, type: type);
|
// path = await pathForWallet(name: name, type: type);
|
||||||
credentials = wownero.createWowneroRestoreWalletFromSeedCredentials(
|
// credentials = wownero.createWowneroRestoreWalletFromSeedCredentials(
|
||||||
name: name,
|
// name: name,
|
||||||
height: 465760,
|
// height: 465760,
|
||||||
mnemonic: testMnemonic25); // TODO catch failure
|
// mnemonic: testMnemonic25); // TODO catch failure
|
||||||
|
//
|
||||||
walletInfo = WalletInfo.external(
|
// walletInfo = WalletInfo.external(
|
||||||
id: WalletBase.idFor(name, type),
|
// id: WalletBase.idFor(name, type),
|
||||||
name: name,
|
// name: name,
|
||||||
type: type,
|
// type: type,
|
||||||
isRecovery: false,
|
// isRecovery: false,
|
||||||
restoreHeight: credentials.height ?? 0,
|
// restoreHeight: credentials.height ?? 0,
|
||||||
date: DateTime.now(),
|
// date: DateTime.now(),
|
||||||
path: path,
|
// path: path,
|
||||||
address: "",
|
// address: "",
|
||||||
dirPath: dirPath);
|
// dirPath: dirPath);
|
||||||
credentials.walletInfo = walletInfo;
|
// credentials.walletInfo = walletInfo;
|
||||||
|
//
|
||||||
_walletCreationService = WalletCreationService(
|
// _walletCreationService = WalletCreationService(
|
||||||
secureStorage: storage,
|
// secureStorage: storage,
|
||||||
walletService: walletService,
|
// walletService: walletService,
|
||||||
keyService: keysStorage,
|
// keyService: keysStorage,
|
||||||
);
|
// );
|
||||||
_walletCreationService.changeWalletType();
|
// _walletCreationService.changeWalletType();
|
||||||
} catch (e, s) {
|
// } catch (e, s) {
|
||||||
print(e);
|
// print(e);
|
||||||
print(s);
|
// print(s);
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
test("Wownero 25 word seed address generation", () async {
|
// test("Wownero 25 word seed address generation", () async {
|
||||||
final wallet = await _walletCreationService.restoreFromSeed(credentials);
|
// final wallet = await _walletCreationService.restoreFromSeed(credentials);
|
||||||
walletInfo.address = wallet.walletAddresses.address;
|
// walletInfo.address = wallet.walletAddresses.address;
|
||||||
|
//
|
||||||
bool hasThrown = false;
|
// bool hasThrown = false;
|
||||||
try {
|
// try {
|
||||||
await _walletInfoSource.add(walletInfo);
|
// await _walletInfoSource.add(walletInfo);
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
|
//
|
||||||
expect(walletInfo.address, mainnetTestData25[0][0]);
|
// expect(walletInfo.address, mainnetTestData25[0][0]);
|
||||||
} catch (_) {
|
// } catch (_) {
|
||||||
hasThrown = true;
|
// hasThrown = true;
|
||||||
}
|
// }
|
||||||
expect(hasThrown, false);
|
// expect(hasThrown, false);
|
||||||
|
//
|
||||||
walletBase?.close();
|
// walletBase?.close();
|
||||||
walletBase = wallet as WowneroWalletBase;
|
// walletBase = wallet as WowneroWalletBase;
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
// TODO delete left over wallet file with name: name
|
// // TODO delete left over wallet file with name: name
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> pathForWalletDir(
|
// Future<String> pathForWalletDir(
|
||||||
{required String name, required WalletType type}) async {
|
// {required String name, required WalletType type}) async {
|
||||||
Directory root = (await getApplicationDocumentsDirectory());
|
// Directory root = (await getApplicationDocumentsDirectory());
|
||||||
if (Platform.isIOS) {
|
// if (Platform.isIOS) {
|
||||||
root = (await getLibraryDirectory());
|
// root = (await getLibraryDirectory());
|
||||||
}
|
// }
|
||||||
final prefix = walletTypeToString(type).toLowerCase();
|
// final prefix = walletTypeToString(type).toLowerCase();
|
||||||
final walletsDir = Directory('${root.path}/wallets');
|
// final walletsDir = Directory('${root.path}/wallets');
|
||||||
final walletDire = Directory('${walletsDir.path}/$prefix/$name');
|
// final walletDire = Directory('${walletsDir.path}/$prefix/$name');
|
||||||
|
//
|
||||||
if (!walletDire.existsSync()) {
|
// if (!walletDire.existsSync()) {
|
||||||
walletDire.createSync(recursive: true);
|
// walletDire.createSync(recursive: true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return walletDire.path;
|
// return walletDire.path;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future<String> pathForWallet(
|
// Future<String> pathForWallet(
|
||||||
{required String name, required WalletType type}) async =>
|
// {required String name, required WalletType type}) async =>
|
||||||
await pathForWalletDir(name: name, type: type)
|
// await pathForWalletDir(name: name, type: type)
|
||||||
.then((path) => '$path/$name');
|
// .then((path) => '$path/$name');
|
||||||
|
|
Loading…
Reference in a new issue