MOAD-0001 (CWE-407): - cake_wallet-0001: exchange_view_model token injection List.any() O(T*L), 275x - cake_wallet-0002: currency_pairs_utils/pairs_utils List.contains() O(ALL*N), 139x - cake_wallet-0003: monero/wownero _usedAddresses List.contains() O(S*U), 275x MOAD-0004 (CWE-312): - cake_wallet-0004: zcash_taddress_rotation prints wallet seeds to verbose log MOAD-0002: NOTED (SettingsStore 2228 lines, DI 1765 lines, global currentWallet) MOAD-0003: CLEAN (no Zone.current / zone-scoped wallet identity) MOAD-0005: CLEAN (Dart single-threaded, no concurrent cache races) 8/8 unit tests PASS
78 lines
2.3 KiB
Dart
78 lines
2.3 KiB
Dart
/// Unit test for cake_wallet-0002: currency_pairs_utils / pairs_utils
|
|
/// List.contains() O(ALL * N) for filtering notSupported currencies.
|
|
|
|
int opsDefect = 0;
|
|
int opsFix = 0;
|
|
|
|
class FakeCurrency {
|
|
final int raw;
|
|
FakeCurrency(this.raw);
|
|
@override
|
|
bool operator ==(Object other) => other is FakeCurrency && other.raw == raw;
|
|
@override
|
|
int get hashCode => raw.hashCode;
|
|
}
|
|
|
|
void main() {
|
|
// CryptoCurrency.all has ~278 entries; notSupported varies by provider
|
|
final allCurrencies = List.generate(278, (i) => FakeCurrency(i));
|
|
|
|
// DFX has ~270 not-supported (only 7 supported)
|
|
final notSupported = List.generate(270, (i) => FakeCurrency(i + 8));
|
|
|
|
// --- Defect: List.contains per element ---
|
|
opsDefect = 0;
|
|
final resultDefect = allCurrencies.where((crypto) {
|
|
for (final ns in notSupported) {
|
|
opsDefect++;
|
|
if (ns == crypto) return false;
|
|
}
|
|
return true;
|
|
}).toList();
|
|
|
|
// --- Fix: Set.contains per element ---
|
|
opsFix = 0;
|
|
final notSupportedSet = notSupported.toSet();
|
|
final resultFix = allCurrencies.where((crypto) {
|
|
opsFix++;
|
|
return !notSupportedSet.contains(crypto);
|
|
}).toList();
|
|
|
|
assert(resultDefect.length == resultFix.length,
|
|
'FAIL: results differ (${resultDefect.length} vs ${resultFix.length})');
|
|
|
|
final ratio = opsDefect / opsFix;
|
|
print('ALL=278 notSupported=270: defect=$opsDefect fix=$opsFix ratio=${ratio.toStringAsFixed(1)}x '
|
|
'${ratio > 2 ? "PASS" : "FAIL"}');
|
|
assert(ratio > 2, 'FAIL: expected speedup, got ${ratio}x');
|
|
|
|
// Also test the supportedPairs pattern (Cartesian product)
|
|
// With 278 all and 100 not-supported:
|
|
final notSupported2 = List.generate(100, (i) => FakeCurrency(i));
|
|
opsDefect = 0;
|
|
opsFix = 0;
|
|
|
|
// Defect
|
|
final supported1 = allCurrencies.where((e) {
|
|
for (final ns in notSupported2) {
|
|
opsDefect++;
|
|
if (ns == e) return false;
|
|
}
|
|
return true;
|
|
}).toList();
|
|
|
|
// Fix
|
|
final ns2Set = notSupported2.toSet();
|
|
final supported2 = allCurrencies.where((e) {
|
|
opsFix++;
|
|
return !ns2Set.contains(e);
|
|
}).toList();
|
|
|
|
assert(supported1.length == supported2.length);
|
|
final ratio2 = opsDefect / opsFix;
|
|
print('ALL=278 notSupported=100: defect=$opsDefect fix=$opsFix ratio=${ratio2.toStringAsFixed(1)}x '
|
|
'${ratio2 > 2 ? "PASS" : "FAIL"}');
|
|
assert(ratio2 > 2);
|
|
|
|
print('cake_wallet-0002: ALL PASS');
|
|
}
|