Skip to content

Commit 782a40a

Browse files
committed
rebase
1 parent 708d9d5 commit 782a40a

File tree

8 files changed

+296
-207
lines changed

8 files changed

+296
-207
lines changed

packages/snaps-controllers/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,7 @@
8484
"@metamask/base-controller": "^8.0.0",
8585
"@metamask/json-rpc-engine": "^10.0.2",
8686
"@metamask/json-rpc-middleware-stream": "^8.0.7",
87-
<<<<<<< HEAD
8887
"@metamask/key-tree": "^10.1.1",
89-
=======
90-
"@metamask/key-tree": "^10.0.2",
91-
"@metamask/keyring-internal-api": "^4.0.1",
92-
>>>>>>> 6d5e7b45 (move `keyring-internal-api` to regular deps)
9388
"@metamask/object-multiplex": "^2.1.0",
9489
"@metamask/permission-controller": "^11.0.6",
9590
"@metamask/phishing-controller": "^12.4.1",

packages/snaps-controllers/src/interface/utils.test.tsx

Lines changed: 238 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,214 @@ describe('constructState', () => {
623623
});
624624
});
625625

626+
it('sets default value for root level AccountSelector', () => {
627+
elementDataGetters.getSelectedAccount.mockReturnValue({
628+
id: MOCK_ACCOUNT_ID,
629+
address: '0x1234567890123456789012345678901234567890',
630+
scopes: ['eip155:0'],
631+
});
632+
633+
elementDataGetters.getAccountByAddress.mockImplementation(
634+
(address: string) => ({
635+
id: MOCK_ACCOUNT_ID,
636+
address,
637+
scopes: ['eip155:0'],
638+
}),
639+
);
640+
641+
const element = (
642+
<Box>
643+
<AccountSelector name="foo" />
644+
</Box>
645+
);
646+
647+
const result = constructState({}, element, elementDataGetters);
648+
expect(result).toStrictEqual({
649+
foo: {
650+
accountId: MOCK_ACCOUNT_ID,
651+
addresses: ['eip155:0:0x1234567890123456789012345678901234567890'],
652+
},
653+
});
654+
});
655+
656+
it('supports root level AccountSelector', () => {
657+
elementDataGetters.getSelectedAccount.mockReturnValue({
658+
id: MOCK_ACCOUNT_ID,
659+
address: '0x1234567890123456789012345678901234567890',
660+
scopes: ['eip155:0'],
661+
});
662+
663+
elementDataGetters.getAccountByAddress.mockImplementation(
664+
(address: string) => ({
665+
id: MOCK_ACCOUNT_ID,
666+
address,
667+
scopes: ['eip155:0'],
668+
}),
669+
);
670+
671+
const element = (
672+
<Box>
673+
<AccountSelector
674+
name="foo"
675+
value="eip155:0:0x1234567890123456789012345678901234567890"
676+
/>
677+
</Box>
678+
);
679+
680+
const result = constructState({}, element, elementDataGetters);
681+
expect(result).toStrictEqual({
682+
foo: {
683+
accountId: MOCK_ACCOUNT_ID,
684+
addresses: ['eip155:0:0x1234567890123456789012345678901234567890'],
685+
},
686+
});
687+
});
688+
689+
it('sets default value for AccountSelector in form', () => {
690+
elementDataGetters.getSelectedAccount.mockReturnValue({
691+
id: MOCK_ACCOUNT_ID,
692+
address: '0x1234567890123456789012345678901234567890',
693+
scopes: ['eip155:0'],
694+
});
695+
696+
elementDataGetters.getAccountByAddress.mockImplementation(
697+
(address: string) => ({
698+
id: MOCK_ACCOUNT_ID,
699+
address,
700+
scopes: ['eip155:0'],
701+
}),
702+
);
703+
704+
const element = (
705+
<Box>
706+
<Form name="form">
707+
<Field label="foo">
708+
<AccountSelector name="foo" />
709+
</Field>
710+
</Form>
711+
</Box>
712+
);
713+
714+
const result = constructState({}, element, elementDataGetters);
715+
expect(result).toStrictEqual({
716+
form: {
717+
foo: {
718+
accountId: MOCK_ACCOUNT_ID,
719+
addresses: ['eip155:0:0x1234567890123456789012345678901234567890'],
720+
},
721+
},
722+
});
723+
});
724+
725+
it('supports AccountSelector in form', () => {
726+
elementDataGetters.getSelectedAccount.mockReturnValue({
727+
id: MOCK_ACCOUNT_ID,
728+
address: '0x1234567890123456789012345678901234567890',
729+
scopes: ['eip155:0'],
730+
});
731+
732+
elementDataGetters.getAccountByAddress.mockImplementation(
733+
(address: string) => ({
734+
id: MOCK_ACCOUNT_ID,
735+
address,
736+
scopes: ['eip155:0'],
737+
}),
738+
);
739+
740+
const element = (
741+
<Box>
742+
<Form name="form">
743+
<Field label="foo">
744+
<AccountSelector
745+
name="foo"
746+
value="eip155:0:0x1234567890123456789012345678901234567890"
747+
/>
748+
</Field>
749+
</Form>
750+
</Box>
751+
);
752+
753+
const result = constructState({}, element, elementDataGetters);
754+
expect(result).toStrictEqual({
755+
form: {
756+
foo: {
757+
accountId: MOCK_ACCOUNT_ID,
758+
addresses: ['eip155:0:0x1234567890123456789012345678901234567890'],
759+
},
760+
},
761+
});
762+
});
763+
764+
it('sets the selected account to the currently selected account if the account does not exist for AccountSelector', () => {
765+
elementDataGetters.getSelectedAccount.mockReturnValue({
766+
id: MOCK_ACCOUNT_ID,
767+
address: '0x1234567890123456789012345678901234567890',
768+
scopes: ['eip155:0'],
769+
});
770+
771+
elementDataGetters.getAccountByAddress.mockReturnValue(undefined);
772+
773+
const element = (
774+
<Box>
775+
<AccountSelector
776+
name="foo"
777+
value="bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6"
778+
/>
779+
</Box>
780+
);
781+
782+
const result = constructState({}, element, elementDataGetters);
783+
784+
expect(result).toStrictEqual({
785+
foo: {
786+
accountId: MOCK_ACCOUNT_ID,
787+
addresses: ['eip155:0:0x1234567890123456789012345678901234567890'],
788+
},
789+
});
790+
});
791+
792+
it('sets the selected account to null if there is no selected account', () => {
793+
elementDataGetters.getSelectedAccount.mockReturnValue(undefined);
794+
795+
const element = (
796+
<Box>
797+
<AccountSelector name="foo" />
798+
</Box>
799+
);
800+
801+
const result = constructState({}, element, elementDataGetters);
802+
803+
expect(result).toStrictEqual({
804+
foo: null,
805+
});
806+
});
807+
808+
it('switches the selected account if `switchGlobalAccount` is set', () => {
809+
elementDataGetters.getAccountByAddress.mockImplementation(
810+
(address: string) => ({
811+
id: MOCK_ACCOUNT_ID,
812+
address,
813+
scopes: ['eip155:0'],
814+
}),
815+
);
816+
817+
const element = (
818+
<Box>
819+
<AccountSelector
820+
name="foo"
821+
value="eip155:0:0x1234567890123456789012345678901234567890"
822+
switchGlobalAccount
823+
/>
824+
</Box>
825+
);
826+
827+
constructState({}, element, elementDataGetters);
828+
829+
expect(elementDataGetters.setSelectedAccount).toHaveBeenCalledWith(
830+
MOCK_ACCOUNT_ID,
831+
);
832+
});
833+
626834
it('sets default value for root level AssetSelector', () => {
627835
elementDataGetters.getAssetsState.mockReturnValue({
628836
assetsMetadata: {
@@ -646,13 +854,9 @@ describe('constructState', () => {
646854
<Box>
647855
<AssetSelector
648856
name="foo"
649-
<<<<<<< HEAD
650857
addresses={[
651858
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
652859
]}
653-
=======
654-
value="eip155:0:0x1234567890123456789012345678901234567890"
655-
>>>>>>> 82969fe5 (address requested changes)
656860
/>
657861
</Box>
658862
);
@@ -731,13 +935,9 @@ describe('constructState', () => {
731935
<Field label="foo">
732936
<AssetSelector
733937
name="foo"
734-
<<<<<<< HEAD
735938
addresses={[
736939
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
737940
]}
738-
=======
739-
value="eip155:0:0x1234567890123456789012345678901234567890"
740-
>>>>>>> 82969fe5 (address requested changes)
741941
/>
742942
</Field>
743943
</Form>
@@ -774,7 +974,6 @@ describe('constructState', () => {
774974

775975
const element = (
776976
<Box>
777-
<<<<<<< HEAD
778977
<Form name="form">
779978
<Field label="foo">
780979
<AssetSelector
@@ -786,12 +985,6 @@ describe('constructState', () => {
786985
/>
787986
</Field>
788987
</Form>
789-
=======
790-
<AccountSelector
791-
name="foo"
792-
value="bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6"
793-
/>
794-
>>>>>>> 82969fe5 (address requested changes)
795988
</Box>
796989
);
797990

@@ -844,7 +1037,6 @@ describe('constructState', () => {
8441037
});
8451038
});
8461039

847-
<<<<<<< HEAD
8481040
it('sets the value to null if the account has no assets', () => {
8491041
elementDataGetters.getAssetsState.mockReturnValue({
8501042
assetsMetadata: {
@@ -861,27 +1053,14 @@ describe('constructState', () => {
8611053
elementDataGetters.getAccountByAddress.mockReturnValue({
8621054
id: MOCK_ACCOUNT_ID,
8631055
});
864-
=======
865-
it('switches the selected account if `switchGlobalAccount` is set', () => {
866-
getAccountByAddress.mockImplementation((address: string) => ({
867-
id: 'foo',
868-
address,
869-
scopes: ['eip155:0'],
870-
}));
871-
>>>>>>> 82969fe5 (address requested changes)
8721056

8731057
const element = (
8741058
<Box>
8751059
<AssetSelector
8761060
name="foo"
877-
<<<<<<< HEAD
8781061
addresses={[
8791062
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
8801063
]}
881-
=======
882-
value="eip155:0:0x1234567890123456789012345678901234567890"
883-
switchGlobalAccount
884-
>>>>>>> 82969fe5 (address requested changes)
8851064
/>
8861065
</Box>
8871066
);
@@ -1196,7 +1375,12 @@ describe('getDefaultAsset', () => {
11961375
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
11971376
],
11981377
undefined,
1199-
{ getAssetsState, getAccountByAddress },
1378+
{
1379+
getAssetsState,
1380+
getAccountByAddress,
1381+
getSelectedAccount: jest.fn(),
1382+
setSelectedAccount: jest.fn(),
1383+
},
12001384
),
12011385
).toStrictEqual({
12021386
asset: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
@@ -1231,7 +1415,12 @@ describe('getDefaultAsset', () => {
12311415
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
12321416
],
12331417
undefined,
1234-
{ getAssetsState, getAccountByAddress },
1418+
{
1419+
getAssetsState,
1420+
getAccountByAddress,
1421+
getSelectedAccount: jest.fn(),
1422+
setSelectedAccount: jest.fn(),
1423+
},
12351424
),
12361425
).toStrictEqual({
12371426
asset:
@@ -1259,7 +1448,12 @@ describe('getDefaultAsset', () => {
12591448
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
12601449
],
12611450
undefined,
1262-
{ getAssetsState, getAccountByAddress },
1451+
{
1452+
getAssetsState,
1453+
getAccountByAddress,
1454+
getSelectedAccount: jest.fn(),
1455+
setSelectedAccount: jest.fn(),
1456+
},
12631457
),
12641458
).toBeNull();
12651459
});
@@ -1295,7 +1489,12 @@ describe('getDefaultAsset', () => {
12951489
'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
12961490
],
12971491
['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
1298-
{ getAssetsState, getAccountByAddress },
1492+
{
1493+
getAssetsState,
1494+
getAccountByAddress,
1495+
getSelectedAccount: jest.fn(),
1496+
setSelectedAccount: jest.fn(),
1497+
},
12991498
),
13001499
).toStrictEqual({
13011500
asset: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
@@ -1320,7 +1519,12 @@ describe('getDefaultAsset', () => {
13201519
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
13211520
],
13221521
undefined,
1323-
{ getAssetsState, getAccountByAddress },
1522+
{
1523+
getAssetsState,
1524+
getAccountByAddress,
1525+
getSelectedAccount: jest.fn(),
1526+
setSelectedAccount: jest.fn(),
1527+
},
13241528
),
13251529
).toThrow(
13261530
'Account not found for address: solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv.',

0 commit comments

Comments
 (0)