Skip to content

Commit

Permalink
chore(suite): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Feb 11, 2025
1 parent 8e843a3 commit b646159
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/blockchain-link-utils/src/blockbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export const transformTokenInfo = (
{
...token,
decimals: token.decimals || 0,
standard: token.standard,
},
]);
}, [] as TokenInfo[]);
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-link-utils/src/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const transformTokenInfo = (
const info = tokens.map(token => ({
type: 'BLOCKFROST',
balance: token.quantity,
standard: 'BLOCKFROST',
...transformToken(token),
}));

Expand Down
4 changes: 3 additions & 1 deletion packages/blockchain-link-utils/src/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const transformTokenInfo = (
decimals: info.tokenAmount.decimals,
...getTokenNameAndSymbol(info.mint, tokenDetailByMint),
address: tokenAccount.pubkey,
standard: tokenProgramsInfo[program].tokenStandard,
};
}),
A.reduce(
Expand All @@ -176,9 +177,10 @@ export const transformTokenInfo = (
balance: token.balance || '0',
});
} else {
const { type, contract, balance, decimals, name, symbol } = token;
const { type, standard, contract, balance, decimals, name, symbol } = token;
acc[token.contract] = {
type,
standard,
contract,
balance,
decimals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const tOut = {
const tIn = {
name: 'Token name',
type: 'ERC20',
standard: 'ERC20',
symbol: 'TN',
contract: '0x0',
value: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default {
result: [
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
fingerprint: 'asset1hwnpal5vap799t6kkjmjf6myhse4zl2vu4ahzz',
policyId: 'b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f',
symbol: 'BerrySapphire',
Expand All @@ -164,6 +165,7 @@ export default {
},
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
decimals: 0,
fingerprint: 'asset108xu02ckwrfc8qs9d97mgyh4kn8gdu9w8f5sxk',
name: 'Snek',
Expand All @@ -174,6 +176,7 @@ export default {
},
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
fingerprint: 'asset1zvclg2cvj4e5jfz5vswf3sx0lasy79xn8cdap9',
policyId: '02477d7c23b4c2834b0be8ca8578dde47af0cc82a964688f6fc95a7a',
symbol: 'GRIC',
Expand Down Expand Up @@ -515,6 +518,7 @@ export default {
tokens: [
{
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
fingerprint: 'asset1eevmdlaz5424s3663ypw8w4vyxdlxkm3lefz06',
contract:
'2f712364ec46f0cf707d412106ce71ef3370f76e27fb56b6bb14708776657465726e696b4e657a6a6564656e79',
Expand Down
2 changes: 2 additions & 0 deletions packages/blockchain-link-utils/src/tests/fixtures/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ export const fixtures = {
expectedOutput: [
{
type: 'SPL',
standard: 'SPL',
contract: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
balance: '2000000',
decimals: 6,
Expand All @@ -998,6 +999,7 @@ export const fixtures = {
expectedOutput: [
{
type: 'SPL',
standard: 'SPL',
contract: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
balance: '3000000',
decimals: 6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ const fixtures: {
tokens: [
{
type: 'ERC20',
standard: 'ERC20',
name: 'Token name',
symbol: 'TKNNME',
contract: '0x0',
Expand All @@ -476,6 +477,7 @@ const fixtures: {
tokens: [
{
type: 'ERC20',
standard: 'ERC20',
name: 'Token name',
symbol: 'TKNNME',
contract: '0x0',
Expand Down Expand Up @@ -600,6 +602,7 @@ const fixtures: {
address: '0x3c205C8B3e02421Da82064646788c82f7bd753B9',
contractInfo: {
type: 'ERC20',
standard: 'ERC20',
contract: '0x3c205C8B3e02421Da82064646788c82f7bd753B9',
name: 'PureFi Token',
symbol: 'UFI',
Expand All @@ -619,6 +622,7 @@ const fixtures: {
addressAliases: undefined,
contractInfo: {
type: 'ERC20',
standard: 'ERC20',
contract: '0x3c205C8B3e02421Da82064646788c82f7bd753B9',
name: 'PureFi Token',
symbol: 'UFI',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const getToken = (contract: string, symbol: string, decimals: number) => ({
symbol,
decimals,
type: 'ERC20',
standard: 'ERC20',
});

const TOKEN_1 = getToken('0xaea46a60368a7bd060eec7df8cba43b7ef41ad85', 'FET', 6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('Trading Common Actions', () => {
estimatedFeeLimit: '123',
token: {
type: 'abc',
standard: 'ERC20',
contract: 'cde',
decimals: 0,
},
Expand Down
9 changes: 8 additions & 1 deletion packages/suite/src/hooks/wallet/__fixtures__/useSendForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ export const ETH_ACCOUNT = {
availableBalance: '10000000000000000000', // 10 ETH
misc: { nonce: '0' },
tokens: [
{ type: 'ERC20', contract: '0xABCD', symbol: '0xABCD', decimals: 3, balance: '1' },
{
type: 'ERC20',
standard: 'ERC20',
contract: '0xABCD',
symbol: '0xABCD',
decimals: 3,
balance: '1',
},
],
}),
network: { networkType: 'ethereum', symbol: 'eth', decimals: 18, chainId: 1 },
Expand Down
1 change: 1 addition & 0 deletions packages/suite/src/storage/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ export const migrate: OnUpgradeFunc<SuiteDBSchema> = async (
fingerprint: token.name,
policyId,
type: token.type,
standard: token.standard,
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const FIXTURE_ACCOUNTS: Partial<Account>[] = [
decimals: 6,
name: 'Tether USD',
symbol: 'usdt',
standard: 'ERC20',
type: 'ERC20',
},
// unknown token
Expand All @@ -59,6 +60,7 @@ export const FIXTURE_ACCOUNTS: Partial<Account>[] = [
decimals: 6,
name: 'USDC',
symbol: 'usdc',
standard: 'ERC20',
type: 'ERC20',
},
// supported and known token
Expand All @@ -68,6 +70,7 @@ export const FIXTURE_ACCOUNTS: Partial<Account>[] = [
decimals: 6,
name: 'VeChain',
symbol: 'VEE',
standard: 'ERC20',
type: 'ERC20',
},
],
Expand All @@ -93,6 +96,7 @@ export const FIXTURE_ACCOUNTS: Partial<Account>[] = [
decimals: 6,
name: 'Tether USD',
symbol: 'usdt',
standard: 'ERC20',
type: 'ERC20',
},
],
Expand All @@ -112,6 +116,7 @@ export const FIXTURE_ACCOUNTS: Partial<Account>[] = [
decimals: 6,
name: 'USDC',
symbol: 'usdc',
standard: 'ERC20',
type: 'ERC20',
},
],
Expand All @@ -131,6 +136,7 @@ export const FIXTURE_ACCOUNTS: Partial<Account>[] = [
decimals: 6,
name: 'USDC',
symbol: 'usdc',
standard: 'ERC20',
type: 'ERC20',
},
],
Expand Down
3 changes: 3 additions & 0 deletions suite-common/trading/src/__fixtures__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ export const accountEth = {
tokens: [
{
type: 'ERC20',
standard: 'ERC20',
contract: '0x1234123412341234123412341234123412341234',
symbol: 'usdt',
decimals: 18,
},
{
type: 'ERC20',
standard: 'ERC20',
contract: '0x1234123412341234123412341234123412341235',
symbol: 'usdc',
decimals: 18,
},
{
type: 'ERC20',
standard: 'ERC20',
contract: '0x1234123412341234123412341234123412341236',
symbol: 'other',
decimals: 18,
Expand Down
2 changes: 2 additions & 0 deletions suite-common/wallet-utils/src/__fixtures__/cardanoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const formatMaxOutputAmount = [
name: 'Nuts',
symbol: 'NUTS',
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
},
],
},
Expand Down Expand Up @@ -262,6 +263,7 @@ export const formatMaxOutputAmount = [
name: 'Nuts',
symbol: 'NUTS',
type: 'BLOCKFROST',
standard: 'BLOCKFROST',
contract: '57fca08abbaddee36da742a839f7d83a7e1d2419f1507fcbf391652243484f43',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const prepareEthereumTransaction = [
txInfo: {
token: {
type: 'ERC20',
standard: 'ERC20',
symbol: 'gnt',
decimals: 18,
contract: '0xa74476443119A942dE498590Fe1f2454d7D4aC0d',
Expand Down
18 changes: 16 additions & 2 deletions suite-common/wallet-utils/src/__tests__/sendFormUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,22 @@ describe('sendForm utils', () => {

const EthAccount = getWalletAccount({
tokens: [
{ type: 'ERC20', contract: 'A', symbol: 'A', decimals: 2, name: 'A' },
{ type: 'ERC20', contract: 'B', symbol: 'B', decimals: 6, name: 'B' },
{
type: 'ERC20',
standard: 'ERC20',
contract: 'A',
symbol: 'A',
decimals: 2,
name: 'A',
},
{
type: 'ERC20',
standard: 'ERC20',
contract: 'B',
symbol: 'B',
decimals: 6,
name: 'B',
},
],
});
const EthNetwork = networks.eth;
Expand Down
5 changes: 5 additions & 0 deletions suite-common/wallet-utils/src/accountUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,11 @@ export const isTokenMatchesSearch = (token: TokenInfo, search: string) =>
token.fingerprint?.toLowerCase().includes(search) ||
token.policyId?.toLowerCase().includes(search);

export const isTokenTransferMatchesSearch = (token: TokenTransfer, search: string) =>
token.symbol?.toLowerCase().includes(search) ||
token.name?.toLowerCase().includes(search) ||
token.contract.toLowerCase().includes(search);

export const isNftMatchesSearch = (token: TokenInfo, search: string) =>
token.symbol?.toLowerCase().includes(search) ||
token.name?.toLowerCase().includes(search) ||
Expand Down
1 change: 1 addition & 0 deletions suite-common/wallet-utils/src/reviewTransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const getCardanoTokenBundle = (account: Account, output: CardanoOutput) => {

return {
type: 'cardano',
standard: 'BLOCKFROST',
contract: output.address,
balance: token.amount,
symbol: token.assetNameBytes
Expand Down
6 changes: 3 additions & 3 deletions suite-common/wallet-utils/src/transactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { arrayPartition } from '@trezor/utils';
import { BigNumber } from '@trezor/utils/src/bigNumber';

import { formatAmount, formatNetworkAmount, isTokenMatchesSearch } from './accountUtils';
import { formatAmount, formatNetworkAmount, isTokenTransferMatchesSearch } from './accountUtils';
import { getFiatRateKey, roundTimestampToNearestPastHour } from './fiatRatesUtils';
import { getMyInputsFromTransaction } from './getMyInputsFromTransaction';
import { toFiatCurrency } from '../src/fiatConverterUtils';
Expand Down Expand Up @@ -491,7 +491,7 @@ export const isNftMultitokenTransfer = (transfer: TokenTransfer) =>

// TODO: TokenInfo should use TokenStandard type
export const isNftToken = (token: TokenInfo) =>
['ERC1155', 'ERC721', 'BEP1155', 'BEP721'].includes(token.type || '');
['ERC1155', 'ERC721', 'BEP1155', 'BEP721'].includes(token.standard || '');

export const getNftTokenId = (transfer: TokenTransfer) =>
// use 0 index, haven't found an example where multiTokenValues.length > 1
Expand Down Expand Up @@ -930,7 +930,7 @@ export const simpleSearchTransactions = (
const foundTxsForToken = transactions.flatMap(transaction => {
const hasMatchingToken = transaction.tokens.some(
token =>
isTokenMatchesSearch(token, search.toLowerCase()) ||
isTokenTransferMatchesSearch(token, search.toLowerCase()) ||
token.to?.toLowerCase().includes(search.toLowerCase()) ||
token.from?.toLowerCase().includes(search.toLowerCase()),
);
Expand Down

0 comments on commit b646159

Please sign in to comment.