Files
hash-wallet/test/utils/payment_request_test.dart
T
jwinterm dd449f2594 Merge upstream Cake Wallet v6.5.0
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.
2026-10-24 23:49:29 -04:00

125 lines
4.7 KiB
Dart

import "package:hash_wallet/utils/payment_request.dart";
import "package:cw_core/erc20_token.dart";
import "package:flutter_test/flutter_test.dart";
void main() {
group("PaymentRequest", () {
group("Ethereum URIs", () {
test("extract address and raw token amount from EIP681 Uri with contract", () {
final uri = Uri.parse(
"ethereum:0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174@1/transfer?address=0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41&uint256=2000000000000000000",
);
final paymentRequest = PaymentRequest.fromUri(uri);
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
expect(paymentRequest.amount, "");
expect(paymentRequest.rawTokenAmount, "2000000000000000000");
});
test("extract address and amount from EIP681 Uri", () {
final uri = Uri.parse(
"ethereum:0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41@1?value=2000000000000000000",
);
final paymentRequest = PaymentRequest.fromUri(uri);
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
expect(paymentRequest.amount, "2");
});
test("extract address and amount from Cake Style Uri", () {
final uri = Uri.parse("ethereum:0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41@1?amount=2.00");
final paymentRequest = PaymentRequest.fromUri(uri);
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
expect(paymentRequest.amount, "2.00");
});
test("extract address from EIP681 Uri with contract", () {
final uri = Uri.parse(
"ethereum:0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174@1/transfer?address=0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41",
);
final paymentRequest = PaymentRequest.fromUri(uri);
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
expect(paymentRequest.amount, "");
});
test("extract address and raw token amount from EIP681 Uri with contract and no chainId", () {
final uri = Uri.parse(
"ethereum:0x1234567890abcdef1234567890abcdef12345678/transfer?address=0xabcdef1234567890abcdef1234567890abcdef12&uint256=1000000000000000000",
);
final paymentRequest = PaymentRequest.fromUri(uri);
expect(paymentRequest.address, "0xabcdef1234567890abcdef1234567890abcdef12");
expect(paymentRequest.amount, "");
expect(paymentRequest.rawTokenAmount, "1000000000000000000");
});
test("extract address from minimal EIP681 Uri", () {
final uri = Uri.parse("ethereum:0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
final paymentRequest = PaymentRequest.fromUri(uri);
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
expect(paymentRequest.amount, "");
});
});
group("resolveTokenAmount", () {
final usdt = Erc20Token(
name: "Tether",
symbol: "USDT",
contractAddress: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
decimal: 6,
);
final dai = Erc20Token(
name: "Dai",
symbol: "DAI",
contractAddress: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
decimal: 18,
);
test("converts the raw uint256 using the token decimals", () {
final uri = Uri.parse(
"ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7@1/transfer?address=0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41&uint256=1000000",
);
final paymentRequest = PaymentRequest.fromUri(uri);
expect(paymentRequest.resolveTokenAmount(usdt), "1");
});
test("converts an 18 decimal raw amount unchanged", () {
final paymentRequest =
PaymentRequest("addr", "", "", "ethereum", null, rawTokenAmount: "1500000000000000000");
expect(paymentRequest.resolveTokenAmount(dai), "1.5");
});
test("falls back to the legacy 18 decimal reading for implausibly large amounts", () {
final paymentRequest = PaymentRequest(
"addr",
"",
"",
"ethereum",
null,
rawTokenAmount: "50000000000000000000",
);
expect(paymentRequest.resolveTokenAmount(usdt), "50");
});
test("prefers the decimal amount over the raw token amount", () {
final paymentRequest =
PaymentRequest("addr", "2.5", "", "ethereum", null, rawTokenAmount: "1000000");
expect(paymentRequest.resolveTokenAmount(usdt), "2.5");
});
test("returns null when there is no amount at all", () {
final paymentRequest = PaymentRequest("addr", "", "", "ethereum", null);
expect(paymentRequest.resolveTokenAmount(usdt), null);
});
});
});
}