Skip to content

Commit e31075c

Browse files
committed
chore(rampsController): add test case for solana, bitcoin, tron
1 parent 6840747 commit e31075c

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

app/selectors/rampsController/index.test.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import {
77
type PaymentMethod,
88
} from '@metamask/ramps-controller';
99
import { AccountGroupType } from '@metamask/account-api';
10+
import { AccountId } from '@metamask/accounts-controller';
11+
import { TrxAccountType } from '@metamask/keyring-api';
12+
import { KeyringTypes } from '@metamask/keyring-controller';
1013
import { InternalAccount } from '@metamask/keyring-internal-api';
1114
import { createMockInternalAccount } from '../../util/test/accountsControllerTestUtils';
15+
import { mockSolanaAddress } from '../../util/test/keyringControllerTestUtils';
1216
import {
1317
selectUserRegion,
1418
selectProviders,
@@ -439,6 +443,131 @@ describe('RampsController Selectors', () => {
439443

440444
expect(selectRampsOrdersForSelectedAccountGroup(state)).toEqual([]);
441445
});
446+
447+
it('keeps orders whose walletAddress matches a Solana account in the selected group', () => {
448+
const solanaAccountId = 'account-ramps-solana' as AccountId;
449+
const otherSolanaAddress = '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM';
450+
const solanaInternalAccount: InternalAccount = {
451+
id: solanaAccountId,
452+
address: mockSolanaAddress,
453+
type: 'solana:dataAccount' as InternalAccount['type'],
454+
options: {},
455+
methods: [],
456+
scopes: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
457+
metadata: {
458+
name: 'Solana Account',
459+
importTime: Date.now(),
460+
keyring: {
461+
type: 'Snap Keyring',
462+
},
463+
},
464+
};
465+
const mockOrders = [
466+
{
467+
providerOrderId: 'order-sol-match',
468+
walletAddress: mockSolanaAddress,
469+
status: 'COMPLETED',
470+
createdAt: 1000,
471+
},
472+
{
473+
providerOrderId: 'order-sol-other',
474+
walletAddress: otherSolanaAddress,
475+
status: 'COMPLETED',
476+
createdAt: 2000,
477+
},
478+
];
479+
const state = createStateWithSelectedAccountGroup(
480+
{ orders: mockOrders } as never,
481+
solanaInternalAccount,
482+
solanaAccountId,
483+
);
484+
485+
expect(selectRampsOrdersForSelectedAccountGroup(state)).toEqual([
486+
mockOrders[0],
487+
]);
488+
});
489+
490+
it('keeps orders whose walletAddress matches a Bitcoin account in the selected group', () => {
491+
const bitcoinAccountId = 'account-ramps-bitcoin' as AccountId;
492+
const bitcoinAddress = 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh';
493+
const otherBitcoinAddress = 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq';
494+
const bitcoinInternalAccount: InternalAccount = {
495+
id: bitcoinAccountId,
496+
address: bitcoinAddress,
497+
type: 'bip122:p2wpkh' as InternalAccount['type'],
498+
options: {},
499+
methods: [],
500+
scopes: ['bip122:000000000019d6689c085ae165831e93'],
501+
metadata: {
502+
name: 'Bitcoin Account',
503+
importTime: Date.now(),
504+
keyring: {
505+
type: 'Snap Keyring',
506+
},
507+
},
508+
};
509+
const mockOrders = [
510+
{
511+
providerOrderId: 'order-btc-match',
512+
walletAddress: bitcoinAddress,
513+
status: 'COMPLETED',
514+
createdAt: 1000,
515+
},
516+
{
517+
providerOrderId: 'order-btc-other',
518+
walletAddress: otherBitcoinAddress,
519+
status: 'COMPLETED',
520+
createdAt: 2000,
521+
},
522+
];
523+
const state = createStateWithSelectedAccountGroup(
524+
{ orders: mockOrders } as never,
525+
bitcoinInternalAccount,
526+
bitcoinAccountId,
527+
);
528+
529+
expect(selectRampsOrdersForSelectedAccountGroup(state)).toEqual([
530+
mockOrders[0],
531+
]);
532+
});
533+
534+
it('keeps orders whose walletAddress matches a Tron account in the selected group', () => {
535+
const tronAccountId = 'account-ramps-tron' as AccountId;
536+
const tronAddress = 'TXYZopYRdj2D9XRtbPoJZ1CuXLNaoEBgD';
537+
const otherTronAddress = 'TN3W4H6rK2ce4vX9YnFQHw8ENXNA9s8rPH';
538+
const tronInternalAccount: InternalAccount = {
539+
...createMockInternalAccount(
540+
tronAddress,
541+
'Tron Account',
542+
KeyringTypes.snap,
543+
TrxAccountType.Eoa,
544+
),
545+
id: tronAccountId,
546+
};
547+
const mockOrders = [
548+
{
549+
providerOrderId: 'order-tron-match',
550+
walletAddress: tronAddress,
551+
status: 'COMPLETED',
552+
createdAt: 1000,
553+
},
554+
{
555+
providerOrderId: 'order-tron-other',
556+
walletAddress: otherTronAddress,
557+
status: 'COMPLETED',
558+
createdAt: 2000,
559+
},
560+
];
561+
const state = createStateWithSelectedAccountGroup(
562+
{ orders: mockOrders } as never,
563+
tronInternalAccount,
564+
tronAccountId,
565+
);
566+
567+
expect(selectRampsOrdersForSelectedAccountGroup(state)).toEqual([
568+
mockOrders[0],
569+
]);
570+
});
442571
});
443572

444573
describe('selectTransak', () => {

0 commit comments

Comments
 (0)