mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-28 06:28:41 +01:00
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.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:hash_wallet/entities/parse_address_from_domain.dart';
|
||||
import 'package:hash_wallet/core/address_resolver/address_resolver_utils.dart';
|
||||
import 'package:hash_wallet/core/address_resolver/unstoppable/unstoppable_address_provider.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -8,7 +9,7 @@ void main() {
|
||||
// late MockWalletBase mockWallet;
|
||||
// late MockSettingsStore mockSettingsStore;
|
||||
// late MockBuildContext mockContext;
|
||||
// late AddressResolver addressResolver;
|
||||
// late AddressResolver addressResolverUtils;
|
||||
//
|
||||
// setUp(() {
|
||||
// mockYatService = MockYatService();
|
||||
@@ -19,7 +20,7 @@ void main() {
|
||||
// when(mockWallet.type).thenReturn(WalletType.bitcoin);
|
||||
// when(mockWallet.currency).thenReturn(CryptoCurrency.btc);
|
||||
//
|
||||
// addressResolver = AddressResolver(
|
||||
// addressResolverUtils = AddressResolverUtils(
|
||||
// yatService: mockYatService,
|
||||
// wallet: mockWallet,
|
||||
// settingsStore: mockSettingsStore,
|
||||
@@ -30,7 +31,7 @@ void main() {
|
||||
test('extracts Bitcoin address correctly', () {
|
||||
final raw =
|
||||
'My Bitcoin address is bc1qhg4l43pmq5v5atmtlr7gnwyuxs043cvrut5hkq please use it';
|
||||
final result = AddressResolver.extractAddressByType(
|
||||
final result = AddressResolverUtils.extractAddressByType(
|
||||
raw: raw,
|
||||
type: CryptoCurrency.btc,
|
||||
);
|
||||
@@ -39,7 +40,7 @@ void main() {
|
||||
|
||||
test('extracts Ethereum address correctly', () {
|
||||
final raw = 'Send ETH to 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 thanks';
|
||||
final result = AddressResolver.extractAddressByType(
|
||||
final result = AddressResolverUtils.extractAddressByType(
|
||||
raw: raw,
|
||||
type: CryptoCurrency.eth,
|
||||
);
|
||||
@@ -49,7 +50,7 @@ void main() {
|
||||
test('extracts Monero address correctly', () {
|
||||
final raw =
|
||||
'XMR: 85s6zfxGAkdCN21h566R8EFDSfThxCrFiEkhw3JEtaXN2DDfahABLXTjRj385Ro7om5saGWJG7iuE6EyW5MYcoz93DLvNqh';
|
||||
final result = AddressResolver.extractAddressByType(
|
||||
final result = AddressResolverUtils.extractAddressByType(
|
||||
raw: raw,
|
||||
type: CryptoCurrency.xmr,
|
||||
);
|
||||
@@ -59,7 +60,7 @@ void main() {
|
||||
|
||||
test('extracts Bitcoin Cash address correctly', () {
|
||||
final raw = 'BCH: bitcoincash:qr2z7dusk64qnq97azhg0u0hlf7qgwwfzyj92jgmqj';
|
||||
final result = AddressResolver.extractAddressByType(
|
||||
final result = AddressResolverUtils.extractAddressByType(
|
||||
raw: raw,
|
||||
type: CryptoCurrency.bch,
|
||||
);
|
||||
@@ -68,7 +69,7 @@ void main() {
|
||||
|
||||
test('extracts Nano address correctly', () {
|
||||
final raw = 'NANO: nano_1natrium1o3z5519ifou7xii8crpxpk8y65qmkih8e8bpsjri651oza8imdd';
|
||||
final result = AddressResolver.extractAddressByType(
|
||||
final result = AddressResolverUtils.extractAddressByType(
|
||||
raw: raw,
|
||||
type: CryptoCurrency.nano,
|
||||
);
|
||||
@@ -78,13 +79,13 @@ void main() {
|
||||
test('returns null for unsupported currency', () {
|
||||
final raw = 'Some text without an address';
|
||||
expect(
|
||||
() => AddressResolver.extractAddressByType(
|
||||
() => AddressResolverUtils.extractAddressByType(
|
||||
raw: raw,
|
||||
type: CryptoCurrency.btc,
|
||||
),
|
||||
returnsNormally);
|
||||
|
||||
final result = AddressResolver.extractAddressByType(
|
||||
final result = AddressResolverUtils.extractAddressByType(
|
||||
raw: raw,
|
||||
type: CryptoCurrency.btc,
|
||||
);
|
||||
@@ -94,7 +95,7 @@ void main() {
|
||||
test('extracts monero address from URI', () {
|
||||
final raw =
|
||||
'monero_wallet:467iotZU5tvG26k2xdZWkJ7gwATFVhfbuV3yDoWx5jHoPwxEi4f5BuJQwkP6GpCb1sZvUVB7nbSkgEuW8NKrh9KKRRga5qz?spend_key=029c559cd7669f14e91fd835144916009f8697ab5ac5c7f7c06e1ff869c17b0b&view_key=afaf646edbff3d3bcee8efd3383ffe5d20c947040f74e1110b70ca0fbb0ef90d';
|
||||
final result = AddressResolver.extractAddressByType(
|
||||
final result = AddressResolverUtils.extractAddressByType(
|
||||
raw: raw, type: CryptoCurrency.xmr, requireSurroundingWhitespaces: false);
|
||||
expect(result,
|
||||
'467iotZU5tvG26k2xdZWkJ7gwATFVhfbuV3yDoWx5jHoPwxEi4f5BuJQwkP6GpCb1sZvUVB7nbSkgEuW8NKrh9KKRRga5qz');
|
||||
@@ -111,13 +112,16 @@ sp1qq0avpawwjg4l66p6lqafj0vlvm6rlhdc6qt0r6dfual835vhs3gvkq63pechaqezvn7j7uj2jucw
|
||||
#LTC MWEB
|
||||
ltcmweb1qq0at62jjucmawxp78qutn0cqwkwahcfx7fxls0r2ma5llg5w6wyy2qe20gxa3rku2658j88zg9d2j4ttpw35k0a5nrg93h5nq3wyvkcgwc3q4dgc
|
||||
''';
|
||||
final resultXmr = AddressResolver.extractAddressByType(raw: raw, type: CryptoCurrency.xmr);
|
||||
final resultXmr =
|
||||
AddressResolverUtils.extractAddressByType(raw: raw, type: CryptoCurrency.xmr);
|
||||
expect(resultXmr,
|
||||
'89bH6i3ftaWSWuPJJYSQuuApWJ8xzinCEbbnAXN1Z3mGGUuAFdpBUg82R9MvJDSheJ6kW2dyMQEFUGM4tsZqRb2Q75UXqvc');
|
||||
final resultBtc = AddressResolver.extractAddressByType(raw: raw, type: CryptoCurrency.btc);
|
||||
final resultBtc =
|
||||
AddressResolverUtils.extractAddressByType(raw: raw, type: CryptoCurrency.btc);
|
||||
expect(resultBtc,
|
||||
'sp1qq0avpawwjg4l66p6lqafj0vlvm6rlhdc6qt0r6dfual835vhs3gvkq63pechaqezvn7j7uj2jucwj5k7nenpw2r86wf42xv6wqdvxuk5rggrul45');
|
||||
final resultLtc = AddressResolver.extractAddressByType(raw: raw, type: CryptoCurrency.ltc);
|
||||
final resultLtc =
|
||||
AddressResolverUtils.extractAddressByType(raw: raw, type: CryptoCurrency.ltc);
|
||||
expect(resultLtc,
|
||||
'ltcmweb1qq0at62jjucmawxp78qutn0cqwkwahcfx7fxls0r2ma5llg5w6wyy2qe20gxa3rku2658j88zg9d2j4ttpw35k0a5nrg93h5nq3wyvkcgwc3q4dgc');
|
||||
});
|
||||
@@ -125,7 +129,7 @@ ltcmweb1qq0at62jjucmawxp78qutn0cqwkwahcfx7fxls0r2ma5llg5w6wyy2qe20gxa3rku2658j88
|
||||
// test('throws exception for unexpected token', () {
|
||||
// // Create a custom crypto currency that won't have a pattern
|
||||
// final customCurrency = CryptoCurrency('CUSTOM', 'Custom');
|
||||
// expect(() => AddressResolver.extractAddressByType(
|
||||
// expect(() => AddressResolverUtils.extractAddressByType(
|
||||
// raw: 'Some text',
|
||||
// type: customCurrency,
|
||||
// ), throwsException);
|
||||
@@ -134,25 +138,25 @@ ltcmweb1qq0at62jjucmawxp78qutn0cqwkwahcfx7fxls0r2ma5llg5w6wyy2qe20gxa3rku2658j88
|
||||
//
|
||||
// group('isEmailFormat', () {
|
||||
// test('returns true for valid email format', () {
|
||||
// expect(addressResolver.isEmailFormat('user@example.com'), isTrue);
|
||||
// expect(addressResolver.isEmailFormat('name.surname@domain.co.uk'), isTrue);
|
||||
// expect(addressResolver.isEmailFormat('user123@subdomain.example.org'), isTrue);
|
||||
// expect(addressResolverUtils.isEmailFormat('user@example.com'), isTrue);
|
||||
// expect(addressResolverUtils.isEmailFormat('name.surname@domain.co.uk'), isTrue);
|
||||
// expect(addressResolverUtils.isEmailFormat('user123@subdomain.example.org'), isTrue);
|
||||
// });
|
||||
//
|
||||
// test('returns false for invalid email format', () {
|
||||
// expect(addressResolver.isEmailFormat('user@'), isFalse);
|
||||
// expect(addressResolver.isEmailFormat('@domain.com'), isFalse);
|
||||
// expect(addressResolver.isEmailFormat('user@domain'), isFalse);
|
||||
// expect(addressResolver.isEmailFormat('user.domain.com'), isFalse);
|
||||
// expect(addressResolver.isEmailFormat('user@domain@com'), isFalse);
|
||||
// expect(addressResolver.isEmailFormat('bc1qhg4l43pmq5v5atmtlr7gnwyuxs043cvrut5hkq'), isFalse);
|
||||
// expect(addressResolverUtils.isEmailFormat('user@'), isFalse);
|
||||
// expect(addressResolverUtils.isEmailFormat('@domain.com'), isFalse);
|
||||
// expect(addressResolverUtils.isEmailFormat('user@domain'), isFalse);
|
||||
// expect(addressResolverUtils.isEmailFormat('user.domain.com'), isFalse);
|
||||
// expect(addressResolverUtils.isEmailFormat('user@domain@com'), isFalse);
|
||||
// expect(addressResolverUtils.isEmailFormat('bc1qhg4l43pmq5v5atmtlr7gnwyuxs043cvrut5hkq'), isFalse);
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// group('resolve', () {
|
||||
// test('returns ParsedAddress with original text when no resolution is possible', () async {
|
||||
// final text = 'bc1qhg4l43pmq5v5atmtlr7gnwyuxs043cvrut5hkq';
|
||||
// final result = await addressResolver.resolve(mockContext, text, CryptoCurrency.btc);
|
||||
// final result = await addressResolverUtils.resolve(mockContext, text, CryptoCurrency.btc);
|
||||
//
|
||||
// expect(result, isA<ParsedAddress>());
|
||||
// expect(result.addresses, [text]);
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
import "dart:io";
|
||||
|
||||
import "package:hash_wallet/entities/saved_nfts.dart";
|
||||
import "package:hash_wallet/entities/solana_nft_asset_model.dart";
|
||||
import "package:hash_wallet/entities/wallet_nft_response.dart";
|
||||
import "package:cw_core/db/sqlite.dart";
|
||||
import "package:cw_core/imported_nft.dart";
|
||||
import "package:flutter_test/flutter_test.dart";
|
||||
import "package:path_provider_platform_interface/path_provider_platform_interface.dart";
|
||||
import "package:sqflite_common_ffi/sqflite_ffi.dart";
|
||||
|
||||
class _FakePathProviderPlatform extends PathProviderPlatform {
|
||||
_FakePathProviderPlatform(this.root);
|
||||
|
||||
final String root;
|
||||
|
||||
@override
|
||||
Future<String?> getApplicationDocumentsPath() async => root;
|
||||
|
||||
@override
|
||||
Future<String?> getApplicationSupportPath() async => root;
|
||||
}
|
||||
|
||||
SolanaNFTAssetModel solanaNFT(String mint, {String? name, bool? isOwned}) =>
|
||||
SolanaNFTAssetModel(mint: mint, address: mint, name: name ?? mint, isOwned: isOwned);
|
||||
|
||||
Future<void> main() async {
|
||||
final dataRoot = Directory("./test/data/saved_nfts");
|
||||
|
||||
const wallet = "MyWallet";
|
||||
const otherWallet = "OtherWallet";
|
||||
const otherChain = "eth";
|
||||
|
||||
final saved = SavedNFTs();
|
||||
|
||||
setUpAll(() async {
|
||||
if (dataRoot.existsSync()) {
|
||||
dataRoot.deleteSync(recursive: true);
|
||||
}
|
||||
dataRoot.createSync(recursive: true);
|
||||
Directory("${dataRoot.path}/cake_wallet").createSync(recursive: true);
|
||||
|
||||
PathProviderPlatform.instance = _FakePathProviderPlatform(dataRoot.absolute.path);
|
||||
|
||||
sqfliteFfiInit();
|
||||
databaseFactory = databaseFactoryFfi;
|
||||
await initDb();
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await db!.delete(ImportedNFT.tableName);
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
if (dataRoot.existsSync()) {
|
||||
dataRoot.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
group("SavedNFTs, solana", () {
|
||||
test("keeps what was added and reads it back", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA", name: "Ape", isOwned: true));
|
||||
|
||||
final stored = await saved.solanaNFTs(wallet);
|
||||
|
||||
expect(stored.keys, ["MintA"]);
|
||||
expect(stored["MintA"]!.name, "Ape");
|
||||
expect(stored["MintA"]!.isOwned, isTrue);
|
||||
});
|
||||
|
||||
test("keeps wallets and chains apart", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA"));
|
||||
|
||||
expect(await saved.solanaNFTs(otherWallet), isEmpty);
|
||||
expect(await saved.evmNFTs(wallet, otherChain), isEmpty);
|
||||
});
|
||||
|
||||
test("adding the same mint twice replaces it rather than duplicating", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA", name: "first"));
|
||||
await saved.addSolana(wallet, solanaNFT("MintA", name: "second"));
|
||||
|
||||
final stored = await saved.solanaNFTs(wallet);
|
||||
|
||||
expect(stored.length, 1);
|
||||
expect(stored["MintA"]!.name, "second");
|
||||
});
|
||||
|
||||
test("ignores an asset with no mint", () async {
|
||||
await saved.addSolana(wallet, SolanaNFTAssetModel(address: "x"));
|
||||
|
||||
expect(await saved.solanaNFTs(wallet), isEmpty);
|
||||
});
|
||||
|
||||
test("removes what was sent", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA"));
|
||||
await saved.removeSolana(wallet, "MintA");
|
||||
|
||||
expect(await saved.solanaNFTs(wallet), isEmpty);
|
||||
});
|
||||
|
||||
test("refresh updates what is still saved and does not add anything new", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA", name: "old", isOwned: true));
|
||||
|
||||
await saved.refreshSolana(wallet, [
|
||||
solanaNFT("MintA", name: "new", isOwned: false),
|
||||
solanaNFT("MintB", name: "never imported"),
|
||||
]);
|
||||
|
||||
final stored = await saved.solanaNFTs(wallet);
|
||||
|
||||
expect(stored.keys, ["MintA"]);
|
||||
expect(stored["MintA"]!.name, "new");
|
||||
expect(stored["MintA"]!.isOwned, isFalse);
|
||||
});
|
||||
|
||||
// A refresh runs for seconds while it fetches metadata per mint, and the
|
||||
// user can import during it.
|
||||
test("an import that lands during a refresh is not lost", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA", name: "old"));
|
||||
|
||||
final refreshing = saved.refreshSolana(wallet, [solanaNFT("MintA", name: "refreshed")]);
|
||||
final importing = saved.addSolana(wallet, solanaNFT("MintNew", name: "imported"));
|
||||
|
||||
await Future.wait([refreshing, importing]);
|
||||
|
||||
final stored = await saved.solanaNFTs(wallet);
|
||||
|
||||
expect(stored.keys.toSet(), {"MintA", "MintNew"});
|
||||
expect(stored["MintA"]!.name, "refreshed");
|
||||
});
|
||||
|
||||
test("an import during a refresh survives whichever order they run in", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA"));
|
||||
|
||||
final importing = saved.addSolana(wallet, solanaNFT("MintNew"));
|
||||
final refreshing = saved.refreshSolana(wallet, [solanaNFT("MintA", name: "refreshed")]);
|
||||
|
||||
await Future.wait([importing, refreshing]);
|
||||
|
||||
expect((await saved.solanaNFTs(wallet)).keys.toSet(), {"MintA", "MintNew"});
|
||||
});
|
||||
|
||||
test("an NFT sent during a refresh is not put back", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA"));
|
||||
|
||||
final sending = saved.removeSolana(wallet, "MintA");
|
||||
final refreshing = saved.refreshSolana(wallet, [solanaNFT("MintA", name: "refreshed")]);
|
||||
|
||||
await Future.wait([sending, refreshing]);
|
||||
|
||||
expect(await saved.solanaNFTs(wallet), isEmpty);
|
||||
});
|
||||
|
||||
test("an NFT sent after a refresh has already read the rows is not put back", () async {
|
||||
await saved.addSolana(wallet, solanaNFT("MintA"));
|
||||
|
||||
// The refresh starts first here, so its read of the rows is queued ahead of
|
||||
// the delete. That is the ordering a real send hits: the user taps send
|
||||
// while a refresh is already in flight.
|
||||
final refreshing = saved.refreshSolana(wallet, [solanaNFT("MintA", name: "refreshed")]);
|
||||
final sending = saved.removeSolana(wallet, "MintA");
|
||||
|
||||
await Future.wait([refreshing, sending]);
|
||||
|
||||
expect(await saved.solanaNFTs(wallet), isEmpty);
|
||||
});
|
||||
|
||||
test("many overlapping writes all land", () async {
|
||||
await Future.wait([
|
||||
for (var i = 0; i < 20; i++) saved.addSolana(wallet, solanaNFT("Mint$i")),
|
||||
]);
|
||||
|
||||
expect((await saved.solanaNFTs(wallet)).length, 20);
|
||||
});
|
||||
});
|
||||
|
||||
group("SavedNFTs, evm", () {
|
||||
NFTAssetModel evmNFT(String address, String tokenId, {String? name}) => NFTAssetModel(
|
||||
tokenAddress: address,
|
||||
tokenId: tokenId,
|
||||
name: name ?? address,
|
||||
symbol: "SYM",
|
||||
normalizedMetadata: NormalizedMetadata(
|
||||
name: name,
|
||||
description: "a description",
|
||||
image: "ipfs://QmAbC",
|
||||
),
|
||||
);
|
||||
|
||||
test("an imported evm nft survives a restart", () async {
|
||||
await saved.addEvm(wallet, otherChain, evmNFT("0xabc", "7", name: "Punk"));
|
||||
|
||||
final stored = await saved.evmNFTs(wallet, otherChain);
|
||||
|
||||
expect(stored.length, 1);
|
||||
expect(stored.first.tokenAddress, "0xabc");
|
||||
expect(stored.first.tokenId, "7");
|
||||
expect(stored.first.name, "Punk");
|
||||
expect(stored.first.normalizedMetadata?.description, "a description");
|
||||
});
|
||||
|
||||
test("stores the ipfs image through the shared gateway", () async {
|
||||
await saved.addEvm(wallet, otherChain, evmNFT("0xabc", "7"));
|
||||
|
||||
final stored = await saved.evmNFTs(wallet, otherChain);
|
||||
|
||||
expect(stored.first.normalizedMetadata?.imageUrl, "https://ipfs.io/ipfs/QmAbC");
|
||||
});
|
||||
|
||||
test("tells two token ids of one contract apart", () async {
|
||||
await saved.addEvm(wallet, otherChain, evmNFT("0xabc", "7"));
|
||||
await saved.addEvm(wallet, otherChain, evmNFT("0xabc", "8"));
|
||||
|
||||
expect((await saved.evmNFTs(wallet, otherChain)).length, 2);
|
||||
});
|
||||
|
||||
test("keeps evm and solana entries apart by chain", () async {
|
||||
await saved.addEvm(wallet, otherChain, evmNFT("0xabc", "7"));
|
||||
await saved.addSolana(wallet, solanaNFT("MintA"));
|
||||
|
||||
expect((await saved.evmNFTs(wallet, otherChain)).length, 1);
|
||||
expect((await saved.solanaNFTs(wallet)).length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import "package:hash_wallet/entities/solana_nft_asset_model.dart";
|
||||
import "package:cw_core/utils/nft_text.dart";
|
||||
import "package:hash_wallet/entities/wallet_nft_response.dart";
|
||||
import "package:flutter_test/flutter_test.dart";
|
||||
|
||||
void main() {
|
||||
group("SolanaNFTAssetModel", () {
|
||||
Map<String, dynamic> json({String name = "DeGod", bool? isOwned}) => {
|
||||
"address": "MintAddr",
|
||||
"mint": "MintAddr",
|
||||
"standard": "metaplex",
|
||||
"name": name,
|
||||
"symbol": "DGOD",
|
||||
"description": "a description",
|
||||
"imageOriginalUrl": "ipfs://QmAbC123",
|
||||
"externalUrl": "https://example.com",
|
||||
"metadataOriginalUrl": "https://example.com/meta.json",
|
||||
"totalSupply": "1",
|
||||
"isOwned": isOwned,
|
||||
};
|
||||
|
||||
test("sanitises the text a mint controls", () {
|
||||
final asset = SolanaNFTAssetModel.fromJson(json(name: "Ape\u2028Address: 9xQeW"));
|
||||
|
||||
expect(asset.name, "Ape Address: 9xQeW");
|
||||
});
|
||||
|
||||
test("routes an ipfs image through the gateway", () {
|
||||
expect(
|
||||
SolanaNFTAssetModel.fromJson(json()).imageOriginalUrl,
|
||||
"https://ipfs.io/ipfs/QmAbC123",
|
||||
);
|
||||
});
|
||||
|
||||
test("reads the fields the indexer actually sends", () {
|
||||
final asset = SolanaNFTAssetModel.fromJson(json());
|
||||
|
||||
expect(asset.mint, "MintAddr");
|
||||
expect(asset.name, "DeGod");
|
||||
expect(asset.imageOriginalUrl, "https://ipfs.io/ipfs/QmAbC123");
|
||||
});
|
||||
|
||||
test("sanitising is idempotent, so a value read back from storage stays stable", () {
|
||||
final once = SolanaNFTAssetModel.fromJson(json(name: "Ape\u2028Name"));
|
||||
|
||||
expect(once.name, "Ape Name");
|
||||
expect(sanitizeNFTText(once.name), once.name);
|
||||
});
|
||||
|
||||
test("sanitises collection and contract text, which render on the same screen", () {
|
||||
final asset = SolanaNFTAssetModel.fromJson({
|
||||
...json(),
|
||||
"collection": {
|
||||
"name": "Coll\u2028ection",
|
||||
"description": "desc\u202Eription",
|
||||
},
|
||||
"contract": {
|
||||
"name": "Cont\u2029ract",
|
||||
"symbol": "SY\u200BM",
|
||||
},
|
||||
});
|
||||
|
||||
expect(asset.collection?.name, "Coll ection");
|
||||
expect(asset.collection?.description, "desc ription");
|
||||
expect(asset.contract?.name, "Cont ract");
|
||||
expect(asset.contract?.symbol, "SY M");
|
||||
});
|
||||
});
|
||||
|
||||
group("NFTAssetModel", () {
|
||||
Map<String, dynamic> evmJson({String name = "Punk", String image = "ipfs://QmAbC"}) => {
|
||||
"token_address": "0xabc",
|
||||
"token_id": "7",
|
||||
"contract_type": "ERC721",
|
||||
"name": name,
|
||||
"symbol": "PNK",
|
||||
"normalized_metadata": {
|
||||
"name": name,
|
||||
"description": "a description",
|
||||
"image": image,
|
||||
},
|
||||
};
|
||||
|
||||
test("sanitises the text a contract controls", () {
|
||||
final asset = NFTAssetModel.fromJson(evmJson(name: "Punk\u2028Address: 0xdead"));
|
||||
|
||||
expect(asset.name, "Punk Address: 0xdead");
|
||||
expect(asset.normalizedMetadata?.name, "Punk Address: 0xdead");
|
||||
});
|
||||
|
||||
test("routes an ipfs image through the same gateway as solana", () {
|
||||
expect(
|
||||
NFTAssetModel.fromJson(evmJson()).normalizedMetadata?.imageUrl,
|
||||
"https://ipfs.io/ipfs/QmAbC",
|
||||
);
|
||||
});
|
||||
|
||||
test("leaves a plain gateway url alone instead of mangling it", () {
|
||||
expect(
|
||||
NFTAssetModel.fromJson(evmJson(image: "https://example.com/ipfs/QmAbC"))
|
||||
.normalizedMetadata
|
||||
?.imageUrl,
|
||||
"https://example.com/ipfs/QmAbC",
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user