dev
dart 84 lines 2.63 KB
Raw
1 import "package:cake_wallet/utils/token_utilities.dart";
2 import "package:cw_core/crypto_currency.dart";
3 import "package:cw_core/erc20_token.dart";
4 import "package:cw_core/spl_token.dart";
5 import "package:cw_core/tron_token.dart";
6 import "package:flutter_test/flutter_test.dart";
7
8 void main() {
9 group("TokenUtilities", () {
10 group("findTronTokenContract", () {
11 test("returns the contract from a TronToken instance", () {
12 final token = TronToken(
13 name: "Test Token",
14 symbol: "TST",
15 contractAddress: "TContractAddress123",
16 decimal: 6,
17 );
18
19 expect(TokenUtilities.findTronTokenContract(token), "TContractAddress123");
20 });
21
22 test("resolves a bare currency from the default token list", () {
23 expect(
24 TokenUtilities.findTronTokenContract(CryptoCurrency.usdttrc20),
25 "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
26 );
27 });
28
29 test("returns null for native TRX", () {
30 expect(TokenUtilities.findTronTokenContract(CryptoCurrency.trx), null);
31 });
32
33 test("does not resolve a token from another network", () {
34 expect(TokenUtilities.findTronTokenContract(CryptoCurrency.usdtSol), null);
35 });
36 });
37
38 group("findSolanaTokenMint", () {
39 test("returns the mint from an SPLToken instance", () {
40 final token = SPLToken(
41 name: "Test Token",
42 symbol: "TST",
43 mintAddress: "MintAddress123",
44 decimal: 6,
45 mint: "tst",
46 );
47
48 expect(TokenUtilities.findSolanaTokenMint(token), "MintAddress123");
49 });
50
51 test("resolves a bare currency from the default token list", () {
52 expect(
53 TokenUtilities.findSolanaTokenMint(CryptoCurrency.usdtSol),
54 "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
55 );
56 });
57
58 test("returns null for native SOL", () {
59 expect(TokenUtilities.findSolanaTokenMint(CryptoCurrency.sol), null);
60 });
61
62 test("does not resolve a token from another network", () {
63 expect(TokenUtilities.findSolanaTokenMint(CryptoCurrency.usdttrc20), null);
64 });
65 });
66
67 group("findErc20TokenForSwap", () {
68 test("returns the same instance for an Erc20Token", () {
69 final token = Erc20Token(
70 name: "Test Token",
71 symbol: "TST",
72 contractAddress: "0x0000000000000000000000000000000000000001",
73 decimal: 18,
74 );
75
76 expect(TokenUtilities.findErc20TokenForSwap(token), same(token));
77 });
78
79 test("returns null for native ETH", () {
80 expect(TokenUtilities.findErc20TokenForSwap(CryptoCurrency.eth), null);
81 });
82 });
83 });
84 }