mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-05 10:19:22 +00:00
disable auto mint test
This commit is contained in:
parent
d2fbb7a4ba
commit
1ca9449abb
1 changed files with 218 additions and 219 deletions
|
@ -26,7 +26,6 @@ import 'firo_wallet_test.mocks.dart';
|
||||||
import 'firo_wallet_test_parameters.dart';
|
import 'firo_wallet_test_parameters.dart';
|
||||||
import 'sample_data/get_anonymity_set_sample_data.dart';
|
import 'sample_data/get_anonymity_set_sample_data.dart';
|
||||||
import 'sample_data/get_used_serials_sample_data.dart';
|
import 'sample_data/get_used_serials_sample_data.dart';
|
||||||
import 'sample_data/get_utxos_sample_data.dart';
|
|
||||||
import 'sample_data/gethistory_samples.dart';
|
import 'sample_data/gethistory_samples.dart';
|
||||||
import 'sample_data/transaction_data_samples.dart';
|
import 'sample_data/transaction_data_samples.dart';
|
||||||
|
|
||||||
|
@ -3398,224 +3397,224 @@ void main() {
|
||||||
await firo.exit();
|
await firo.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("autoMint", () async {
|
// test("autoMint", () async {
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
// TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
const MethodChannel('uk.spiralarm.flutter/devicelocale')
|
// const MethodChannel('uk.spiralarm.flutter/devicelocale')
|
||||||
.setMockMethodCallHandler((methodCall) async => 'en_US');
|
// .setMockMethodCallHandler((methodCall) async => 'en_US');
|
||||||
|
//
|
||||||
final client = MockElectrumX();
|
// final client = MockElectrumX();
|
||||||
final cachedClient = MockCachedElectrumX();
|
// final cachedClient = MockCachedElectrumX();
|
||||||
final secureStore = FakeSecureStorage();
|
// final secureStore = FakeSecureStorage();
|
||||||
final priceAPI = MockPriceAPI();
|
// final priceAPI = MockPriceAPI();
|
||||||
|
//
|
||||||
// mock electrumx client calls
|
// // mock electrumx client calls
|
||||||
when(client.getServerFeatures()).thenAnswer((_) async => {
|
// when(client.getServerFeatures()).thenAnswer((_) async => {
|
||||||
"hosts": {},
|
// "hosts": {},
|
||||||
"pruning": null,
|
// "pruning": null,
|
||||||
"server_version": "Unit tests",
|
// "server_version": "Unit tests",
|
||||||
"protocol_min": "1.4",
|
// "protocol_min": "1.4",
|
||||||
"protocol_max": "1.4.2",
|
// "protocol_max": "1.4.2",
|
||||||
"genesis_hash": GENESIS_HASH_MAINNET,
|
// "genesis_hash": GENESIS_HASH_MAINNET,
|
||||||
"hash_function": "sha256",
|
// "hash_function": "sha256",
|
||||||
"services": []
|
// "services": []
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
when(client.getBlockHeadTip()).thenAnswer(
|
// when(client.getBlockHeadTip()).thenAnswer(
|
||||||
(_) async => {"height": 465873, "hex": "this value not used here"});
|
// (_) async => {"height": 465873, "hex": "this value not used here"});
|
||||||
|
//
|
||||||
when(client.broadcastTransaction(rawTx: anyNamed("rawTx")))
|
// when(client.broadcastTransaction(rawTx: anyNamed("rawTx")))
|
||||||
.thenAnswer((realInvocation) async {
|
// .thenAnswer((realInvocation) async {
|
||||||
final rawTx =
|
// final rawTx =
|
||||||
realInvocation.namedArguments[const Symbol("rawTx")] as String;
|
// realInvocation.namedArguments[const Symbol("rawTx")] as String;
|
||||||
final rawTxData = Format.stringToUint8List(rawTx);
|
// final rawTxData = Format.stringToUint8List(rawTx);
|
||||||
|
//
|
||||||
final hash = sha256
|
// final hash = sha256
|
||||||
.convert(sha256.convert(rawTxData.toList(growable: false)).bytes);
|
// .convert(sha256.convert(rawTxData.toList(growable: false)).bytes);
|
||||||
|
//
|
||||||
final reversedBytes =
|
// final reversedBytes =
|
||||||
Uint8List.fromList(hash.bytes.reversed.toList(growable: false));
|
// Uint8List.fromList(hash.bytes.reversed.toList(growable: false));
|
||||||
|
//
|
||||||
final txid = Format.uint8listToString(reversedBytes);
|
// final txid = Format.uint8listToString(reversedBytes);
|
||||||
|
//
|
||||||
return txid;
|
// return txid;
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
when(client.estimateFee(blocks: 1))
|
// when(client.estimateFee(blocks: 1))
|
||||||
.thenAnswer((_) async => Decimal.parse("0.00001000"));
|
// .thenAnswer((_) async => Decimal.parse("0.00001000"));
|
||||||
when(client.estimateFee(blocks: 5))
|
// when(client.estimateFee(blocks: 5))
|
||||||
.thenAnswer((_) async => Decimal.parse("0.00001000"));
|
// .thenAnswer((_) async => Decimal.parse("0.00001000"));
|
||||||
when(client.estimateFee(blocks: 20))
|
// when(client.estimateFee(blocks: 20))
|
||||||
.thenAnswer((_) async => Decimal.parse("0.00001000"));
|
// .thenAnswer((_) async => Decimal.parse("0.00001000"));
|
||||||
|
//
|
||||||
when(cachedClient.getAnonymitySet(
|
// when(cachedClient.getAnonymitySet(
|
||||||
groupId: "1", blockhash: "", coin: Coin.firo))
|
// groupId: "1", blockhash: "", coin: Coin.firo))
|
||||||
.thenAnswer((_) async => GetAnonymitySetSampleData.data);
|
// .thenAnswer((_) async => GetAnonymitySetSampleData.data);
|
||||||
when(cachedClient.getUsedCoinSerials(startNumber: 0, coin: Coin.firo))
|
// when(cachedClient.getUsedCoinSerials(startNumber: 0, coin: Coin.firo))
|
||||||
.thenAnswer(
|
// .thenAnswer(
|
||||||
(_) async => GetUsedSerialsSampleData.serials['serials'] as List);
|
// (_) async => GetUsedSerialsSampleData.serials['serials'] as List);
|
||||||
|
//
|
||||||
when(client.getLatestCoinId()).thenAnswer((_) async => 1);
|
// when(client.getLatestCoinId()).thenAnswer((_) async => 1);
|
||||||
// when(client.getCoinsForRecovery(setId: 1))
|
// // when(client.getCoinsForRecovery(setId: 1))
|
||||||
// .thenAnswer((_) async => getCoinsForRecoveryResponse);
|
// // .thenAnswer((_) async => getCoinsForRecoveryResponse);
|
||||||
when(client.getUsedCoinSerials(startNumber: 0))
|
// when(client.getUsedCoinSerials(startNumber: 0))
|
||||||
.thenAnswer((_) async => GetUsedSerialsSampleData.serials);
|
// .thenAnswer((_) async => GetUsedSerialsSampleData.serials);
|
||||||
|
//
|
||||||
// mock price calls
|
// // mock price calls
|
||||||
when(priceAPI.getPricesAnd24hChange(baseCurrency: "USD")).thenAnswer(
|
// when(priceAPI.getPricesAnd24hChange(baseCurrency: "USD")).thenAnswer(
|
||||||
(_) async => {Coin.firo: Tuple2(Decimal.fromInt(10), 1.0)});
|
// (_) async => {Coin.firo: Tuple2(Decimal.fromInt(10), 1.0)});
|
||||||
|
//
|
||||||
// mock transaction calls
|
// // mock transaction calls
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash0,
|
// txHash: SampleGetTransactionData.txHash0,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData0);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData0);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash1,
|
// txHash: SampleGetTransactionData.txHash1,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData1);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData1);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash2,
|
// txHash: SampleGetTransactionData.txHash2,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData2);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData2);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash3,
|
// txHash: SampleGetTransactionData.txHash3,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData3);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData3);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash4,
|
// txHash: SampleGetTransactionData.txHash4,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData4);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData4);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash5,
|
// txHash: SampleGetTransactionData.txHash5,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData5);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData5);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash6,
|
// txHash: SampleGetTransactionData.txHash6,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData6);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData6);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash7,
|
// txHash: SampleGetTransactionData.txHash7,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData7);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData7);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash8,
|
// txHash: SampleGetTransactionData.txHash8,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData8);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData8);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash9,
|
// txHash: SampleGetTransactionData.txHash9,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData9);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData9);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash10,
|
// txHash: SampleGetTransactionData.txHash10,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData10);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData10);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash11,
|
// txHash: SampleGetTransactionData.txHash11,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData11);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData11);
|
||||||
when(cachedClient.getTransaction(
|
// when(cachedClient.getTransaction(
|
||||||
txHash: SampleGetTransactionData.txHash12,
|
// txHash: SampleGetTransactionData.txHash12,
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
)).thenAnswer((_) async => SampleGetTransactionData.txData12);
|
// )).thenAnswer((_) async => SampleGetTransactionData.txData12);
|
||||||
|
//
|
||||||
final firo = FiroWallet(
|
// final firo = FiroWallet(
|
||||||
walletName: testWalletName,
|
// walletName: testWalletName,
|
||||||
walletId: "${testWalletId}autoMint",
|
// walletId: "${testWalletId}autoMint",
|
||||||
coin: Coin.firo,
|
// coin: Coin.firo,
|
||||||
client: client,
|
// client: client,
|
||||||
cachedClient: cachedClient,
|
// cachedClient: cachedClient,
|
||||||
secureStore: secureStore,
|
// secureStore: secureStore,
|
||||||
priceAPI: priceAPI,
|
// priceAPI: priceAPI,
|
||||||
tracker: MockTransactionNotificationTracker(),
|
// tracker: MockTransactionNotificationTracker(),
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
// pre grab derivations in order to set up mock calls needed later on
|
// // pre grab derivations in order to set up mock calls needed later on
|
||||||
await firo.fillAddresses(TEST_MNEMONIC);
|
// await firo.fillAddresses(TEST_MNEMONIC);
|
||||||
final wallet = await Hive.openBox<dynamic>("${testWalletId}autoMint");
|
// final wallet = await Hive.openBox<dynamic>("${testWalletId}autoMint");
|
||||||
await wallet.put(
|
// await wallet.put(
|
||||||
'receivingAddresses', RefreshTestParams.receivingAddresses);
|
// 'receivingAddresses', RefreshTestParams.receivingAddresses);
|
||||||
await wallet.put('changeAddresses', RefreshTestParams.changeAddresses);
|
// await wallet.put('changeAddresses', RefreshTestParams.changeAddresses);
|
||||||
|
//
|
||||||
final rcv = await secureStore.read(
|
// final rcv = await secureStore.read(
|
||||||
key: "${testWalletId}autoMint_receiveDerivations");
|
// key: "${testWalletId}autoMint_receiveDerivations");
|
||||||
final chg = await secureStore.read(
|
// final chg = await secureStore.read(
|
||||||
key: "${testWalletId}autoMint_changeDerivations");
|
// key: "${testWalletId}autoMint_changeDerivations");
|
||||||
final receiveDerivations =
|
// final receiveDerivations =
|
||||||
Map<String, dynamic>.from(jsonDecode(rcv as String) as Map);
|
// Map<String, dynamic>.from(jsonDecode(rcv as String) as Map);
|
||||||
final changeDerivations =
|
// final changeDerivations =
|
||||||
Map<String, dynamic>.from(jsonDecode(chg as String) as Map);
|
// Map<String, dynamic>.from(jsonDecode(chg as String) as Map);
|
||||||
|
//
|
||||||
for (int i = 0; i < receiveDerivations.length; i++) {
|
// for (int i = 0; i < receiveDerivations.length; i++) {
|
||||||
final receiveHash = AddressUtils.convertToScriptHash(
|
// final receiveHash = AddressUtils.convertToScriptHash(
|
||||||
receiveDerivations["$i"]!["address"] as String, firoNetwork);
|
// receiveDerivations["$i"]!["address"] as String, firoNetwork);
|
||||||
final changeHash = AddressUtils.convertToScriptHash(
|
// final changeHash = AddressUtils.convertToScriptHash(
|
||||||
changeDerivations["$i"]!["address"] as String, firoNetwork);
|
// changeDerivations["$i"]!["address"] as String, firoNetwork);
|
||||||
List<Map<String, dynamic>> data;
|
// List<Map<String, dynamic>> data;
|
||||||
switch (receiveHash) {
|
// switch (receiveHash) {
|
||||||
case SampleGetHistoryData.scripthash0:
|
// case SampleGetHistoryData.scripthash0:
|
||||||
data = SampleGetHistoryData.data0;
|
// data = SampleGetHistoryData.data0;
|
||||||
break;
|
// break;
|
||||||
case SampleGetHistoryData.scripthash1:
|
// case SampleGetHistoryData.scripthash1:
|
||||||
data = SampleGetHistoryData.data1;
|
// data = SampleGetHistoryData.data1;
|
||||||
break;
|
// break;
|
||||||
case SampleGetHistoryData.scripthash2:
|
// case SampleGetHistoryData.scripthash2:
|
||||||
data = SampleGetHistoryData.data2;
|
// data = SampleGetHistoryData.data2;
|
||||||
break;
|
// break;
|
||||||
case SampleGetHistoryData.scripthash3:
|
// case SampleGetHistoryData.scripthash3:
|
||||||
data = SampleGetHistoryData.data3;
|
// data = SampleGetHistoryData.data3;
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
data = [];
|
// data = [];
|
||||||
}
|
// }
|
||||||
when(client.getHistory(scripthash: receiveHash))
|
// when(client.getHistory(scripthash: receiveHash))
|
||||||
.thenAnswer((_) async => data);
|
// .thenAnswer((_) async => data);
|
||||||
|
//
|
||||||
switch (changeHash) {
|
// switch (changeHash) {
|
||||||
case SampleGetHistoryData.scripthash0:
|
// case SampleGetHistoryData.scripthash0:
|
||||||
data = SampleGetHistoryData.data0;
|
// data = SampleGetHistoryData.data0;
|
||||||
break;
|
// break;
|
||||||
case SampleGetHistoryData.scripthash1:
|
// case SampleGetHistoryData.scripthash1:
|
||||||
data = SampleGetHistoryData.data1;
|
// data = SampleGetHistoryData.data1;
|
||||||
break;
|
// break;
|
||||||
case SampleGetHistoryData.scripthash2:
|
// case SampleGetHistoryData.scripthash2:
|
||||||
data = SampleGetHistoryData.data2;
|
// data = SampleGetHistoryData.data2;
|
||||||
break;
|
// break;
|
||||||
case SampleGetHistoryData.scripthash3:
|
// case SampleGetHistoryData.scripthash3:
|
||||||
data = SampleGetHistoryData.data3;
|
// data = SampleGetHistoryData.data3;
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
data = [];
|
// data = [];
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
when(client.getHistory(scripthash: changeHash))
|
// when(client.getHistory(scripthash: changeHash))
|
||||||
.thenAnswer((_) async => data);
|
// .thenAnswer((_) async => data);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
when(client.getUTXOs(scripthash: GetUtxoSampleData.scriptHash0))
|
// when(client.getUTXOs(scripthash: GetUtxoSampleData.scriptHash0))
|
||||||
.thenAnswer((_) async => GetUtxoSampleData.utxos0);
|
// .thenAnswer((_) async => GetUtxoSampleData.utxos0);
|
||||||
when(client.getUTXOs(scripthash: GetUtxoSampleData.scriptHash1))
|
// when(client.getUTXOs(scripthash: GetUtxoSampleData.scriptHash1))
|
||||||
.thenAnswer((_) async => GetUtxoSampleData.utxos1);
|
// .thenAnswer((_) async => GetUtxoSampleData.utxos1);
|
||||||
|
//
|
||||||
await firo.recoverFromMnemonic(
|
// await firo.recoverFromMnemonic(
|
||||||
mnemonic: TEST_MNEMONIC,
|
// mnemonic: TEST_MNEMONIC,
|
||||||
maxUnusedAddressGap: 20,
|
// maxUnusedAddressGap: 20,
|
||||||
height: 0,
|
// height: 0,
|
||||||
maxNumberOfIndexesToCheck: 1000);
|
// maxNumberOfIndexesToCheck: 1000);
|
||||||
|
//
|
||||||
firo.timer = Timer(const Duration(minutes: 3), () {});
|
// firo.timer = Timer(const Duration(minutes: 3), () {});
|
||||||
|
//
|
||||||
await firo.refresh();
|
// await firo.refresh();
|
||||||
|
//
|
||||||
bool flag = false;
|
// bool flag = false;
|
||||||
try {
|
// try {
|
||||||
await firo.autoMint();
|
// await firo.autoMint();
|
||||||
} catch (_) {
|
// } catch (_) {
|
||||||
flag = true;
|
// flag = true;
|
||||||
}
|
// }
|
||||||
expect(flag, false);
|
// expect(flag, false);
|
||||||
|
//
|
||||||
await firo.exit();
|
// await firo.exit();
|
||||||
}, timeout: const Timeout(Duration(minutes: 3)));
|
// }, timeout: const Timeout(Duration(minutes: 3)));
|
||||||
|
|
||||||
test("exit", () async {
|
test("exit", () async {
|
||||||
final firo = FiroWallet(
|
final firo = FiroWallet(
|
||||||
|
|
Loading…
Reference in a new issue