mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-18 16:44:32 +00:00
fix manager tests and update fakecoinservice
This commit is contained in:
parent
686c897515
commit
e248a6fd77
2 changed files with 57 additions and 117 deletions
|
@ -1,19 +1,11 @@
|
||||||
import 'package:decimal/decimal.dart';
|
import 'package:stackwallet/models/balance.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/paymint/fee_object_model.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/coin_service.dart';
|
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
|
||||||
class FakeCoinServiceAPI extends CoinServiceAPI {
|
class FakeCoinServiceAPI extends CoinServiceAPI {
|
||||||
@override
|
|
||||||
// TODO: implement allOwnAddresses
|
|
||||||
Future<List<String>> get allOwnAddresses => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement balanceMinusMaxFee
|
|
||||||
Future<Decimal> get balanceMinusMaxFee => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement currentReceivingAddress
|
// TODO: implement currentReceivingAddress
|
||||||
Future<String> get currentReceivingAddress => throw UnimplementedError();
|
Future<String> get currentReceivingAddress => throw UnimplementedError();
|
||||||
|
@ -32,24 +24,12 @@ class FakeCoinServiceAPI extends CoinServiceAPI {
|
||||||
// TODO: implement mnemonic
|
// TODO: implement mnemonic
|
||||||
Future<List<String>> get mnemonic => throw UnimplementedError();
|
Future<List<String>> get mnemonic => throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement pendingBalance
|
|
||||||
Future<Decimal> get pendingBalance => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> refresh() {
|
Future<void> refresh() {
|
||||||
// TODO: implement refresh
|
// TODO: implement refresh
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement totalBalance
|
|
||||||
Future<Decimal> get totalBalance => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement transactionData
|
|
||||||
Future<TransactionData> get transactionData => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool validateAddress(String address) {
|
bool validateAddress(String address) {
|
||||||
// TODO: implement validateAddress
|
// TODO: implement validateAddress
|
||||||
|
@ -71,10 +51,6 @@ class FakeCoinServiceAPI extends CoinServiceAPI {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement unspentOutputs
|
|
||||||
Future<List<UtxoObject>> get unspentOutputs => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get isFavorite => throw UnimplementedError();
|
bool get isFavorite => throw UnimplementedError();
|
||||||
|
|
||||||
|
@ -84,10 +60,6 @@ class FakeCoinServiceAPI extends CoinServiceAPI {
|
||||||
@override
|
@override
|
||||||
late bool shouldAutoSync;
|
late bool shouldAutoSync;
|
||||||
|
|
||||||
@override
|
|
||||||
// TODO: implement availableBalance
|
|
||||||
Future<Decimal> get availableBalance => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement coin
|
// TODO: implement coin
|
||||||
Coin get coin => throw UnimplementedError();
|
Coin get coin => throw UnimplementedError();
|
||||||
|
@ -162,15 +134,6 @@ class FakeCoinServiceAPI extends CoinServiceAPI {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<String> send(
|
|
||||||
{required String toAddress,
|
|
||||||
required int amount,
|
|
||||||
Map<String, String> args = const {}}) {
|
|
||||||
// TODO: implement send
|
|
||||||
throw UnimplementedError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> testNetworkConnection() {
|
Future<bool> testNetworkConnection() {
|
||||||
// TODO: implement testNetworkConnection
|
// TODO: implement testNetworkConnection
|
||||||
|
@ -188,4 +151,20 @@ class FakeCoinServiceAPI extends CoinServiceAPI {
|
||||||
// TODO: implement updateSentCachedTxData
|
// TODO: implement updateSentCachedTxData
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement balance
|
||||||
|
Balance get balance => throw UnimplementedError();
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement storedChainHeight
|
||||||
|
int get storedChainHeight => throw UnimplementedError();
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement transactions
|
||||||
|
Future<List<Transaction>> get transactions => throw UnimplementedError();
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement utxos
|
||||||
|
Future<List<UTXO>> get utxos => throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import 'package:decimal/decimal.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:mockito/annotations.dart';
|
import 'package:mockito/annotations.dart';
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:mockito/mockito.dart';
|
||||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||||
import 'package:stackwallet/models/models.dart';
|
import 'package:stackwallet/models/balance.dart';
|
||||||
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||||
|
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||||
import 'package:stackwallet/services/coins/coin_service.dart';
|
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/manager.dart';
|
import 'package:stackwallet/services/coins/manager.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
|
||||||
import 'firo/sample_data/transaction_data_samples.dart';
|
|
||||||
import 'manager_test.mocks.dart';
|
import 'manager_test.mocks.dart';
|
||||||
|
|
||||||
@GenerateMocks([FiroWallet, ElectrumX])
|
@GenerateMocks([FiroWallet, ElectrumX])
|
||||||
|
@ -28,30 +28,6 @@ void main() {
|
||||||
expect(manager.coin, Coin.firo);
|
expect(manager.coin, Coin.firo);
|
||||||
});
|
});
|
||||||
|
|
||||||
group("send", () {
|
|
||||||
test("successful send", () async {
|
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
|
||||||
when(wallet.send(toAddress: "some address", amount: 1987634))
|
|
||||||
.thenAnswer((_) async => "some txid");
|
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
|
||||||
|
|
||||||
expect(await manager.send(toAddress: "some address", amount: 1987634),
|
|
||||||
"some txid");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("failed send", () {
|
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
|
||||||
when(wallet.send(toAddress: "some address", amount: 1987634))
|
|
||||||
.thenThrow(Exception("Tx failed!"));
|
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
|
||||||
|
|
||||||
expect(() => manager.send(toAddress: "some address", amount: 1987634),
|
|
||||||
throwsA(isA<Exception>()));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("fees", () async {
|
test("fees", () async {
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
final CoinServiceAPI wallet = MockFiroWallet();
|
||||||
when(wallet.fees).thenAnswer((_) async => FeeObject(
|
when(wallet.fees).thenAnswer((_) async => FeeObject(
|
||||||
|
@ -98,68 +74,53 @@ void main() {
|
||||||
group("get balances", () {
|
group("get balances", () {
|
||||||
test("balance", () async {
|
test("balance", () async {
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
final CoinServiceAPI wallet = MockFiroWallet();
|
||||||
when(wallet.availableBalance).thenAnswer((_) async => Decimal.ten);
|
when(wallet.balance).thenAnswer(
|
||||||
|
(_) => Balance(
|
||||||
|
coin: Coin.firo,
|
||||||
|
total: 10,
|
||||||
|
spendable: 1,
|
||||||
|
blockedTotal: 0,
|
||||||
|
pendingSpendable: 9,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
final manager = Manager(wallet);
|
||||||
|
|
||||||
expect(await manager.availableBalance, Decimal.ten);
|
expect(manager.balance.coin, Coin.firo);
|
||||||
});
|
expect(manager.balance.total, 10);
|
||||||
|
expect(manager.balance.spendable, 1);
|
||||||
test("pendingBalance", () async {
|
expect(manager.balance.blockedTotal, 0);
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
expect(manager.balance.pendingSpendable, 9);
|
||||||
when(wallet.pendingBalance).thenAnswer((_) async => Decimal.fromInt(23));
|
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
|
||||||
|
|
||||||
expect(await manager.pendingBalance, Decimal.fromInt(23));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("totalBalance", () async {
|
|
||||||
final wallet = MockFiroWallet();
|
|
||||||
when(wallet.totalBalance).thenAnswer((_) async => Decimal.fromInt(2));
|
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
|
||||||
|
|
||||||
expect(await manager.totalBalance, Decimal.fromInt(2));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("balanceMinusMaxFee", () async {
|
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
|
||||||
when(wallet.balanceMinusMaxFee).thenAnswer((_) async => Decimal.one);
|
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
|
||||||
|
|
||||||
expect(await manager.balanceMinusMaxFee, Decimal.one);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("allOwnAddresses", () async {
|
test("transactions", () async {
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
final CoinServiceAPI wallet = MockFiroWallet();
|
||||||
when(wallet.allOwnAddresses)
|
final tx = Transaction(
|
||||||
.thenAnswer((_) async => ["address1", "address2", "address3"]);
|
walletId: "walletId",
|
||||||
|
txid: "txid",
|
||||||
|
timestamp: 6,
|
||||||
|
type: TransactionType.incoming,
|
||||||
|
subType: TransactionSubType.mint,
|
||||||
|
amount: 123,
|
||||||
|
fee: 3,
|
||||||
|
height: 123,
|
||||||
|
isCancelled: false,
|
||||||
|
isLelantus: true,
|
||||||
|
slateId: null,
|
||||||
|
otherData: null,
|
||||||
|
);
|
||||||
|
when(wallet.transactions).thenAnswer((_) async => [
|
||||||
|
tx,
|
||||||
|
]);
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
final manager = Manager(wallet);
|
||||||
|
|
||||||
expect(await manager.allOwnAddresses, ["address1", "address2", "address3"]);
|
final result = await manager.transactions;
|
||||||
});
|
|
||||||
|
|
||||||
test("transactionData", () async {
|
expect(result.length, 1);
|
||||||
final CoinServiceAPI wallet = MockFiroWallet();
|
|
||||||
when(wallet.transactionData)
|
|
||||||
.thenAnswer((_) async => TransactionData.fromJson(dateTimeChunksJson));
|
|
||||||
|
|
||||||
final manager = Manager(wallet);
|
expect(result.first, tx);
|
||||||
|
|
||||||
final expectedMap =
|
|
||||||
TransactionData.fromJson(dateTimeChunksJson).getAllTransactions();
|
|
||||||
final result = (await manager.transactionData).getAllTransactions();
|
|
||||||
|
|
||||||
expect(result.length, expectedMap.length);
|
|
||||||
|
|
||||||
for (int i = 0; i < expectedMap.length; i++) {
|
|
||||||
final resultTxid = result.keys.toList(growable: false)[i];
|
|
||||||
expect(result[resultTxid].toString(), expectedMap[resultTxid].toString());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("refresh", () async {
|
test("refresh", () async {
|
||||||
|
|
Loading…
Reference in a new issue