This repository was archived by the owner on Oct 7, 2024. It is now read-only.
generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
chore(deps): bump @metamask/keyring-api to v0.2.1
#70
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aa235ff
bump @metamask/keyring-api to v0.2.1
gantunesr ad9c18a
fix SnapKeyring tests
gantunesr 3695711
chore: add ts-expect-error to unblock unit tests
gantunesr f256aa5
test: update tests to use InternalAccount
gantunesr de00339
chore: merge changes from feat/internal-account
gantunesr 18df028
chore: merge changes from feat/internal-account (unit tests)
gantunesr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import { TransactionFactory } from '@ethereumjs/tx'; | ||
| import { KeyringAccount } from '@metamask/keyring-api'; | ||
| import { | ||
| EthMethod, | ||
| EthAccountType, | ||
| InternalAccount, | ||
| } from '@metamask/keyring-api'; | ||
| import { SnapController } from '@metamask/snaps-controllers'; | ||
|
|
||
| import { KeyringState, SnapKeyring } from '.'; | ||
|
|
@@ -17,18 +21,16 @@ describe('SnapKeyring', () => { | |
| { | ||
| id: 'b05d918a-b37c-497a-bb28-3d15c0d56b7a', | ||
| address: '0xC728514Df8A7F9271f4B7a4dd2Aa6d2D723d3eE3', | ||
| name: 'Account 1', | ||
| options: null, | ||
| supportedMethods: ['personal_sign', 'eth_sendTransaction'], | ||
| type: 'eip155:eoa', | ||
| options: {}, | ||
| methods: [EthMethod.PersonalSign], | ||
| type: EthAccountType.Eoa, | ||
| }, | ||
| { | ||
| id: '33c96b60-2237-488e-a7bb-233576f3d22f', | ||
| address: '0x34b13912eAc00152bE0Cb409A301Ab8E55739e63', | ||
| name: 'Account 2', | ||
| options: null, | ||
| supportedMethods: ['eth_sendTransaction', 'eth_signTypedData'], | ||
| type: 'eip155:eoa', | ||
| options: {}, | ||
| methods: [EthMethod.SignTypedData], | ||
| type: EthAccountType.Eoa, | ||
| }, | ||
| ] as const; | ||
|
|
||
|
|
@@ -38,7 +40,8 @@ describe('SnapKeyring', () => { | |
| mockSnapController.handleRequest.mockResolvedValue(accounts); | ||
| await keyring.handleKeyringSnapMessage(snapId, { | ||
| method: 'createAccount', | ||
| params: { account: account as unknown as KeyringAccount }, | ||
| // @ts-expect-error Check https://github.com/ianstormtaylor/superstruct/issues/983 | ||
| params: { account: account as unknown as InternalAccount }, | ||
|
Comment on lines
+43
to
+44
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment we're suppressing this error until it's fixed in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gantunesr It should be fixed in |
||
| }); | ||
| } | ||
| }); | ||
|
|
@@ -48,7 +51,9 @@ describe('SnapKeyring', () => { | |
| const result = await keyring.handleKeyringSnapMessage(snapId, { | ||
| method: 'listAccounts', | ||
| }); | ||
| expect(result).toStrictEqual(accounts); | ||
| expect(result).toStrictEqual( | ||
| accounts.map((a) => a.address.toLowerCase()), | ||
| ); | ||
| }); | ||
|
|
||
| it('should fail if the method is not supported', async () => { | ||
|
|
@@ -60,7 +65,10 @@ describe('SnapKeyring', () => { | |
| }); | ||
|
|
||
| it('should submit an async request and return the result', async () => { | ||
| mockSnapController.handleRequest.mockResolvedValue({ pending: true }); | ||
| mockSnapController.handleRequest.mockResolvedValue({ | ||
| pending: true, | ||
| redirect: 'https://mock-url.com', | ||
| }); | ||
| const requestPromise = keyring.signPersonalMessage( | ||
| accounts[0].address, | ||
| 'hello', | ||
|
|
@@ -82,7 +90,9 @@ describe('SnapKeyring', () => { | |
| describe('getAccounts', () => { | ||
| it('should return all account addresses', async () => { | ||
| const addresses = await keyring.getAccounts(); | ||
| expect(addresses).toStrictEqual(accounts.map((a) => a.address)); | ||
| expect(addresses).toStrictEqual( | ||
| accounts.map((a) => a.address.toLowerCase()), | ||
| ); | ||
| expect(mockSnapController.handleRequest).toHaveBeenCalledWith({ | ||
| handler: 'onRpcRequest', | ||
| origin: 'metamask', | ||
|
|
@@ -152,7 +162,7 @@ describe('SnapKeyring', () => { | |
| }); | ||
|
|
||
| describe('signTransaction', () => { | ||
| it('should sign a transaction synchronously', async () => { | ||
| it('should sign a ethereum transaction synchronously', async () => { | ||
| const mockTx = { | ||
| data: '0x0', | ||
| gasLimit: '0x26259fe', | ||
|
|
@@ -178,6 +188,43 @@ describe('SnapKeyring', () => { | |
| const signature = await keyring.signTransaction(accounts[0].address, tx); | ||
| expect(signature).toStrictEqual(expectedSignedTx); | ||
| }); | ||
|
|
||
| it('should sign a transaction synchronously and return a userOperation', async () => { | ||
| const mockTx = { | ||
| data: '0x0', | ||
| gasLimit: '0x26259fe', | ||
| gasPrice: '0x1', | ||
| nonce: '0xfffffffe', | ||
| to: '0xccccccccccccd000000000000000000000000000', | ||
| value: '0x1869e', | ||
| chainId: '0x1', | ||
| type: '0x00', | ||
| }; | ||
| const mockSignedTx = { | ||
| userOp: { | ||
| sender: accounts[0].address, | ||
| nonce: '0x0', | ||
| initCode: '0x', | ||
| callData: '0x', | ||
| callGasLimit: '0x0', | ||
| verificationGasLimit: '0x2DC6C0', | ||
| preVerificationGas: '0x2DC6C0', | ||
| maxFeePerGas: '0x0', | ||
| maxPriorityFeePerGas: '0x3B9ACA00', | ||
| paymasterAndData: '0x', | ||
| signature: '0x', | ||
| }, | ||
| userOpHash: '0x0', | ||
| }; | ||
| const tx = TransactionFactory.fromTxData(mockTx); | ||
| const expectedSignedTx = mockSignedTx; | ||
| mockSnapController.handleRequest.mockResolvedValue({ | ||
| pending: false, | ||
| result: mockSignedTx, | ||
| }); | ||
| const signature = await keyring.signTransaction(accounts[0].address, tx); | ||
| expect(signature).toStrictEqual(expectedSignedTx); | ||
| }); | ||
| }); | ||
|
|
||
| describe('signPersonalMessage', () => { | ||
|
|
@@ -278,14 +325,18 @@ describe('SnapKeyring', () => { | |
| it('should remove an account', async () => { | ||
| mockSnapController.handleRequest.mockResolvedValue(null); | ||
| await keyring.removeAccount(accounts[0].address); | ||
| expect(await keyring.getAccounts()).toStrictEqual([accounts[1].address]); | ||
| expect(await keyring.getAccounts()).toStrictEqual([ | ||
| accounts[1].address.toLowerCase(), | ||
| ]); | ||
| }); | ||
|
|
||
| it('should remove the account and warn if snap fails', async () => { | ||
| const spy = jest.spyOn(console, 'error').mockImplementation(); | ||
| mockSnapController.handleRequest.mockRejectedValue('error'); | ||
| await keyring.removeAccount(accounts[0].address); | ||
| expect(await keyring.getAccounts()).toStrictEqual([accounts[1].address]); | ||
| expect(await keyring.getAccounts()).toStrictEqual([ | ||
| accounts[1].address.toLowerCase(), | ||
| ]); | ||
| expect(console.error).toHaveBeenCalledWith( | ||
| 'Account "0xC728514Df8A7F9271f4B7a4dd2Aa6d2D723d3eE3" may not have been removed from snap "local:snap.mock":', | ||
| 'error', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests regarding
serializeanddeserializeare not working currently because of the data type change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danroc @montelaidev regarding our conversation earlier today, when should the
metadataattribute be added to the accounts object to comply with theInternalAccount? And what's the source of data for the fieldssnapandname?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snapmetadata is filled by theSnapKeyring(this repo), thenameshould be filled by theAccountsController.