Skip to content

Commit

Permalink
refactor: accounts outside
Browse files Browse the repository at this point in the history
  • Loading branch information
montelaidev committed Jun 14, 2024
1 parent 2bb3a2a commit a78087a
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,11 @@ describe('MetaMaskController', () => {
});

describe('#_onKeyringControllerUpdate', () => {
const accounts = [
'0x603E83442BA54A2d0E080c34D6908ec228bef59f',
'0xDe95cE6E727692286E02A931d074efD1E5E2f03c',
];

it('should do nothing if there are no keyrings in state', async () => {
jest
.spyOn(metamaskController.accountTracker, 'syncWithAddresses')
Expand All @@ -1348,20 +1353,14 @@ describe('MetaMaskController', () => {
await metamaskController._onKeyringControllerUpdate({
keyrings: [
{
accounts: [
'0x603E83442BA54A2d0E080c34D6908ec228bef59f',
'0xDe95cE6E727692286E02A931d074efD1E5E2f03c',
],
accounts,
},
],
});

expect(
metamaskController.accountTracker.syncWithAddresses,
).toHaveBeenCalledWith([
'0x603E83442BA54A2d0E080c34D6908ec228bef59f',
'0xDe95cE6E727692286E02A931d074efD1E5E2f03c',
]);
).toHaveBeenCalledWith(accounts);
expect(metamaskController.getState()).toStrictEqual(oldState);
});

Expand All @@ -1375,24 +1374,18 @@ describe('MetaMaskController', () => {
isUnlocked: true,
keyrings: [
{
accounts: [
'0x603E83442BA54A2d0E080c34D6908ec228bef59f',
'0xDe95cE6E727692286E02A931d074efD1E5E2f03c',
],
accounts,
},
],
});

expect(
metamaskController.accountTracker.syncWithAddresses,
).toHaveBeenCalledWith([
'0x603E83442BA54A2d0E080c34D6908ec228bef59f',
'0xDe95cE6E727692286E02A931d074efD1E5E2f03c',
]);
).toHaveBeenCalledWith(accounts);
expect(metamaskController.getState()).toStrictEqual(oldState);
});

it('should filter out non-EVM addresses prior to calling syncWithAddresses', async () => {
it('filter out non-EVM addresses prior to calling syncWithAddresses', async () => {
jest
.spyOn(metamaskController.accountTracker, 'syncWithAddresses')
.mockReturnValue();
Expand All @@ -1402,20 +1395,17 @@ describe('MetaMaskController', () => {
keyrings: [
{
accounts: [
'0x603E83442BA54A2d0E080c34D6908ec228bef59f',
'0xDe95cE6E727692286E02A931d074efD1E5E2f03c',
'1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa',
...accounts,
// Non-EVM address which should not be used by syncWithAddresses
'bc1ql49ydapnjafl5t2cp9zqpjwe6pdgmxy98859v2',
],
},
],
});

expect(
metamaskController.accountTracker.syncWithAddresses,
).toHaveBeenCalledWith([
'0x603E83442BA54A2d0E080c34D6908ec228bef59f',
'0xDe95cE6E727692286E02A931d074efD1E5E2f03c',
]);
).toHaveBeenCalledWith(accounts);
expect(metamaskController.getState()).toStrictEqual(oldState);
});
});
Expand Down

0 comments on commit a78087a

Please sign in to comment.