Skip to content

Commit 1e12de9

Browse files
committed
rebase
1 parent eb3b011 commit 1e12de9

File tree

8 files changed

+296
-215
lines changed

8 files changed

+296
-215
lines changed

packages/snaps-controllers/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,7 @@
8383
"@metamask/base-controller": "^8.0.0",
8484
"@metamask/json-rpc-engine": "^10.0.2",
8585
"@metamask/json-rpc-middleware-stream": "^8.0.7",
86-
<<<<<<< HEAD
8786
"@metamask/key-tree": "^10.1.1",
88-
=======
89-
"@metamask/key-tree": "^10.0.2",
90-
"@metamask/keyring-internal-api": "^4.0.1",
91-
>>>>>>> 6d5e7b45 (move `keyring-internal-api` to regular deps)
9287
"@metamask/object-multiplex": "^2.1.0",
9388
"@metamask/permission-controller": "^11.0.6",
9489
"@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
);
@@ -1124,7 +1303,12 @@ describe('getDefaultAsset', () => {
11241303
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
11251304
],
11261305
undefined,
1127-
{ getAssetsState, getAccountByAddress },
1306+
{
1307+
getAssetsState,
1308+
getAccountByAddress,
1309+
getSelectedAccount: jest.fn(),
1310+
setSelectedAccount: jest.fn(),
1311+
},
11281312
),
11291313
).toStrictEqual({
11301314
asset: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
@@ -1159,7 +1343,12 @@ describe('getDefaultAsset', () => {
11591343
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
11601344
],
11611345
undefined,
1162-
{ getAssetsState, getAccountByAddress },
1346+
{
1347+
getAssetsState,
1348+
getAccountByAddress,
1349+
getSelectedAccount: jest.fn(),
1350+
setSelectedAccount: jest.fn(),
1351+
},
11631352
),
11641353
).toStrictEqual({
11651354
asset:
@@ -1187,7 +1376,12 @@ describe('getDefaultAsset', () => {
11871376
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
11881377
],
11891378
undefined,
1190-
{ getAssetsState, getAccountByAddress },
1379+
{
1380+
getAssetsState,
1381+
getAccountByAddress,
1382+
getSelectedAccount: jest.fn(),
1383+
setSelectedAccount: jest.fn(),
1384+
},
11911385
),
11921386
).toBeNull();
11931387
});
@@ -1223,7 +1417,12 @@ describe('getDefaultAsset', () => {
12231417
'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
12241418
],
12251419
['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
1226-
{ getAssetsState, getAccountByAddress },
1420+
{
1421+
getAssetsState,
1422+
getAccountByAddress,
1423+
getSelectedAccount: jest.fn(),
1424+
setSelectedAccount: jest.fn(),
1425+
},
12271426
),
12281427
).toStrictEqual({
12291428
asset: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
@@ -1248,7 +1447,12 @@ describe('getDefaultAsset', () => {
12481447
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv',
12491448
],
12501449
undefined,
1251-
{ getAssetsState, getAccountByAddress },
1450+
{
1451+
getAssetsState,
1452+
getAccountByAddress,
1453+
getSelectedAccount: jest.fn(),
1454+
setSelectedAccount: jest.fn(),
1455+
},
12521456
),
12531457
).toThrow(
12541458
'Account not found for address: solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv.',

0 commit comments

Comments
 (0)