Skip to content

Commit

Permalink
refactor: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed Nov 23, 2023
1 parent 2e64041 commit fe45b61
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,35 @@ describe('KeyringController', () => {
});
});

describe(`with cacheEncryptionKey = true and encryptionKey is set`, () => {
it('should not update the vault', async () => {
const mockEncryptor = new MockEncryptor();
const keyringController = await initializeKeyringController({
password: PASSWORD,
constructorOptions: {
cacheEncryptionKey: true,
encryptor: mockEncryptor,
},
});
const initialVault = keyringController.store.getState().vault;
const updatedVaultMock =
'{"vault": "updated_vault_detail", "salt": "salt"}';
const mockEncryptionResult = {
data: '0x1234',
iv: 'an iv',
};
sinon.stub(mockEncryptor, 'updateVault').resolves(updatedVaultMock);
sinon
.stub(mockEncryptor, 'encryptWithKey')
.resolves(mockEncryptionResult);

await keyringController.unlockKeyrings(PASSWORD);
const updatedVault = keyringController.store.getState().vault;

expect(initialVault).not.toBe(updatedVault);
});
});

describe(`with cacheEncryptionKey = false`, () => {
it('should update the vault', async () => {
const mockEncryptor = new MockEncryptor();
Expand Down

0 comments on commit fe45b61

Please sign in to comment.