Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Salah-eddineS committed Aug 29, 2023
1 parent 471f845 commit 3d98084
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,51 @@ describe('KeyringController', () => {
});
});

describe('decryptMessage', () => {
it('should successfully decrypt a message with valid parameters and return the raw decryption result', async () => {
await withController(async ({ controller }) => {
const messageParams = {
from: '0x1234567890abcdef',
data: {
version: '1.0',
nonce: '123456',
ephemPublicKey: '0xabcdef1234567890',
ciphertext: '0xabcdef1234567890',
},
};
const expectedDecryptionResult = 'decrypted message';

const decryptMessageMock = jest
.fn()
.mockResolvedValue(expectedDecryptionResult);
controller.decryptMessage = decryptMessageMock;

const result = await controller.decryptMessage(messageParams);

expect(result).toBe(expectedDecryptionResult);
expect(decryptMessageMock).toHaveBeenCalledWith(messageParams);
});
});

it("should throw an error if the 'from' parameter is not a valid account address", async () => {
await withController(async ({ controller }) => {
const messageParams = {
from: 'invalid address',
data: {
version: '1.0',
nonce: '123456',
ephemPublicKey: '0xabcdef1234567890',
ciphertext: '0xabcdef1234567890',
},
};

await expect(controller.decryptMessage(messageParams)).rejects.toThrow(
'KeyringController - No keyring found. Error info: The address passed in is invalid/empty',
);
});
});
});

describe('getKeyringForAccount', () => {
describe('when existing account is provided', () => {
it('should get correct keyring', async () => {
Expand Down

0 comments on commit 3d98084

Please sign in to comment.