Skip to content

Commit

Permalink
chore: add unit test for native currency validation (#12234)
Browse files Browse the repository at this point in the history
## **Description**

Adds unit test coverage for
#11693

## **Related issues**


## **Manual testing steps**


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
bergeron authored Nov 13, 2024
1 parent 09fa44a commit 282cc80
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/core/RPCMethods/wallet_addEthereumChain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,42 @@ describe('RPC Method - wallet_addEthereumChain', () => {
}
});

it('should report native currency symbol length being too long', async () => {
const symbol = 'aaaaaaaaaaaaaaa';
await expect(
wallet_addEthereumChain({
req: {
params: [{
...correctParams,
nativeCurrency: { symbol, decimals: 18 },
}],
},
...otherOptions,
}),
).rejects.toThrow(
`Expected 1-6 character string 'nativeCurrency.symbol'. Received:\n${symbol}`,
);
});

it('should allow 1 letter native currency symbols', async () => {
jest.mock('./networkChecker.util');
jest
.spyOn(Engine.context.NetworkController, 'addNetwork')
.mockResolvedValue({ rpcEndpoints: [] });

await wallet_addEthereumChain({
req: {
params: [
{
...correctParams,
nativeCurrency: { symbol: 'a', decimals: 18 },
},
],
},
...otherOptions,
});
});

describe('Approval Flow', () => {
it('should start and end a new approval flow if chain does not already exist', async () => {
jest
Expand Down

0 comments on commit 282cc80

Please sign in to comment.