Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
test: add test over scope with non-defined chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
ccharly committed Feb 29, 2024
1 parent f54a257 commit 6e77c23
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/SnapKeyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


Check failure on line 784 in src/SnapKeyring.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Delete `⏎`

Check failure on line 784 in src/SnapKeyring.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Delete `⏎`

Check failure on line 784 in src/SnapKeyring.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Delete `⏎`
it('calls eth_prepareUserOperation', async () => {
const baseTxs = [
{
Expand Down

0 comments on commit 6e77c23

Please sign in to comment.