games_app/prediqo_mobile/test/wallet_money_flows_section_test.dart
2026-10-25 20:49:23 +02:00

141 lines
3.7 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:prediqo_mobile/data/models/balance_model.dart';
import 'package:prediqo_mobile/data/models/test_wallet_models.dart';
import 'package:prediqo_mobile/data/models/transaction_model.dart';
import 'package:prediqo_mobile/data/models/wallet_type_model.dart';
import 'package:prediqo_mobile/data/repositories/wallet_repository_impl.dart';
import 'package:prediqo_mobile/domain/repositories/health_repository.dart';
import 'package:prediqo_mobile/features/wallet/utils/money_confirm_preflight.dart';
const _usdt = WalletTypeModel(
id: 1,
code: 'USDT_TRC20',
name: 'USDT',
network: 'TRON',
decimals: 6,
depositEnabled: true,
withdrawEnabled: true,
);
class _ControllableWallet implements WalletRepository {
var balancesCalls = 0;
@override
Future<List<WalletTypeModel>> getWalletTypes() async => const [_usdt];
@override
Future<List<BalanceModel>> getBalances() async {
balancesCalls++;
return [
BalanceModel(
walletType: _usdt,
available: '10690000',
locked: '0',
),
];
}
@override
Future<DepositAddressResult> getDepositAddress(String walletType) async =>
DepositAddressResult(address: 'TADDR', walletType: _usdt);
@override
Future<List<TransactionModel>> getTransactions({
int limit = 50,
int offset = 0,
String? category,
}) async =>
const [];
@override
Future<WithdrawResult> withdraw(
String walletType,
String toAddress,
String amount, {
String? totpCode,
}) async =>
const WithdrawResult(transactionId: 'w1', status: 'pending');
@override
Future<TransferResult> transfer(
String toEmail,
String walletType,
String amount, {
String? totpCode,
}) async =>
const TransferResult(transactionId: 't1', status: 'completed');
@override
Future<TestWalletStatusModel> getTestWalletStatus() async =>
const TestWalletStatusModel(
enabled: false,
balanceRaw: '0',
walletTypeId: 1,
decimals: 6,
creditAmountRaw: '0',
maxRequests: 0,
requestsUsed: 0,
canRequest: false,
);
@override
Future<TestWalletCreditResult> requestTestCredits() async =>
throw UnimplementedError();
}
class _ControllableHealth implements HealthRepository {
var healthCalls = 0;
final bool withdrawalsEnabled;
_ControllableHealth({this.withdrawalsEnabled = true});
@override
Future<HealthStatus> getHealth({bool force = false}) async {
healthCalls++;
return HealthStatus(
network: 'mainnet',
withdrawalsEnabled: withdrawalsEnabled,
env: 'test',
withdrawalNetworkFeeRaw: '1000000',
);
}
@override
HealthStatus? peekLast() => null;
@override
void invalidate() {}
}
void main() {
test('money confirm preflight always fetches balances + health fresh', () async {
final wallet = _ControllableWallet();
final health = _ControllableHealth();
final first = await fetchMoneyConfirmPreflight(
walletRepo: wallet,
healthRepo: health,
);
final second = await fetchMoneyConfirmPreflight(
walletRepo: wallet,
healthRepo: health,
);
expect(wallet.balancesCalls, 2);
expect(health.healthCalls, 2);
expect(first.balances.single.available, '10690000');
expect(second.health.withdrawalNetworkFeeRaw, '1000000');
expect(second.health.withdrawalsEnabled, isTrue);
});
test('money confirm preflight surfaces health disable flag', () async {
final wallet = _ControllableWallet();
final health = _ControllableHealth(withdrawalsEnabled: false);
final result = await fetchMoneyConfirmPreflight(
walletRepo: wallet,
healthRepo: health,
);
expect(result.health.withdrawalsEnabled, isFalse);
});
}