From 6e77c23ca041780b0ad959988113432d51752774 Mon Sep 17 00:00:00 2001 From: Charly Chevalier Date: Thu, 29 Feb 2024 16:25:42 +0100 Subject: [PATCH] test: add test over scope with non-defined chainId --- src/SnapKeyring.test.ts | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/SnapKeyring.test.ts b/src/SnapKeyring.test.ts index c9a9f77d..ea5d5f24 100644 --- a/src/SnapKeyring.test.ts +++ b/src/SnapKeyring.test.ts @@ -734,6 +734,54 @@ describe('SnapKeyring', () => { expect(signature).toStrictEqual(expectedSignature); }); + it('signs typed data without domain chainId has no scope', async () => { + mockSnapController.handleRequest.mockResolvedValue({ + pending: false, + result: expectedSignature, + }); + + const dataToSignWithoutDomainChainId = { + ...dataToSign, + domain: { + name: dataToSign.domain.name, + version: dataToSign.domain.version, + verifyingContract: dataToSign.domain.verifyingContract, + // We do not defined the chainId (it's currently marked as + // optional in the current type declation). + // chainId: 1, + }, + }; + + const signature = await keyring.signTypedData( + accounts[0].address, + dataToSignWithoutDomainChainId, + { version: SignTypedDataVersion.V4 }, + ); + expect(mockSnapController.handleRequest).toHaveBeenCalledWith({ + snapId, + handler: 'onKeyringRequest', + origin: 'metamask', + request: { + id: expect.any(String), + jsonrpc: '2.0', + method: 'keyring_submitRequest', + params: { + id: expect.any(String), + // Without chainId alongside the typed message, we cannot + // compute the scope for this request! + scope: '', // Default value for `signTypedTransaction` + account: accounts[0].id, + request: { + method: 'eth_signTypedData_v4', + params: [accounts[0].address, dataToSignWithoutDomainChainId], + }, + }, + }, + }); + expect(signature).toStrictEqual(expectedSignature); + }); + + it('calls eth_prepareUserOperation', async () => { const baseTxs = [ {