-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Add function getCallsStatus for middleware to handle wallet_getCallsStatus requests #15015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jpuri
wants to merge
30
commits into
main
Choose a base branch
from
support_call_status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+576
−308
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
a17f1b5
Adding wallet middleware in mobile
jpuri f257fb0
update
jpuri 09852cd
update
jpuri 68869a6
update
jpuri 61e0e4d
Merge branch 'main' into adding_wallet_middleware
jpuri c2bcf42
Creating transaction for batch transaction request
jpuri b93a514
Merge branch 'main' of github.com:MetaMask/metamask-mobile into addin…
jpuri c1b50a1
Merge branch 'adding_wallet_middleware' of github.com:MetaMask/metama…
jpuri 520b822
update
jpuri 67011b9
Merge branch 'main' into adding_wallet_middleware
jpuri b5934cd
Adding validation for batch request
jpuri e9e0169
Adding test coverage
jpuri 89f5227
update
jpuri 00fd316
update
jpuri ab89539
update
jpuri 0278c00
Merge branch 'main' into adding_wallet_middleware
jpuri d2823ea
Merge branch 'adding_wallet_middleware' into send_call_validations
jpuri 333aec7
Add support for wallet_getCallsStatus in middleware
jpuri fa3b77a
merge
jpuri 78c596d
update
jpuri 4059f4d
Merge branch 'send_call_validations' into support_call_status
jpuri 5b576d8
Merge branch 'send_call_validations' into support_call_status
jpuri e67d111
Merge branch 'support_call_status' of https://github.com/MetaMask/met…
jpuri 46792cb
update
jpuri 82b0c18
update
jpuri 60675a2
update
jpuri 05967e3
update
jpuri c6ec12a
Merge branch 'main' into send_call_validations
jpuri cceeaf8
merge
jpuri 918ca3b
merge
jpuri 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,173 +1,8 @@ | ||
import { | ||
createAsyncWalletMiddleware, | ||
getAccounts, | ||
processSendCalls, | ||
} from './createAsyncWalletMiddleware'; | ||
import Engine from '../Engine'; | ||
import { SendCalls } from '@metamask/eth-json-rpc-middleware'; | ||
import { JsonRpcRequest } from '@metamask/utils'; | ||
|
||
const MOCK_ACCOUNT = '0x1234'; | ||
jest.mock('../Engine', () => ({ | ||
context: { | ||
AccountsController: { | ||
getSelectedAccount: () => ({ address: MOCK_ACCOUNT }), | ||
}, | ||
KeyringController: { | ||
state: { | ||
isUnlocked: true, | ||
}, | ||
}, | ||
PermissionController: { | ||
getCaveat: () => ({ | ||
type: 'authorizedScopes', | ||
value: { | ||
requiredScopes: {}, | ||
optionalScopes: { | ||
'eip155:1': { | ||
accounts: ['eip155:1:0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'], | ||
}, | ||
}, | ||
isMultichainOrigin: false, | ||
}, | ||
}), | ||
}, | ||
TransactionController: { | ||
addTransactionBatch: jest.fn().mockResolvedValue({ batchId: 123 }), | ||
isAtomicBatchSupported: jest.fn().mockResolvedValue([true]), | ||
}, | ||
}, | ||
controllerMessenger: { | ||
call: jest.fn().mockReturnValue({ configuration: { chainId: '0xaa36a7' } }), | ||
}, | ||
})); | ||
|
||
const MockEngine = jest.mocked(Engine); | ||
import { createAsyncWalletMiddleware } from './createAsyncWalletMiddleware'; | ||
|
||
describe('createAsyncWalletMiddleware', () => { | ||
it('return instance of Wallet Middleware', async () => { | ||
const middleware = createAsyncWalletMiddleware(); | ||
expect(middleware).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('getAccounts', () => { | ||
it('return selected account address', async () => { | ||
const accounts = await getAccounts(); | ||
expect(accounts).toStrictEqual([MOCK_ACCOUNT]); | ||
}); | ||
|
||
it('return empty array if origin is metamask and AccountsController returns no selected account', async () => { | ||
MockEngine.context.AccountsController.getSelectedAccount = (() => | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
undefined) as any; | ||
const accounts = await getAccounts(); | ||
expect(accounts).toStrictEqual([]); | ||
}); | ||
}); | ||
|
||
describe('processSendCalls', () => { | ||
const MOCK_PARAMS = { | ||
version: '2.0.0', | ||
from: '0x935e73edb9ff52e23bac7f7ty67u1ecd06d05477', | ||
chainId: '0xaa36a7', | ||
atomicRequired: true, | ||
calls: [ | ||
{ | ||
to: '0x0c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb', | ||
data: '0x654365436543', | ||
value: '0x3B9ACA00', | ||
}, | ||
], | ||
} as SendCalls; | ||
const MOCK_REQUEST = { | ||
method: 'wallet_sendCalls', | ||
params: MOCK_PARAMS, | ||
jsonrpc: '2.0', | ||
id: 1315126919, | ||
toNative: true, | ||
origin: 'metamask.github.io', | ||
networkClientId: 'sepolia', | ||
} as JsonRpcRequest; | ||
|
||
it('creates transaction instance for batch request', async () => { | ||
const result = await processSendCalls(MOCK_PARAMS, MOCK_REQUEST); | ||
expect( | ||
Engine.context.TransactionController.addTransactionBatch, | ||
).toHaveBeenCalledTimes(1); | ||
expect(result.id).toStrictEqual(123); | ||
}); | ||
|
||
it('throw error if wrong version of request is used', async () => { | ||
expect(async () => { | ||
await processSendCalls( | ||
{ ...MOCK_PARAMS, version: '3.0.0' }, | ||
MOCK_REQUEST, | ||
); | ||
}).rejects.toThrow('Version not supported: Got 3.0.0, expected 2.0.0'); | ||
}); | ||
|
||
it('throw error if TransactionController.isAtomicBatchSupported returns false', async () => { | ||
Engine.context.TransactionController.isAtomicBatchSupported = jest | ||
.fn() | ||
.mockResolvedValue([]); | ||
expect(async () => { | ||
await processSendCalls(MOCK_PARAMS, MOCK_REQUEST); | ||
}).rejects.toThrow('EIP-7702 not supported on chain: 0xaa36a7'); | ||
Engine.context.TransactionController.isAtomicBatchSupported = jest | ||
.fn() | ||
.mockResolvedValue([{}]); | ||
}); | ||
|
||
it('throws if top-level capability is required', async () => { | ||
await expect( | ||
processSendCalls( | ||
{ | ||
...MOCK_PARAMS, | ||
capabilities: { | ||
test: {}, | ||
test2: { optional: true }, | ||
test3: { optional: false }, | ||
}, | ||
}, | ||
MOCK_REQUEST, | ||
), | ||
).rejects.toThrow('Unsupported non-optional capabilities: test, test3'); | ||
}); | ||
|
||
it('throws if call capability is required', async () => { | ||
await expect( | ||
processSendCalls( | ||
{ | ||
...MOCK_PARAMS, | ||
calls: [ | ||
...MOCK_PARAMS.calls, | ||
{ | ||
...MOCK_PARAMS.calls[0], | ||
capabilities: { | ||
test: {}, | ||
test2: { optional: true }, | ||
test3: { optional: false }, | ||
}, | ||
}, | ||
], | ||
}, | ||
MOCK_REQUEST, | ||
), | ||
).rejects.toThrow('Unsupported non-optional capabilities: test, test3'); | ||
}); | ||
|
||
it('throw error if dappChainId is different from request chainId', async () => { | ||
Engine.controllerMessenger.call = jest | ||
.fn() | ||
.mockReturnValue({ configuration: { chainId: '0x1' } }); | ||
expect(async () => { | ||
await processSendCalls(MOCK_PARAMS, { | ||
...MOCK_REQUEST, | ||
networkClientId: 'linea', | ||
} as JsonRpcRequest); | ||
}).rejects.toThrow( | ||
'Chain ID must match the dApp selected network: Got 0xaa36a7, expected 0x1', | ||
); | ||
}); | ||
}); |
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.
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.
Is this removal necessary/related?
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.
Or I guess its moved