mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
* feat: add exodus style bip39 to monero legacy seed * feat: restore monero wallet from bip39 and add test * bug: fix wrong naming in CI * feat: add monero bip39 UI flow * fix: monero.dart generation * fix: skip monero_wallet_service tests till CI is fixed * ci: copy monero_libwallet2_api_c.so to /usr/lib for testing ci: reduce timeout for cw_monero tests * fix: monero wallet creation credentials default to bip39 if mnemonic are set * fix: do not skip monero wallets services test * fix: Include non bip39 monero wallets on Wallet Group * fix: null pointer stemming from missing language selector if seed is selected * fix: Fixes to Bip39 Creation and restore - Do not restore from 0 for fresh bip39 wallet - disallow restoring bip39 wallet without date or height * fix: Fixes to Bip39 restore - Refresh height is now getting set correctly - Add new create monero wallet tests - Add seed-language English for Bip39 Monero wallets - Fix seed-type naming * feat (cw_monero): Store monero wallet after bip39 creation * feat (cw_monero): remove prints from monero_wallet_service_test.dart * fix: exception during seed language autodetect * feat (cw_monero): Add support for passphrases on bip39 seeds * feat (cw_monero): Add support for passphrases on bip39 seeds * fix: seed language selection for recovering bip39 wallets * style: improve readability of isLegacySeedOnly in wallet_keys_view_model.dart * feat: hide monero seed type selector from advanced settings when creating a child wallet * fix(cw_monero): use named arguments for bip39_seed tests --------- Co-authored-by: cyan <cyjan@mrcyjanek.net>
148 lines
4.8 KiB
Dart
148 lines
4.8 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:cw_core/unspent_coins_info.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:cw_core/wallet_info.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cw_monero/monero_wallet_service.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hive/hive.dart';
|
|
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
|
|
|
|
import 'mock/path_provider.dart';
|
|
import 'utils/setup_monero_c.dart';
|
|
|
|
Future<void> main() async {
|
|
group("MoneroWalletService Tests", () {
|
|
Hive.init('./test/data/db');
|
|
late MoneroWalletService walletService;
|
|
late File moneroCBinary;
|
|
|
|
setUpAll(() async {
|
|
PathProviderPlatform.instance = MockPathProviderPlatform();
|
|
|
|
final Box<WalletInfo> walletInfoSource =
|
|
await Hive.openBox('testWalletInfo');
|
|
final Box<UnspentCoinsInfo> unspentCoinsInfoSource =
|
|
await Hive.openBox('testUnspentCoinsInfo');
|
|
|
|
walletService = MoneroWalletService(walletInfoSource, unspentCoinsInfoSource);
|
|
moneroCBinary = getMoneroCBinary().copySync(moneroCBinaryName);
|
|
});
|
|
|
|
tearDownAll(() {
|
|
Directory('./test/data').deleteSync(recursive: true);
|
|
moneroCBinary.deleteSync();
|
|
});
|
|
|
|
group("Create wallet", () {
|
|
test("Create Legacy Wallet", () async {
|
|
final credentials = _getTestCreateCredentials(
|
|
name: 'Create Wallet LS',
|
|
language: 'English',
|
|
seedType: MoneroSeedType.legacy);
|
|
final wallet = await walletService.create(credentials);
|
|
|
|
expect(wallet.seed.split(" ").length, 25);
|
|
expect(wallet.restoreHeight, greaterThan(3000000));
|
|
});
|
|
|
|
test("Create Polyseed Wallet", () async {
|
|
final credentials = _getTestCreateCredentials(
|
|
name: 'Create Wallet PS',
|
|
language: 'English',
|
|
seedType: MoneroSeedType.polyseed);
|
|
final wallet = await walletService.create(credentials);
|
|
|
|
expect(wallet.seed.split(" ").length, 16);
|
|
expect(wallet.restoreHeight, greaterThan(3000000));
|
|
});
|
|
|
|
test("Create Bip39 Wallet", () async {
|
|
final credentials = _getTestCreateCredentials(
|
|
name: 'Create Wallet BS',
|
|
language: 'English',
|
|
seedType: MoneroSeedType.bip39);
|
|
final wallet = await walletService.create(credentials);
|
|
|
|
expect(wallet.seed.split(" ").length, 12);
|
|
expect(wallet.restoreHeight, greaterThan(3000000));
|
|
});
|
|
});
|
|
|
|
group("Restore wallet", () {
|
|
test('Legacy Seed', () async {
|
|
final credentials = _getTestRestoreCredentials(
|
|
name: 'Test Wallet LS',
|
|
mnemonic:
|
|
'ability pockets lordship tomorrow gypsy match neutral uncle avatar betting bicycle junk unzip pyramid lynx mammal edgy empty uneven knowledge juvenile wiring paradise psychic betting',
|
|
);
|
|
|
|
final wallet = await walletService.restoreFromSeed(credentials);
|
|
expect(wallet.walletAddresses.primaryAddress,
|
|
'48tLyQXpcwt8w6uKHyb5Zs3vdnoDWAEKFQr1c198o7aX9dBzXP3BTSMVsDiuH3ozDCNqwojb4vNeQZf7xg6URimDLaNtGSN');
|
|
});
|
|
|
|
test('Bip39 Seed', () async {
|
|
final credentials = _getTestRestoreCredentials(
|
|
name: 'Test Wallet BS',
|
|
mnemonic:
|
|
'color ranch color remove subway public water embrace before begin liberty fault');
|
|
|
|
final wallet = await walletService.restoreFromSeed(credentials);
|
|
expect(wallet.walletAddresses.primaryAddress,
|
|
'49MggvPosJugF8Zq7WAKbsSchz6vbyL6YiUxM4ryfGQDXphs6wiWiXLFWCSshnLPcceGTWUaKfWWMHQAAKESV3TQJVQsL9a');
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
MoneroRestoreWalletFromSeedCredentials _getTestRestoreCredentials({
|
|
required String name,
|
|
required String mnemonic,
|
|
}) {
|
|
final credentials = MoneroRestoreWalletFromSeedCredentials(
|
|
name: name, mnemonic: mnemonic, passphrase: '', password: "test");
|
|
|
|
credentials.walletInfo = WalletInfo.external(
|
|
id: WalletBase.idFor(name, WalletType.monero),
|
|
name: name,
|
|
type: WalletType.monero,
|
|
isRecovery: true,
|
|
restoreHeight: credentials.height ?? 0,
|
|
date: DateTime.now(),
|
|
path: '',
|
|
dirPath: '',
|
|
address: '',
|
|
);
|
|
return credentials;
|
|
}
|
|
|
|
MoneroNewWalletCredentials _getTestCreateCredentials({
|
|
required String name,
|
|
required String language,
|
|
required MoneroSeedType seedType,
|
|
String? mnemonic,
|
|
}) {
|
|
final credentials = MoneroNewWalletCredentials(
|
|
name: name,
|
|
language: language,
|
|
seedType: seedType,
|
|
password: "test",
|
|
mnemonic: mnemonic,
|
|
passphrase: '',
|
|
);
|
|
|
|
credentials.walletInfo = WalletInfo.external(
|
|
id: WalletBase.idFor(name, WalletType.monero),
|
|
name: name,
|
|
type: WalletType.monero,
|
|
isRecovery: false,
|
|
restoreHeight: credentials.height ?? 0,
|
|
date: DateTime.now(),
|
|
path: '',
|
|
dirPath: '',
|
|
address: '',
|
|
);
|
|
return credentials;
|
|
}
|