diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index 56f6d3aaf..aa83ea4a9 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -309,6 +309,11 @@ class BitcoinCashWallet extends CoinServiceAPI { throw Exception("genesis hash does not match main net!"); } break; + case Coin.bitcoincashTestnet: + if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { + throw Exception("genesis hash does not match test net!"); + } + break; default: throw Exception( "Attempted to generate a BitcoinCashWallet using a non bch coin type: ${coin.name}"); diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart index cb79b905b..5628c81f3 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart @@ -25,8 +25,8 @@ import 'bitcoincash_utxo_sample_data.dart'; import 'bitcoincash_wallet_test.mocks.dart'; import 'bitcoincash_wallet_test_parameters.dart'; -@GenerateMocks( - [ElectrumX, CachedElectrumX, PriceAPI, TransactionNotificationTracker]) +@GenerateMocks([CachedElectrumX, PriceAPI, TransactionNotificationTracker], + customMocks: [MockSpec(returnNullOnMissingStub: true)]) void main() { group("bitcoincash constants", () { test("bitcoincash minimum confirmations", () async { @@ -2080,8 +2080,8 @@ void main() { }); when(client?.getBatchHistory(args: historyBatchArgs0)) .thenAnswer((_) async => historyBatchResponse); - // when(client?.getBatchHistory(args: historyBatchArgs1)) - // .thenAnswer((_) async => historyBatchResponse); + when(client?.getBatchHistory(args: historyBatchArgs1)) + .thenAnswer((_) async => historyBatchResponse); final wallet = await Hive.openBox(testWalletId); @@ -2099,7 +2099,7 @@ void main() { verify(client?.getServerFeatures()).called(1); verify(client?.getBatchHistory(args: historyBatchArgs0)).called(1); - // verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); + verify(client?.getBatchHistory(args: historyBatchArgs1)).called(1); expect(secureStore?.interactions, 6); expect(secureStore?.writes, 3); @@ -2125,8 +2125,8 @@ void main() { }); when(client?.getBatchHistory(args: historyBatchArgs0)) .thenAnswer((_) async => historyBatchResponse); - when(client?.getBatchHistory(args: historyBatchArgs1)) - .thenAnswer((_) async => historyBatchResponse); + // when(client?.getBatchHistory(args: historyBatchArgs1)) + // .thenAnswer((_) async => historyBatchResponse); when(cachedClient?.clearSharedTransactionCache(coin: Coin.bitcoincash)) .thenAnswer((realInvocation) async {}); diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart index f24f8be4c..fa38e1f9e 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart @@ -2,18 +2,18 @@ // in stackwallet/test/services/coins/bitcoincash/bitcoincash_wallet_test.dart. // Do not manually edit this file. -import 'dart:async' as _i6; +import 'dart:async' as _i7; -import 'package:decimal/decimal.dart' as _i2; -import 'package:http/http.dart' as _i4; +import 'package:decimal/decimal.dart' as _i4; +import 'package:http/http.dart' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart' as _i7; -import 'package:stackwallet/electrumx_rpc/electrumx.dart' as _i5; +import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart' as _i5; +import 'package:stackwallet/electrumx_rpc/electrumx.dart' as _i6; import 'package:stackwallet/services/price.dart' as _i9; import 'package:stackwallet/services/transaction_notification_tracker.dart' as _i11; import 'package:stackwallet/utilities/enums/coin_enum.dart' as _i8; -import 'package:stackwallet/utilities/prefs.dart' as _i3; +import 'package:stackwallet/utilities/prefs.dart' as _i2; import 'package:tuple/tuple.dart' as _i10; // ignore_for_file: type=lint @@ -26,208 +26,16 @@ import 'package:tuple/tuple.dart' as _i10; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types -class _FakeDecimal_0 extends _i1.Fake implements _i2.Decimal {} +class _FakePrefs_0 extends _i1.Fake implements _i2.Prefs {} -class _FakePrefs_1 extends _i1.Fake implements _i3.Prefs {} +class _FakeClient_1 extends _i1.Fake implements _i3.Client {} -class _FakeClient_2 extends _i1.Fake implements _i4.Client {} - -/// A class which mocks [ElectrumX]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockElectrumX extends _i1.Mock implements _i5.ElectrumX { - MockElectrumX() { - _i1.throwOnMissingStub(this); - } - - @override - set failovers(List<_i5.ElectrumXNode>? _failovers) => - super.noSuchMethod(Invocation.setter(#failovers, _failovers), - returnValueForMissingStub: null); - @override - int get currentFailoverIndex => - (super.noSuchMethod(Invocation.getter(#currentFailoverIndex), - returnValue: 0) as int); - @override - set currentFailoverIndex(int? _currentFailoverIndex) => super.noSuchMethod( - Invocation.setter(#currentFailoverIndex, _currentFailoverIndex), - returnValueForMissingStub: null); - @override - String get host => - (super.noSuchMethod(Invocation.getter(#host), returnValue: '') as String); - @override - int get port => - (super.noSuchMethod(Invocation.getter(#port), returnValue: 0) as int); - @override - bool get useSSL => - (super.noSuchMethod(Invocation.getter(#useSSL), returnValue: false) - as bool); - @override - _i6.Future request( - {String? command, - List? args = const [], - Duration? connectionTimeout = const Duration(seconds: 60), - String? requestID, - int? retries = 2}) => - (super.noSuchMethod( - Invocation.method(#request, [], { - #command: command, - #args: args, - #connectionTimeout: connectionTimeout, - #requestID: requestID, - #retries: retries - }), - returnValue: Future.value()) as _i6.Future); - @override - _i6.Future>> batchRequest( - {String? command, - Map>? args, - Duration? connectionTimeout = const Duration(seconds: 60), - int? retries = 2}) => - (super.noSuchMethod( - Invocation.method(#batchRequest, [], { - #command: command, - #args: args, - #connectionTimeout: connectionTimeout, - #retries: retries - }), - returnValue: Future>>.value( - >[])) - as _i6.Future>>); - @override - _i6.Future ping({String? requestID, int? retryCount = 1}) => - (super.noSuchMethod( - Invocation.method( - #ping, [], {#requestID: requestID, #retryCount: retryCount}), - returnValue: Future.value(false)) as _i6.Future); - @override - _i6.Future> getBlockHeadTip({String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getBlockHeadTip, [], {#requestID: requestID}), - returnValue: - Future>.value({})) - as _i6.Future>); - @override - _i6.Future> getServerFeatures({String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getServerFeatures, [], {#requestID: requestID}), - returnValue: - Future>.value({})) as _i6 - .Future>); - @override - _i6.Future broadcastTransaction({String? rawTx, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#broadcastTransaction, [], - {#rawTx: rawTx, #requestID: requestID}), - returnValue: Future.value('')) as _i6.Future); - @override - _i6.Future> getBalance( - {String? scripthash, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getBalance, [], - {#scripthash: scripthash, #requestID: requestID}), - returnValue: - Future>.value({})) - as _i6.Future>); - @override - _i6.Future>> getHistory( - {String? scripthash, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getHistory, [], - {#scripthash: scripthash, #requestID: requestID}), - returnValue: Future>>.value( - >[])) - as _i6.Future>>); - @override - _i6.Future>>> getBatchHistory( - {Map>? args}) => - (super.noSuchMethod( - Invocation.method(#getBatchHistory, [], {#args: args}), - returnValue: Future>>>.value( - >>{})) as _i6 - .Future>>>); - @override - _i6.Future>> getUTXOs( - {String? scripthash, String? requestID}) => - (super.noSuchMethod( - Invocation.method( - #getUTXOs, [], {#scripthash: scripthash, #requestID: requestID}), - returnValue: Future>>.value( - >[])) as _i6 - .Future>>); - @override - _i6.Future>>> getBatchUTXOs( - {Map>? args}) => - (super.noSuchMethod(Invocation.method(#getBatchUTXOs, [], {#args: args}), - returnValue: Future>>>.value( - >>{})) as _i6 - .Future>>>); - @override - _i6.Future> getTransaction( - {String? txHash, bool? verbose = true, String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getTransaction, [], - {#txHash: txHash, #verbose: verbose, #requestID: requestID}), - returnValue: - Future>.value({})) - as _i6.Future>); - @override - _i6.Future> getAnonymitySet( - {String? groupId = r'1', - String? blockhash = r'', - String? requestID}) => - (super.noSuchMethod( - Invocation.method(#getAnonymitySet, [], { - #groupId: groupId, - #blockhash: blockhash, - #requestID: requestID - }), - returnValue: - Future>.value({})) - as _i6.Future>); - @override - _i6.Future getMintData({dynamic mints, String? requestID}) => - (super.noSuchMethod( - Invocation.method( - #getMintData, [], {#mints: mints, #requestID: requestID}), - returnValue: Future.value()) as _i6.Future); - @override - _i6.Future> getUsedCoinSerials( - {String? requestID, int? startNumber}) => - (super.noSuchMethod( - Invocation.method(#getUsedCoinSerials, [], - {#requestID: requestID, #startNumber: startNumber}), - returnValue: - Future>.value({})) - as _i6.Future>); - @override - _i6.Future getLatestCoinId({String? requestID}) => (super.noSuchMethod( - Invocation.method(#getLatestCoinId, [], {#requestID: requestID}), - returnValue: Future.value(0)) as _i6.Future); - @override - _i6.Future> getFeeRate({String? requestID}) => (super - .noSuchMethod(Invocation.method(#getFeeRate, [], {#requestID: requestID}), - returnValue: - Future>.value({})) as _i6 - .Future>); - @override - _i6.Future<_i2.Decimal> estimateFee({String? requestID, int? blocks}) => - (super.noSuchMethod( - Invocation.method( - #estimateFee, [], {#requestID: requestID, #blocks: blocks}), - returnValue: Future<_i2.Decimal>.value(_FakeDecimal_0())) - as _i6.Future<_i2.Decimal>); - @override - _i6.Future<_i2.Decimal> relayFee({String? requestID}) => (super.noSuchMethod( - Invocation.method(#relayFee, [], {#requestID: requestID}), - returnValue: Future<_i2.Decimal>.value(_FakeDecimal_0())) - as _i6.Future<_i2.Decimal>); -} +class _FakeDecimal_2 extends _i1.Fake implements _i4.Decimal {} /// A class which mocks [CachedElectrumX]. /// /// See the documentation for Mockito's code generation for more information. -class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX { +class MockCachedElectrumX extends _i1.Mock implements _i5.CachedElectrumX { MockCachedElectrumX() { _i1.throwOnMissingStub(this); } @@ -244,44 +52,44 @@ class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX { (super.noSuchMethod(Invocation.getter(#useSSL), returnValue: false) as bool); @override - _i3.Prefs get prefs => (super.noSuchMethod(Invocation.getter(#prefs), - returnValue: _FakePrefs_1()) as _i3.Prefs); + _i2.Prefs get prefs => (super.noSuchMethod(Invocation.getter(#prefs), + returnValue: _FakePrefs_0()) as _i2.Prefs); @override - List<_i5.ElectrumXNode> get failovers => + List<_i6.ElectrumXNode> get failovers => (super.noSuchMethod(Invocation.getter(#failovers), - returnValue: <_i5.ElectrumXNode>[]) as List<_i5.ElectrumXNode>); + returnValue: <_i6.ElectrumXNode>[]) as List<_i6.ElectrumXNode>); @override - _i6.Future> getAnonymitySet( + _i7.Future> getAnonymitySet( {String? groupId, String? blockhash = r'', _i8.Coin? coin}) => (super.noSuchMethod( Invocation.method(#getAnonymitySet, [], {#groupId: groupId, #blockhash: blockhash, #coin: coin}), returnValue: Future>.value({})) - as _i6.Future>); + as _i7.Future>); @override - _i6.Future> getTransaction( + _i7.Future> getTransaction( {String? txHash, _i8.Coin? coin, bool? verbose = true}) => (super.noSuchMethod( Invocation.method(#getTransaction, [], {#txHash: txHash, #coin: coin, #verbose: verbose}), returnValue: Future>.value({})) - as _i6.Future>); + as _i7.Future>); @override - _i6.Future> getUsedCoinSerials( + _i7.Future> getUsedCoinSerials( {_i8.Coin? coin, int? startNumber = 0}) => (super.noSuchMethod( Invocation.method(#getUsedCoinSerials, [], {#coin: coin, #startNumber: startNumber}), returnValue: Future>.value([])) - as _i6.Future>); + as _i7.Future>); @override - _i6.Future clearSharedTransactionCache({_i8.Coin? coin}) => + _i7.Future clearSharedTransactionCache({_i8.Coin? coin}) => (super.noSuchMethod( Invocation.method(#clearSharedTransactionCache, [], {#coin: coin}), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i7.Future); } /// A class which mocks [PriceAPI]. @@ -293,21 +101,21 @@ class MockPriceAPI extends _i1.Mock implements _i9.PriceAPI { } @override - _i4.Client get client => (super.noSuchMethod(Invocation.getter(#client), - returnValue: _FakeClient_2()) as _i4.Client); + _i3.Client get client => (super.noSuchMethod(Invocation.getter(#client), + returnValue: _FakeClient_1()) as _i3.Client); @override void resetLastCalledToForceNextCallToUpdateCache() => super.noSuchMethod( Invocation.method(#resetLastCalledToForceNextCallToUpdateCache, []), returnValueForMissingStub: null); @override - _i6.Future>> + _i7.Future>> getPricesAnd24hChange({String? baseCurrency}) => (super.noSuchMethod( Invocation.method( #getPricesAnd24hChange, [], {#baseCurrency: baseCurrency}), returnValue: - Future>>.value( - <_i8.Coin, _i10.Tuple2<_i2.Decimal, double>>{})) - as _i6.Future>>); + Future>>.value( + <_i8.Coin, _i10.Tuple2<_i4.Decimal, double>>{})) + as _i7.Future>>); } /// A class which mocks [TransactionNotificationTracker]. @@ -336,17 +144,205 @@ class MockTransactionNotificationTracker extends _i1.Mock (super.noSuchMethod(Invocation.method(#wasNotifiedPending, [txid]), returnValue: false) as bool); @override - _i6.Future addNotifiedPending(String? txid) => + _i7.Future addNotifiedPending(String? txid) => (super.noSuchMethod(Invocation.method(#addNotifiedPending, [txid]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i7.Future); @override bool wasNotifiedConfirmed(String? txid) => (super.noSuchMethod(Invocation.method(#wasNotifiedConfirmed, [txid]), returnValue: false) as bool); @override - _i6.Future addNotifiedConfirmed(String? txid) => + _i7.Future addNotifiedConfirmed(String? txid) => (super.noSuchMethod(Invocation.method(#addNotifiedConfirmed, [txid]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValueForMissingStub: Future.value()) as _i7.Future); +} + +/// A class which mocks [ElectrumX]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockElectrumX extends _i1.Mock implements _i6.ElectrumX { + @override + set failovers(List<_i6.ElectrumXNode>? _failovers) => + super.noSuchMethod(Invocation.setter(#failovers, _failovers), + returnValueForMissingStub: null); + @override + int get currentFailoverIndex => + (super.noSuchMethod(Invocation.getter(#currentFailoverIndex), + returnValue: 0) as int); + @override + set currentFailoverIndex(int? _currentFailoverIndex) => super.noSuchMethod( + Invocation.setter(#currentFailoverIndex, _currentFailoverIndex), + returnValueForMissingStub: null); + @override + String get host => + (super.noSuchMethod(Invocation.getter(#host), returnValue: '') as String); + @override + int get port => + (super.noSuchMethod(Invocation.getter(#port), returnValue: 0) as int); + @override + bool get useSSL => + (super.noSuchMethod(Invocation.getter(#useSSL), returnValue: false) + as bool); + @override + _i7.Future request( + {String? command, + List? args = const [], + Duration? connectionTimeout = const Duration(seconds: 60), + String? requestID, + int? retries = 2}) => + (super.noSuchMethod( + Invocation.method(#request, [], { + #command: command, + #args: args, + #connectionTimeout: connectionTimeout, + #requestID: requestID, + #retries: retries + }), + returnValue: Future.value()) as _i7.Future); + @override + _i7.Future>> batchRequest( + {String? command, + Map>? args, + Duration? connectionTimeout = const Duration(seconds: 60), + int? retries = 2}) => + (super.noSuchMethod( + Invocation.method(#batchRequest, [], { + #command: command, + #args: args, + #connectionTimeout: connectionTimeout, + #retries: retries + }), + returnValue: Future>>.value( + >[])) + as _i7.Future>>); + @override + _i7.Future ping({String? requestID, int? retryCount = 1}) => + (super.noSuchMethod( + Invocation.method( + #ping, [], {#requestID: requestID, #retryCount: retryCount}), + returnValue: Future.value(false)) as _i7.Future); + @override + _i7.Future> getBlockHeadTip({String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getBlockHeadTip, [], {#requestID: requestID}), + returnValue: + Future>.value({})) + as _i7.Future>); + @override + _i7.Future> getServerFeatures({String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getServerFeatures, [], {#requestID: requestID}), + returnValue: + Future>.value({})) as _i7 + .Future>); + @override + _i7.Future broadcastTransaction({String? rawTx, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#broadcastTransaction, [], + {#rawTx: rawTx, #requestID: requestID}), + returnValue: Future.value('')) as _i7.Future); + @override + _i7.Future> getBalance( + {String? scripthash, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getBalance, [], + {#scripthash: scripthash, #requestID: requestID}), + returnValue: + Future>.value({})) + as _i7.Future>); + @override + _i7.Future>> getHistory( + {String? scripthash, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getHistory, [], + {#scripthash: scripthash, #requestID: requestID}), + returnValue: Future>>.value( + >[])) + as _i7.Future>>); + @override + _i7.Future>>> getBatchHistory( + {Map>? args}) => + (super.noSuchMethod( + Invocation.method(#getBatchHistory, [], {#args: args}), + returnValue: Future>>>.value( + >>{})) as _i7 + .Future>>>); + @override + _i7.Future>> getUTXOs( + {String? scripthash, String? requestID}) => + (super.noSuchMethod( + Invocation.method( + #getUTXOs, [], {#scripthash: scripthash, #requestID: requestID}), + returnValue: Future>>.value( + >[])) as _i7 + .Future>>); + @override + _i7.Future>>> getBatchUTXOs( + {Map>? args}) => + (super.noSuchMethod(Invocation.method(#getBatchUTXOs, [], {#args: args}), + returnValue: Future>>>.value( + >>{})) as _i7 + .Future>>>); + @override + _i7.Future> getTransaction( + {String? txHash, bool? verbose = true, String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getTransaction, [], + {#txHash: txHash, #verbose: verbose, #requestID: requestID}), + returnValue: + Future>.value({})) + as _i7.Future>); + @override + _i7.Future> getAnonymitySet( + {String? groupId = r'1', + String? blockhash = r'', + String? requestID}) => + (super.noSuchMethod( + Invocation.method(#getAnonymitySet, [], { + #groupId: groupId, + #blockhash: blockhash, + #requestID: requestID + }), + returnValue: + Future>.value({})) + as _i7.Future>); + @override + _i7.Future getMintData({dynamic mints, String? requestID}) => + (super.noSuchMethod( + Invocation.method( + #getMintData, [], {#mints: mints, #requestID: requestID}), + returnValue: Future.value()) as _i7.Future); + @override + _i7.Future> getUsedCoinSerials( + {String? requestID, int? startNumber}) => + (super.noSuchMethod( + Invocation.method(#getUsedCoinSerials, [], + {#requestID: requestID, #startNumber: startNumber}), + returnValue: + Future>.value({})) + as _i7.Future>); + @override + _i7.Future getLatestCoinId({String? requestID}) => (super.noSuchMethod( + Invocation.method(#getLatestCoinId, [], {#requestID: requestID}), + returnValue: Future.value(0)) as _i7.Future); + @override + _i7.Future> getFeeRate({String? requestID}) => (super + .noSuchMethod(Invocation.method(#getFeeRate, [], {#requestID: requestID}), + returnValue: + Future>.value({})) as _i7 + .Future>); + @override + _i7.Future<_i4.Decimal> estimateFee({String? requestID, int? blocks}) => + (super.noSuchMethod( + Invocation.method( + #estimateFee, [], {#requestID: requestID, #blocks: blocks}), + returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) + as _i7.Future<_i4.Decimal>); + @override + _i7.Future<_i4.Decimal> relayFee({String? requestID}) => (super.noSuchMethod( + Invocation.method(#relayFee, [], {#requestID: requestID}), + returnValue: Future<_i4.Decimal>.value(_FakeDecimal_2())) + as _i7.Future<_i4.Decimal>); }