mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-22 11:29:23 +00:00
coin tests code error cleanup
This commit is contained in:
parent
35f6ffd4fc
commit
722a884553
7 changed files with 106 additions and 164 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -55,3 +55,4 @@ libcw_monero.dll
|
|||
libcw_wownero.dll
|
||||
libepic_cash_wallet.dll
|
||||
libmobileliblelantus.dll
|
||||
/libisar.so
|
||||
|
|
|
@ -8,9 +8,9 @@ import 'package:mockito/annotations.dart';
|
|||
import 'package:mockito/mockito.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/hive/db.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||
import 'package:stackwallet/models/paymint/utxo_model.dart';
|
||||
import 'package:stackwallet/services/coins/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:stackwallet/services/price.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -612,18 +612,6 @@ void main() async {
|
|||
if (!hiveAdaptersRegistered) {
|
||||
hiveAdaptersRegistered = true;
|
||||
|
||||
// Registering Transaction Model Adapters
|
||||
Hive.registerAdapter(TransactionDataAdapter());
|
||||
Hive.registerAdapter(TransactionChunkAdapter());
|
||||
Hive.registerAdapter(TransactionAdapter());
|
||||
Hive.registerAdapter(InputAdapter());
|
||||
Hive.registerAdapter(OutputAdapter());
|
||||
|
||||
// Registering Utxo Model Adapters
|
||||
Hive.registerAdapter(UtxoDataAdapter());
|
||||
Hive.registerAdapter(UtxoObjectAdapter());
|
||||
Hive.registerAdapter(StatusAdapter());
|
||||
|
||||
final wallets = await Hive.openBox<dynamic>('wallets');
|
||||
await wallets.put('currentWalletName', testWalletName);
|
||||
}
|
||||
|
@ -1295,50 +1283,48 @@ void main() async {
|
|||
//
|
||||
// });
|
||||
//
|
||||
// test("get utxos fails", () async {
|
||||
// btc = BitcoinWallet(
|
||||
// walletId: testWalletId,
|
||||
// walletName: testWalletName,
|
||||
// coin: Coin.bitcoinTestNet,
|
||||
// client: client!,
|
||||
// cachedClient: cachedClient!,
|
||||
// tracker: tracker!,
|
||||
//
|
||||
// secureStore: secureStore,
|
||||
// );
|
||||
// when(client?.ping()).thenAnswer((_) async => true);
|
||||
// when(client?.getServerFeatures()).thenAnswer((_) async => {
|
||||
// "hosts": <dynamic, dynamic>{},
|
||||
// "pruning": null,
|
||||
// "server_version": "Unit tests",
|
||||
// "protocol_min": "1.4",
|
||||
// "protocol_max": "1.4.2",
|
||||
// "genesis_hash": GENESIS_HASH_TESTNET,
|
||||
// "hash_function": "sha256",
|
||||
// "services": <dynamic>[]
|
||||
// });
|
||||
//
|
||||
// when(client?.getBatchUTXOs(args: anyNamed("args")))
|
||||
// .thenThrow(Exception("some exception"));
|
||||
//
|
||||
// await btc?.initializeWallet();
|
||||
// final utxoData = await btc?.utxoData;
|
||||
// expect(utxoData, isA<UtxoData>());
|
||||
// expect(utxoData.toString(),
|
||||
// r"{totalUserCurrency: $0.00, satoshiBalance: 0, bitcoinBalance: 0, unspentOutputArray: []}");
|
||||
//
|
||||
// final outputs = await btc?.unspentOutputs;
|
||||
// expect(outputs, isA<List<UtxoObject>>());
|
||||
// expect(outputs?.length, 0);
|
||||
//
|
||||
// verify(client?.ping()).called(1);
|
||||
// verify(client?.getServerFeatures()).called(1);
|
||||
// verify(client?.getBatchUTXOs(args: anyNamed("args"))).called(1);
|
||||
//
|
||||
// verifyNoMoreInteractions(client);
|
||||
// verifyNoMoreInteractions(cachedClient);
|
||||
//
|
||||
// });
|
||||
test("get utxos fails", () async {
|
||||
btc = BitcoinWallet(
|
||||
walletId: testWalletId,
|
||||
walletName: testWalletName,
|
||||
coin: Coin.bitcoinTestNet,
|
||||
client: client!,
|
||||
cachedClient: cachedClient!,
|
||||
tracker: tracker!,
|
||||
secureStore: secureStore,
|
||||
);
|
||||
when(client?.ping()).thenAnswer((_) async => true);
|
||||
when(client?.getServerFeatures()).thenAnswer((_) async => {
|
||||
"hosts": <dynamic, dynamic>{},
|
||||
"pruning": null,
|
||||
"server_version": "Unit tests",
|
||||
"protocol_min": "1.4",
|
||||
"protocol_max": "1.4.2",
|
||||
"genesis_hash": GENESIS_HASH_TESTNET,
|
||||
"hash_function": "sha256",
|
||||
"services": <dynamic>[]
|
||||
});
|
||||
|
||||
await Hive.openBox<dynamic>(testWalletId);
|
||||
await Hive.openBox<dynamic>(DB.boxNamePrefs);
|
||||
|
||||
when(client?.getBatchUTXOs(args: anyNamed("args")))
|
||||
.thenThrow(Exception("some exception"));
|
||||
|
||||
await btc?.initializeNew();
|
||||
await btc?.initializeExisting();
|
||||
|
||||
final outputs = await btc!.utxos;
|
||||
expect(outputs, isA<List<UTXO>>());
|
||||
expect(outputs.length, 0);
|
||||
|
||||
verify(client?.ping()).called(1);
|
||||
verify(client?.getServerFeatures()).called(1);
|
||||
verify(client?.getBatchUTXOs(args: anyNamed("args"))).called(1);
|
||||
|
||||
verifyNoMoreInteractions(client);
|
||||
verifyNoMoreInteractions(cachedClient);
|
||||
});
|
||||
//
|
||||
// test("chain height fetch, update, and get", () async {
|
||||
// btc = BitcoinWallet(
|
||||
|
|
|
@ -2,14 +2,14 @@ import 'package:decimal/decimal.dart';
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:hive_test/hive_test.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/hive/db.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||
import 'package:stackwallet/models/paymint/utxo_model.dart';
|
||||
import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart';
|
||||
import 'package:stackwallet/services/price.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -22,7 +22,9 @@ import 'bitcoincash_wallet_test_parameters.dart';
|
|||
|
||||
@GenerateMocks(
|
||||
[ElectrumX, CachedElectrumX, PriceAPI, TransactionNotificationTracker])
|
||||
void main() {
|
||||
void main() async {
|
||||
await Isar.initializeIsarCore(download: true);
|
||||
|
||||
group("bitcoincash constants", () {
|
||||
test("bitcoincash minimum confirmations", () async {
|
||||
expect(MINIMUM_CONFIRMATIONS, 1);
|
||||
|
@ -580,18 +582,6 @@ void main() {
|
|||
if (!hiveAdaptersRegistered) {
|
||||
hiveAdaptersRegistered = true;
|
||||
|
||||
// Registering Transaction Model Adapters
|
||||
Hive.registerAdapter(TransactionDataAdapter());
|
||||
Hive.registerAdapter(TransactionChunkAdapter());
|
||||
Hive.registerAdapter(TransactionAdapter());
|
||||
Hive.registerAdapter(InputAdapter());
|
||||
Hive.registerAdapter(OutputAdapter());
|
||||
|
||||
// Registering Utxo Model Adapters
|
||||
Hive.registerAdapter(UtxoDataAdapter());
|
||||
Hive.registerAdapter(UtxoObjectAdapter());
|
||||
Hive.registerAdapter(StatusAdapter());
|
||||
|
||||
final wallets = await Hive.openBox<dynamic>('wallets');
|
||||
await wallets.put('currentWalletName', testWalletName);
|
||||
}
|
||||
|
@ -1162,14 +1152,9 @@ void main() {
|
|||
await bch?.initializeNew();
|
||||
await bch?.initializeExisting();
|
||||
|
||||
final utxoData = await bch?.utxoData;
|
||||
expect(utxoData, isA<UtxoData>());
|
||||
expect(utxoData.toString(),
|
||||
r"{totalUserCurrency: 0.00, satoshiBalance: 0, bitcoinBalance: 0, unspentOutputArray: []}");
|
||||
|
||||
final outputs = await bch?.unspentOutputs;
|
||||
expect(outputs, isA<List<UtxoObject>>());
|
||||
expect(outputs?.length, 0);
|
||||
final outputs = await bch!.utxos;
|
||||
expect(outputs, isA<List<UTXO>>());
|
||||
expect(outputs.length, 0);
|
||||
|
||||
verifyNever(client?.ping()).called(0);
|
||||
verify(client?.getServerFeatures()).called(1);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// import 'dart:typed_data';
|
||||
|
||||
import 'package:bitcoindart/bitcoindart.dart';
|
||||
import 'package:decimal/decimal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -10,9 +8,8 @@ import 'package:mockito/mockito.dart';
|
|||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/hive/db.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||
import 'package:stackwallet/models/paymint/utxo_model.dart';
|
||||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||
import 'package:stackwallet/services/price.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -473,18 +470,6 @@ void main() {
|
|||
if (!hiveAdaptersRegistered) {
|
||||
hiveAdaptersRegistered = true;
|
||||
|
||||
// Registering Transaction Model Adapters
|
||||
Hive.registerAdapter(TransactionDataAdapter());
|
||||
Hive.registerAdapter(TransactionChunkAdapter());
|
||||
Hive.registerAdapter(TransactionAdapter());
|
||||
Hive.registerAdapter(InputAdapter());
|
||||
Hive.registerAdapter(OutputAdapter());
|
||||
|
||||
// Registering Utxo Model Adapters
|
||||
Hive.registerAdapter(UtxoDataAdapter());
|
||||
Hive.registerAdapter(UtxoObjectAdapter());
|
||||
Hive.registerAdapter(StatusAdapter());
|
||||
|
||||
final wallets = await Hive.openBox<dynamic>('wallets');
|
||||
await wallets.put('currentWalletName', testWalletName);
|
||||
}
|
||||
|
@ -1064,14 +1049,9 @@ void main() {
|
|||
await doge?.initializeNew();
|
||||
await doge?.initializeExisting();
|
||||
|
||||
final utxoData = await doge?.utxoData;
|
||||
expect(utxoData, isA<UtxoData>());
|
||||
expect(utxoData.toString(),
|
||||
r"{totalUserCurrency: 0.00, satoshiBalance: 0, bitcoinBalance: 0, unspentOutputArray: []}");
|
||||
|
||||
final outputs = await doge?.unspentOutputs;
|
||||
expect(outputs, isA<List<UtxoObject>>());
|
||||
expect(outputs?.length, 0);
|
||||
final outputs = await doge!.utxos;
|
||||
expect(outputs, isA<List<UTXO>>());
|
||||
expect(outputs.length, 0);
|
||||
|
||||
verifyNever(client?.ping()).called(0);
|
||||
verify(client?.getServerFeatures()).called(1);
|
||||
|
|
|
@ -11,7 +11,11 @@ import 'package:mockito/annotations.dart';
|
|||
import 'package:mockito/mockito.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/models/models.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
||||
import 'package:stackwallet/models/lelantus_coin.dart';
|
||||
import 'package:stackwallet/models/lelantus_fee_data.dart';
|
||||
import 'package:stackwallet/models/paymint/transactions_model.dart' as old;
|
||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/services/price.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -41,7 +45,7 @@ void main() {
|
|||
|
||||
test("isolateRestore success", () async {
|
||||
final cachedClient = MockCachedElectrumX();
|
||||
final txData = TransactionData.fromJson(dateTimeChunksJson);
|
||||
final txDataOLD = old.TransactionData.fromJson(dateTimeChunksJson);
|
||||
final Map<dynamic, dynamic> setData = {};
|
||||
setData[1] = GetAnonymitySetSampleData.data;
|
||||
final usedSerials = GetUsedSerialsSampleData.serials["serials"] as List;
|
||||
|
@ -74,6 +78,34 @@ void main() {
|
|||
firoNetwork,
|
||||
);
|
||||
const currentHeight = 100000000000;
|
||||
|
||||
final txData = txDataOLD
|
||||
.getAllTransactions()
|
||||
.values
|
||||
.map(
|
||||
(t) => Transaction(
|
||||
walletId: "walletId",
|
||||
txid: t.txid,
|
||||
timestamp: t.timestamp,
|
||||
type: t.txType == "Sent"
|
||||
? TransactionType.outgoing
|
||||
: TransactionType.incoming,
|
||||
subType: t.subType == "mint"
|
||||
? TransactionSubType.mint
|
||||
: t.subType == "join"
|
||||
? TransactionSubType.join
|
||||
: TransactionSubType.none,
|
||||
amount: t.amount,
|
||||
fee: t.fees,
|
||||
height: t.height,
|
||||
isCancelled: t.isCancelled,
|
||||
isLelantus: null,
|
||||
slateId: t.slateId,
|
||||
otherData: t.otherData,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
final result = await staticProcessRestore(txData, message, currentHeight);
|
||||
|
||||
expect(result, isA<Map<String, dynamic>>());
|
||||
|
@ -512,18 +544,6 @@ void main() {
|
|||
if (!hiveAdaptersRegistered) {
|
||||
hiveAdaptersRegistered = true;
|
||||
|
||||
// Registering Transaction Model Adapters
|
||||
Hive.registerAdapter(TransactionDataAdapter());
|
||||
Hive.registerAdapter(TransactionChunkAdapter());
|
||||
Hive.registerAdapter(TransactionAdapter());
|
||||
Hive.registerAdapter(InputAdapter());
|
||||
Hive.registerAdapter(OutputAdapter());
|
||||
|
||||
// Registering Utxo Model Adapters
|
||||
Hive.registerAdapter(UtxoDataAdapter());
|
||||
Hive.registerAdapter(UtxoObjectAdapter());
|
||||
Hive.registerAdapter(StatusAdapter());
|
||||
|
||||
// Registering Lelantus Model Adapters
|
||||
Hive.registerAdapter(LelantusCoinAdapter());
|
||||
}
|
||||
|
@ -1181,21 +1201,19 @@ void main() {
|
|||
const MethodChannel('uk.spiralarm.flutter/devicelocale')
|
||||
.setMockMethodCallHandler((methodCall) async => 'en_US');
|
||||
|
||||
List<UtxoObject> utxos = [
|
||||
UtxoObject(
|
||||
List<UTXO> utxos = [
|
||||
UTXO(
|
||||
txid: BuildMintTxTestParams.utxoInfo["txid"] as String,
|
||||
vout: BuildMintTxTestParams.utxoInfo["vout"] as int,
|
||||
value: BuildMintTxTestParams.utxoInfo["value"] as int,
|
||||
txName: '',
|
||||
status: Status(
|
||||
confirmed: false,
|
||||
blockHash: "",
|
||||
blockHeight: -1,
|
||||
blockTime: 42,
|
||||
confirmations: 0),
|
||||
isCoinbase: false,
|
||||
blocked: false,
|
||||
fiatWorth: '',
|
||||
walletId: '',
|
||||
name: '',
|
||||
isBlocked: false,
|
||||
blockedReason: '',
|
||||
blockHash: '',
|
||||
blockHeight: -1,
|
||||
blockTime: 42,
|
||||
)
|
||||
];
|
||||
const sats = 9658;
|
||||
|
@ -3023,7 +3041,7 @@ void main() {
|
|||
expect(firo.balance.getTotal(), Decimal.parse("0.00021594"));
|
||||
});
|
||||
|
||||
test("get transactionData", () async {
|
||||
test("get transactions", () async {
|
||||
final client = MockElectrumX();
|
||||
final cachedClient = MockCachedElectrumX();
|
||||
final secureStore = FakeSecureStorage();
|
||||
|
@ -3118,9 +3136,9 @@ void main() {
|
|||
'receivingAddresses', RefreshTestParams.receivingAddresses);
|
||||
await wallet.put('changeAddresses', RefreshTestParams.changeAddresses);
|
||||
|
||||
final txData = await firo.transactionData;
|
||||
final txData = await firo.transactions;
|
||||
|
||||
expect(txData, isA<TransactionData>());
|
||||
expect(txData, isA<List<Transaction>>());
|
||||
|
||||
// kill timer and listener
|
||||
await firo.exit();
|
||||
|
|
|
@ -8,8 +8,6 @@ import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
|||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/hive/db.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||
import 'package:stackwallet/models/paymint/utxo_model.dart';
|
||||
import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart';
|
||||
import 'package:stackwallet/services/price.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -18,7 +16,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
|
||||
import 'namecoin_history_sample_data.dart';
|
||||
import 'namecoin_transaction_data_samples.dart';
|
||||
import 'namecoin_utxo_sample_data.dart';
|
||||
import 'namecoin_wallet_test.mocks.dart';
|
||||
import 'namecoin_wallet_test_parameters.dart';
|
||||
|
||||
|
@ -442,18 +439,6 @@ void main() {
|
|||
if (!hiveAdaptersRegistered) {
|
||||
hiveAdaptersRegistered = true;
|
||||
|
||||
// Registering Transaction Model Adapters
|
||||
Hive.registerAdapter(TransactionDataAdapter());
|
||||
Hive.registerAdapter(TransactionChunkAdapter());
|
||||
Hive.registerAdapter(TransactionAdapter());
|
||||
Hive.registerAdapter(InputAdapter());
|
||||
Hive.registerAdapter(OutputAdapter());
|
||||
|
||||
// Registering Utxo Model Adapters
|
||||
Hive.registerAdapter(UtxoDataAdapter());
|
||||
Hive.registerAdapter(UtxoObjectAdapter());
|
||||
Hive.registerAdapter(StatusAdapter());
|
||||
|
||||
final wallets = await Hive.openBox<dynamic>('wallets');
|
||||
await wallets.put('currentWalletName', testWalletName);
|
||||
}
|
||||
|
@ -1354,7 +1339,7 @@ void main() {
|
|||
"bc1qggtj4ka8jsaj44hhd5mpamx7mp34m2d3w7k0m0",
|
||||
"bc1q42lja79elem0anu8q8s3h2n687re9jax556pcc"));
|
||||
|
||||
nmc?.outputsList = utxoList;
|
||||
// nmc?.outputsList = utxoList;
|
||||
|
||||
bool didThrow = false;
|
||||
try {
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:mockito/annotations.dart';
|
|||
import 'package:mockito/mockito.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/models/models.dart';
|
||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||
import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
|
||||
import 'package:stackwallet/services/price.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
|
@ -15,7 +15,6 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|||
|
||||
import 'particl_history_sample_data.dart';
|
||||
import 'particl_transaction_data_samples.dart';
|
||||
import 'particl_utxo_sample_data.dart';
|
||||
import 'particl_wallet_test.mocks.dart';
|
||||
import 'particl_wallet_test_parameters.dart';
|
||||
|
||||
|
@ -489,18 +488,6 @@ void main() {
|
|||
if (!hiveAdaptersRegistered) {
|
||||
hiveAdaptersRegistered = true;
|
||||
|
||||
// Registering Transaction Model Adapters
|
||||
Hive.registerAdapter(TransactionDataAdapter());
|
||||
Hive.registerAdapter(TransactionChunkAdapter());
|
||||
Hive.registerAdapter(TransactionAdapter());
|
||||
Hive.registerAdapter(InputAdapter());
|
||||
Hive.registerAdapter(OutputAdapter());
|
||||
|
||||
// Registering Utxo Model Adapters
|
||||
Hive.registerAdapter(UtxoDataAdapter());
|
||||
Hive.registerAdapter(UtxoObjectAdapter());
|
||||
Hive.registerAdapter(StatusAdapter());
|
||||
|
||||
final wallets = await Hive.openBox<dynamic>('wallets');
|
||||
await wallets.put('currentWalletName', testWalletName);
|
||||
}
|
||||
|
@ -1282,7 +1269,7 @@ void main() {
|
|||
"pw1qvr6ehcm44vvqe96mxy9zw9aa5sa5yezvr2r94s",
|
||||
"pw1q66xtkhqzcue808nlg8tp48uq7fshmaddljtkpy"));
|
||||
|
||||
part?.outputsList = utxoList;
|
||||
// part?.outputsList = utxoList;
|
||||
|
||||
bool didThrow = false;
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue