mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-12 08:53:57 +01:00
Catches up from the May 12 fork point (v6.1.2+23) through v6.5.0: 535 upstream commits, including the Monero silent-open fix, Monero on Trezor, Ledger/Trezor BLE fixes, the new seed and history screens, quick Bitcoin sync, git-pinned dependencies (pubspec_overrides.yaml), frozen Hive adapters (*.part.dart), monero_c v0.18.4.6-RC2 and Flutter 3.41.9. Merged with both sides normalized first (import rename, 100-column format), which took the conflict count from 614 paths to 322. The procedure is now scripts/upstream_sync.sh. Kept from Hash Bags: - WalletType enum order and Hive IDs. SQLite stores WalletType.index and our order differs from upstream's; taking theirs would reread saved wallets as other chains. Our frozen adapter keeps the shipped IDs. - The 1.0.2 legacy PIN and wallet-password decode and self-heal. - Removed chains (Solana, Tron, Zano, Zcash, Decred, Haven) and the new Robinhood chain stay out; Cake Pay and non-Trocador swaps stay out. - Default nodes (node.wownero.org, sethforprivacy, Blockstream, bysh.me), converted to upstream's isDefault node-list key; Wownero is back in the node reset list. - Privacy: address resolvers limited to domain-anchored sources again; prices.neroswap.com for fiat; upstream's charts tab, which reads prices.cakewallet.com, sits behind FeatureFlag.isChartsEnabled = false. - Lightning stays behind FeatureFlag.isLightningEnabled, including upstream's new post-seed Lightning username step. - Our icon pipeline, branding and bundle identifiers. Twelve new upstream widget tests are skipped: test and code are unchanged from v6.5.0 apart from renames (not rerun on a pristine upstream checkout; upstream's top_bar_test does not compile against its own TopBar). flutter analyze lib: 0 errors; flutter test: 345 passed, 12 skipped; flutter build bundle compiles. Built with Flutter 3.41.9.
212 lines
6.5 KiB
Dart
212 lines
6.5 KiB
Dart
import "package:hash_wallet/core/execution_state.dart";
|
|
import "package:hash_wallet/exchange/limits_state.dart";
|
|
import "package:hash_wallet/new-ui/pages/swap_page.dart";
|
|
import "package:hash_wallet/new-ui/widgets/currency_picker/currency_picker_row.dart";
|
|
import "package:hash_wallet/new-ui/widgets/currency_picker/currency_picker_search_field.dart";
|
|
import "package:hash_wallet/new-ui/widgets/swap_page/swap_amount_box.dart";
|
|
import "package:hash_wallet/new-ui/widgets/swap_page/swap_confirm_sheet.dart";
|
|
import "package:hash_wallet/src/widgets/primary_button.dart";
|
|
import "package:hash_wallet/view_model/send/send_view_model_state.dart";
|
|
import "package:cw_core/crypto_currency.dart";
|
|
import "package:cw_core/wallet_type.dart";
|
|
import "package:flutter/material.dart";
|
|
import "package:flutter_test/flutter_test.dart";
|
|
|
|
import "../core/base_robot.dart";
|
|
import "../core/test_config.dart";
|
|
import "../core/test_wallets.dart";
|
|
|
|
class NewSwapPageRobot extends BaseRobot {
|
|
NewSwapPageRobot(super.tester);
|
|
|
|
@override
|
|
Future<void> isDisplayed() async {
|
|
await pumpUntilFound(find.byType(NewSwapPage));
|
|
}
|
|
|
|
Future<void> enterDepositAmount(String amount) async {
|
|
await enterTextByKey("swap_page_deposit_amount_field_key", amount);
|
|
}
|
|
|
|
Future<void> chooseReceiveCurrency(CryptoCurrency currency) async {
|
|
await tapByKey("swap_amount_box_receive_currency_button_key");
|
|
|
|
final search = find.descendant(
|
|
of: find.byType(CurrencyPickerSearchField),
|
|
matching: find.byType(EditableText),
|
|
);
|
|
|
|
await pumpUntilFound(search);
|
|
|
|
await tester.enterText(search.first, currency.title);
|
|
await settle(max: const Duration(seconds: 2));
|
|
|
|
await tapWhenVisible(
|
|
find.byWidgetPredicate(
|
|
(widget) => widget is CurrencyPickerRow && _isSameCurrency(widget.currency, currency),
|
|
),
|
|
);
|
|
|
|
final chosen = await pumpUntil(
|
|
() => _isSameCurrency(
|
|
tester.widget<NewSwapPage>(find.byType(NewSwapPage)).exchangeViewModel.receiveCurrency,
|
|
currency,
|
|
),
|
|
);
|
|
|
|
expect(
|
|
chosen,
|
|
true,
|
|
reason: "The picker did not switch the receive currency to ${currency.title}",
|
|
);
|
|
}
|
|
|
|
static bool _isSameCurrency(CryptoCurrency one, CryptoCurrency other) =>
|
|
one.title.toLowerCase() == other.title.toLowerCase() &&
|
|
(one.tag ?? "").toLowerCase() == (other.tag ?? "").toLowerCase();
|
|
|
|
Future<void> confirmQuoteReceived({Duration timeout = const Duration(seconds: 90)}) async {
|
|
final received = await pumpUntil(() => _bestRate() > 0, timeout: timeout);
|
|
|
|
expect(received, true, reason: "No provider quote arrived within ${timeout.inSeconds}s");
|
|
}
|
|
|
|
Future<void> enterMinimumViableDepositAmount() async {
|
|
final limitsLoaded = await pumpUntil(
|
|
() => _limitsState() is LimitsLoadedSuccessfully,
|
|
timeout: const Duration(seconds: 90),
|
|
);
|
|
|
|
expect(limitsLoaded, true, reason: "Provider limits never loaded");
|
|
|
|
final min = _limitsMin() ?? 0;
|
|
|
|
// 5 percent over the minimum, so a small rate move does not invalidate the trade.
|
|
final amount = min > 0 ? (min * 1.05).toStringAsFixed(8) : "0.01";
|
|
await enterDepositAmount(amount);
|
|
}
|
|
|
|
Future<String> enterTestReceiveAddress() async {
|
|
final exchangeViewModel =
|
|
tester.widget<NewSwapPage>(find.byType(NewSwapPage)).exchangeViewModel;
|
|
final receiveType = cryptoCurrencyOrTokenToWalletType(exchangeViewModel.receiveCurrency);
|
|
final address = receiveType == null ? "" : TestWallets.receiveAddressFor(receiveType);
|
|
|
|
expect(
|
|
address.isNotEmpty,
|
|
true,
|
|
reason: "No test receive address for ${exchangeViewModel.receiveCurrency.title}",
|
|
);
|
|
|
|
final receiveCard = find.byWidgetPredicate(
|
|
(widget) => widget is SwapAmountBox && widget.isReceiverCard,
|
|
);
|
|
|
|
tester.state<SwapAmountBoxState>(receiveCard).addressController.text = address;
|
|
await settle();
|
|
|
|
return address;
|
|
}
|
|
|
|
Future<void> confirmSwapButtonEnabled({Duration timeout = TestConfig.walletSyncBudget}) async {
|
|
final button = find.byKey(const ValueKey("exchange_page_exchange_button_key"));
|
|
|
|
final enabled = await pumpUntil(
|
|
() => tester.any(button) && !tester.widget<LoadingPrimaryButton>(button).isDisabled,
|
|
timeout: timeout,
|
|
);
|
|
|
|
expect(
|
|
enabled,
|
|
true,
|
|
reason: "The swap button stayed disabled with an amount, a quote and a receive address",
|
|
);
|
|
}
|
|
|
|
Future<void> tapSwapButton() async {
|
|
await tapByKey("exchange_page_exchange_button_key");
|
|
}
|
|
|
|
Future<void> confirmTradeCreated({Duration timeout = const Duration(minutes: 2)}) async {
|
|
await pumpUntilFound(find.byType(SwapConfirmSheet), timeout: timeout);
|
|
}
|
|
|
|
void confirmPayoutAddress(String expected) {
|
|
final sheet = tester.widget<SwapConfirmSheet>(find.byType(SwapConfirmSheet));
|
|
final payout = sheet.exchangeTradeViewModel.trade.payoutAddress ?? "";
|
|
final isHex = expected.startsWith("0x");
|
|
|
|
expect(
|
|
isHex ? payout.toLowerCase() : payout,
|
|
isHex ? expected.toLowerCase() : expected,
|
|
reason: "The trade pays out somewhere other than the test wallet",
|
|
);
|
|
}
|
|
|
|
Future<void> confirmDepositCommitted({Duration timeout = const Duration(minutes: 3)}) async {
|
|
ExecutionState? lastState;
|
|
|
|
final committed = await pumpUntil(
|
|
() {
|
|
final sheet = find.byType(SwapConfirmSheet);
|
|
|
|
if (!tester.any(sheet)) {
|
|
return true;
|
|
}
|
|
|
|
lastState =
|
|
tester.widget<SwapConfirmSheet>(sheet).exchangeTradeViewModel.sendViewModel.state;
|
|
|
|
return lastState is TransactionCommitted;
|
|
},
|
|
timeout: timeout,
|
|
);
|
|
|
|
expect(
|
|
committed,
|
|
true,
|
|
reason: "The deposit never committed within ${timeout.inMinutes}m, "
|
|
"the sheet reported ${lastState.runtimeType}",
|
|
);
|
|
|
|
expect(
|
|
lastState,
|
|
isA<TransactionCommitted>(),
|
|
reason: "The confirm sheet closed before the deposit committed, "
|
|
"it last reported ${lastState.runtimeType}",
|
|
);
|
|
|
|
await pumpUntilGone(find.byType(NewSwapPage));
|
|
}
|
|
|
|
double? _limitsMin() {
|
|
final finder = find.byType(NewSwapPage);
|
|
|
|
if (!tester.any(finder)) {
|
|
return null;
|
|
}
|
|
|
|
return tester.widget<NewSwapPage>(finder.first).exchangeViewModel.limits.min;
|
|
}
|
|
|
|
LimitsState? _limitsState() {
|
|
final finder = find.byType(NewSwapPage);
|
|
|
|
if (!tester.any(finder)) {
|
|
return null;
|
|
}
|
|
|
|
return tester.widget<NewSwapPage>(finder.first).exchangeViewModel.limitsState;
|
|
}
|
|
|
|
double _bestRate() {
|
|
final finder = find.byType(NewSwapPage);
|
|
|
|
if (!tester.any(finder)) {
|
|
return 0;
|
|
}
|
|
|
|
return tester.widget<NewSwapPage>(finder.first).exchangeViewModel.bestRate;
|
|
}
|
|
}
|