mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
Add Wownero mainnet wallet address generation test
This commit is contained in:
parent
b6e51cb954
commit
c2aeb5bae8
2 changed files with 178 additions and 0 deletions
164
test/services/coins/wownero/wownero_wallet_test.dart
Normal file
164
test/services/coins/wownero/wownero_wallet_test.dart
Normal file
|
@ -0,0 +1,164 @@
|
|||
import 'dart:async';
|
||||
import 'dart:core';
|
||||
import 'dart:core' as core;
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:hive_test/hive_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'package:cw_core/monero_amount_format.dart';
|
||||
import 'package:cw_core/node.dart';
|
||||
import 'package:cw_core/pending_transaction.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/wallet_credentials.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
import 'package:cw_core/wallet_service.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:cw_wownero/api/wallet.dart';
|
||||
import 'package:cw_wownero/pending_wownero_transaction.dart';
|
||||
import 'package:cw_wownero/wownero_wallet.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_libmonero/core/key_service.dart';
|
||||
import 'package:flutter_libmonero/core/wallet_creation_service.dart';
|
||||
import 'package:flutter_libmonero/view_model/send/output.dart';
|
||||
import 'package:flutter_libmonero/wownero/wownero.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'wownero_wallet_test_data.dart';
|
||||
|
||||
FakeSecureStorage? storage;
|
||||
WalletService? walletService;
|
||||
SharedPreferences? prefs;
|
||||
KeyService? keysStorage;
|
||||
WowneroWalletBase? walletBase;
|
||||
late WalletCreationService _walletCreationService;
|
||||
dynamic _walletInfoSource;
|
||||
|
||||
String path = '';
|
||||
|
||||
String name = 'namee${Random().nextInt(10000000)}';
|
||||
int nettype = 0;
|
||||
WalletType type = WalletType.wownero;
|
||||
|
||||
@GenerateMocks([])
|
||||
void main() async {
|
||||
storage = FakeSecureStorage();
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
keysStorage = KeyService(storage!);
|
||||
WalletInfo walletInfo = WalletInfo.external(
|
||||
id: '',
|
||||
name: '',
|
||||
type: type,
|
||||
isRecovery: false,
|
||||
restoreHeight: 0,
|
||||
date: DateTime.now(),
|
||||
path: '',
|
||||
address: '',
|
||||
dirPath: '');
|
||||
late WalletCredentials credentials;
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
Directory appDir = (await getApplicationDocumentsDirectory());
|
||||
if (Platform.isIOS) {
|
||||
appDir = (await getLibraryDirectory());
|
||||
}
|
||||
await Hive.close();
|
||||
Hive.init(appDir.path);
|
||||
Hive.registerAdapter(NodeAdapter());
|
||||
Hive.registerAdapter(WalletInfoAdapter());
|
||||
Hive.registerAdapter(WalletTypeAdapter());
|
||||
Hive.registerAdapter(UnspentCoinsInfoAdapter());
|
||||
|
||||
wownero.onStartup();
|
||||
_walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
||||
walletService = wownero.createWowneroWalletService(_walletInfoSource);
|
||||
|
||||
group("Wownero tests", () {
|
||||
setUp(() async {
|
||||
try {
|
||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
||||
path = await pathForWallet(name: name, type: type);
|
||||
credentials = wownero.createWowneroRestoreWalletFromSeedCredentials(
|
||||
name: name, height: 465760, mnemonic: testMnemonic);
|
||||
|
||||
walletInfo = WalletInfo.external(
|
||||
id: WalletBase.idFor(name, type),
|
||||
name: name,
|
||||
type: type,
|
||||
isRecovery: false,
|
||||
restoreHeight: credentials.height ?? 0,
|
||||
date: DateTime.now(),
|
||||
path: path,
|
||||
address: "",
|
||||
dirPath: dirPath);
|
||||
credentials.walletInfo = walletInfo;
|
||||
|
||||
_walletCreationService = WalletCreationService(
|
||||
secureStorage: storage,
|
||||
sharedPreferences: prefs,
|
||||
walletService: walletService,
|
||||
keyService: keysStorage,
|
||||
);
|
||||
_walletCreationService.changeWalletType();
|
||||
} catch (e, s) {
|
||||
print(e);
|
||||
print(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("Test mainnet address generation from seed", () async {
|
||||
final wallet = await _walletCreationService.restoreFromSeed(credentials);
|
||||
walletInfo.address = wallet.walletAddresses.address;
|
||||
|
||||
await _walletInfoSource.add(walletInfo);
|
||||
walletBase?.close();
|
||||
walletBase = wallet as WowneroWalletBase;
|
||||
|
||||
expect(walletInfo.address, mainnetTestData[0][0]);
|
||||
expect(
|
||||
await walletBase!.getTransactionAddress(0, 0), mainnetTestData[0][0]);
|
||||
expect(
|
||||
await walletBase!.getTransactionAddress(0, 1), mainnetTestData[0][1]);
|
||||
expect(
|
||||
await walletBase!.getTransactionAddress(0, 2), mainnetTestData[0][2]);
|
||||
expect(
|
||||
await walletBase!.getTransactionAddress(1, 0), mainnetTestData[1][0]);
|
||||
expect(
|
||||
await walletBase!.getTransactionAddress(1, 1), mainnetTestData[1][1]);
|
||||
expect(
|
||||
await walletBase!.getTransactionAddress(1, 2), mainnetTestData[1][2]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<String> pathForWalletDir(
|
||||
{required String name, required WalletType type}) async {
|
||||
Directory root = (await getApplicationDocumentsDirectory());
|
||||
if (Platform.isIOS) {
|
||||
root = (await getLibraryDirectory());
|
||||
}
|
||||
final prefix = walletTypeToString(type).toLowerCase();
|
||||
final walletsDir = Directory('${root.path}/wallets');
|
||||
final walletDire = Directory('${walletsDir.path}/$prefix/$name');
|
||||
|
||||
if (!walletDire.existsSync()) {
|
||||
walletDire.createSync(recursive: true);
|
||||
}
|
||||
|
||||
return walletDire.path;
|
||||
}
|
||||
|
||||
Future<String> pathForWallet(
|
||||
{required String name, required WalletType type}) async =>
|
||||
await pathForWalletDir(name: name, type: type)
|
||||
.then((path) => path + '/$name');
|
14
test/services/coins/wownero/wownero_wallet_test_data.dart
Normal file
14
test/services/coins/wownero/wownero_wallet_test_data.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
String testMnemonic =
|
||||
'weather cruise school such silly profit clerk wage reduce obtain ill sand episode shadow';
|
||||
var mainnetTestData = [
|
||||
[
|
||||
'Wo3jmHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmsEi',
|
||||
'WW3K54QzmMFB1uTZh3LVvgQYqANLmX1FkJHLJ4sU1E7BQmp8nGizyBnjNXSgsjCa4BQ3Rw3GG5jw1ByUkaUjSywm2KmHAbFvK',
|
||||
'WW3e3F51KAojcSW2G5WimmE1WVFsbBHc6HppZFBa6dNiEn21cThXzdGGDbpv89aTKXSRSPSFaetK6HgCozYawaYz2knUi9Hmn'
|
||||
],
|
||||
[
|
||||
'WW2nx7MFruyN2CcXnGnMbDdvqsyZUGQthLWKYPkQ4iM9XCE54RyWVjNjgopryUbyi9WKzYhHDai2wENbh1Jh1UHa28CL72TYt',
|
||||
'WW34p57QBMoD6MEZVTu5u9R7G3KeYqvN4eYbvHLYsgbWXpLe992fBvVB7ANJNvaGmPg2uwY5oKjwKbpo4fDU6cGS231PmvXrZ',
|
||||
'WW2KQLLt6gjC9gRsC4NGehbAZX6UPU7sK89UQFwSg3NKj3MXPwnjh5BiJVqYYNQb6JNsfa7oP7eDjLagtLa2H6YP11RhUNQqw'
|
||||
]
|
||||
];
|
Loading…
Reference in a new issue