2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:hive_test/hive_test.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/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/prefs.dart';
|
|
|
|
|
|
|
|
import 'cached_electrumx_test.mocks.dart';
|
2022-09-08 20:21:26 +00:00
|
|
|
// import 'sample_data/get_anonymity_set_sample_data.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@GenerateMocks([ElectrumX, Prefs])
|
|
|
|
void main() {
|
|
|
|
group("tests using mock hive", () {
|
|
|
|
setUp(() async {
|
|
|
|
await setUpTestHive();
|
2023-07-03 22:27:36 +00:00
|
|
|
// await Hive.openBox<dynamic>(
|
|
|
|
// DB.instance.boxNameUsedSerialsCache(coin: Coin.firo));
|
|
|
|
// await Hive.openBox<dynamic>(DB.instance.boxNameSetCache(coin: Coin.firo));
|
|
|
|
// await Hive.openBox<dynamic>(DB.instance.boxNameTxCache(coin: Coin.firo));
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
group("getAnonymitySet", () {
|
2022-09-08 20:21:26 +00:00
|
|
|
// test("empty set cache call", () async {
|
|
|
|
// final client = MockElectrumX();
|
|
|
|
// when(
|
|
|
|
// client.getAnonymitySet(
|
|
|
|
// groupId: "1",
|
|
|
|
// blockhash: "",
|
|
|
|
// ),
|
|
|
|
// ).thenAnswer(
|
|
|
|
// (_) async => GetAnonymitySetSampleData.data,
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// final cachedClient = CachedElectrumX(
|
|
|
|
// electrumXClient: client,
|
|
|
|
// port: 0,
|
|
|
|
// failovers: [],
|
|
|
|
// server: '',
|
|
|
|
// useSSL: true,
|
|
|
|
// prefs: Prefs.instance);
|
|
|
|
//
|
|
|
|
// final result = await cachedClient.getAnonymitySet(
|
|
|
|
// groupId: "1",
|
|
|
|
// coin: Coin.firo,
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// final expected =
|
|
|
|
// Map<String, dynamic>.from(GetAnonymitySetSampleData.data);
|
|
|
|
// expected["setId"] = "1";
|
|
|
|
//
|
|
|
|
// expect(result, expected);
|
|
|
|
// });
|
2022-08-26 08:11:35 +00:00
|
|
|
//
|
|
|
|
// test("use and update set cache call", () async {
|
|
|
|
// final storedData = Map.from(GetAnonymitySetSampleData.initialData);
|
|
|
|
// storedData["setId"] = "1";
|
|
|
|
// final box = await Hive.openBox('Some coinName_anonymitySetCache');
|
|
|
|
// await box.put("1", storedData);
|
|
|
|
//
|
|
|
|
// final client = MockElectrumX();
|
|
|
|
// when(
|
|
|
|
// client.getAnonymitySet(
|
|
|
|
// groupId: "1",
|
|
|
|
// blockhash: GetAnonymitySetSampleData.initialData["blockHash"],
|
|
|
|
// ),
|
|
|
|
// ).thenAnswer(
|
|
|
|
// (_) async => GetAnonymitySetSampleData.followUpData,
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// final cachedClient = CCachedElectrumX(
|
|
|
|
// electrumXClient: client,
|
|
|
|
// port: 0,
|
|
|
|
// failovers: [],
|
|
|
|
// server: '',
|
|
|
|
// useSSL: true,
|
|
|
|
// prefs: Prefs.instance);
|
|
|
|
//
|
|
|
|
// final result = await cachedClient.getAnonymitySet(
|
|
|
|
// groupId: "1",
|
|
|
|
// coinName: "Some coinName",
|
|
|
|
// callOutSideMainIsolate: true,
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// final expected = Map.from(GetAnonymitySetSampleData.finalData as Map);
|
|
|
|
// expected["setId"] = "1";
|
|
|
|
//
|
|
|
|
// expect(result, expected);
|
|
|
|
// fail("This test needs updating");
|
|
|
|
// });
|
|
|
|
|
2022-09-08 20:21:26 +00:00
|
|
|
// test("getAnonymitySet throws", () async {
|
|
|
|
// final client = MockElectrumX();
|
|
|
|
// when(
|
|
|
|
// client.getAnonymitySet(
|
|
|
|
// groupId: "1",
|
|
|
|
// blockhash: "",
|
|
|
|
// ),
|
|
|
|
// ).thenThrow(Exception());
|
|
|
|
//
|
|
|
|
// final cachedClient = CachedElectrumX(
|
|
|
|
// electrumXClient: client,
|
|
|
|
// port: 0,
|
|
|
|
// failovers: [],
|
|
|
|
// server: '',
|
|
|
|
// useSSL: true,
|
|
|
|
// prefs: Prefs.instance);
|
|
|
|
//
|
|
|
|
// expect(
|
|
|
|
// () async => await cachedClient.getAnonymitySet(
|
|
|
|
// groupId: "1",
|
|
|
|
// coin: Coin.firo,
|
|
|
|
// ),
|
|
|
|
// throwsA(isA<Exception>()));
|
|
|
|
// });
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("getTransaction throws", () async {
|
|
|
|
final client = MockElectrumX();
|
|
|
|
when(
|
|
|
|
client.getTransaction(
|
|
|
|
txHash: "some hash",
|
|
|
|
),
|
|
|
|
).thenThrow(Exception());
|
|
|
|
|
|
|
|
final cachedClient = CachedElectrumX(
|
2023-05-26 23:45:14 +00:00
|
|
|
electrumXClient: client,
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
expect(
|
|
|
|
() async => await cachedClient.getTransaction(
|
|
|
|
txHash: "some hash",
|
|
|
|
coin: Coin.firo,
|
|
|
|
),
|
|
|
|
throwsA(isA<Exception>()));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("clearSharedTransactionCache", () async {
|
|
|
|
final cachedClient = CachedElectrumX(
|
2023-05-26 23:45:14 +00:00
|
|
|
electrumXClient: MockElectrumX(),
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
bool didThrow = false;
|
|
|
|
try {
|
|
|
|
await cachedClient.clearSharedTransactionCache(coin: Coin.firo);
|
|
|
|
} catch (_) {
|
|
|
|
didThrow = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(didThrow, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
await tearDownTestHive();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test(".from factory", () {
|
|
|
|
final node = ElectrumXNode(
|
|
|
|
address: "some address",
|
|
|
|
port: 1,
|
|
|
|
name: "some name",
|
|
|
|
id: "some ID",
|
|
|
|
useSSL: true,
|
|
|
|
);
|
|
|
|
|
2023-05-26 23:45:14 +00:00
|
|
|
final client = CachedElectrumX.from(electrumXClient: MockElectrumX());
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
expect(client, isA<CachedElectrumX>());
|
|
|
|
});
|
|
|
|
}
|