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 Mar 5, 2024
1 parent fb591b0 commit b09a4ea
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/SnapKeyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,53 @@ 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 declaration).
// 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 = [
{
Expand Down

0 comments on commit b09a4ea

Please sign in to comment.