Skip to content
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

Jl/caip multichain/test cleanups #26698

Merged
merged 9 commits into from
Aug 29, 2024

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Aug 27, 2024

Description

Test cleanup chores

Open in GitHub Codespaces

Related issues

See: https://github.com/MetaMask/MetaMask-planning/issues/3046

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

invoker: 'test.com',
parentCapability: Caip25EndowmentPermissionName,
});
}).toThrow(new Error('missing required caveat'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a todo to improve this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we're going to have to just comb through all the changes in the feature branch to make sure we catch all these because not all of them have TODO comments

expect(isChainIdSupportedBody).toContain('findNetworkClientIdByChainId');
});

it('throws if the input requiredScopes ScopesObject is not already validated and flattened', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be requiredScopes in the mocked value returned by the validateAndFlattenScopes mock for this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment below #26698 (comment)

}).toThrow(/Expected values to be strictly deep-equal/u);
});

it('throws if the input optionalScopes ScopesObject is not already validated and flattened', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh is the idea here that the validateAndFlattenScopes mock is returning an empty object for flattenedOptionalScopes because the optionalScopes were invalid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the wording of these tests could be a bit more clear? "Throws if the input does not match the output of validateAndFlattenScopes"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh is the idea here that the validateAndFlattenScopes mock is returning an empty object for flattenedOptionalScopes because the optionalScopes were invalid?

right. invalid OR just not flattened, but the point is that the input ScopesObject does not match

Maybe the wording of these tests could be a bit more clear? "Throws if the input does not match the output of validateAndFlattenScopes"?

I thought about this, but it seems too descriptive / describes the wrong thing? I mean it's not wrong, it just seems that our goal is to throw when the input ScopesObject is not validated and flattened. How we achieve that is an implementation detail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense. I feel like not everyone feels the same way about naming/describing tests. Personally when the test name doesn't clearly/directly describe what's being tested I like to add inline comments to explain the discrepancy. But its not strictly necessary. And not everyone agrees with this thinking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. It's unclear from the test setup why the mock return value of validateAndFlattenScopes must be changed. I've updated the scenario descriptions because of that bcd8ebc

@@ -138,7 +133,7 @@ async function requestEthereumAccountsHandler(
properties: {
is_first_visit: isFirstVisit,
number_of_accounts: Object.keys(metamaskState.accounts).length,
number_of_accounts_connected: numberOfConnectedAccounts,
number_of_accounts_connected: accounts,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?
a) is accounts a number, as the property name seems to imply it should be?
b) how does this relate tot he other changes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) whoops... it should be a number, but it isn't currently. good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b) getAccounts(), a hook we need for getting accounts ordered correctly, already gets the accounts from the permission. We don't need a separate call to getPermissionsForOrigin to also get the accounts (ordered potentially incorrectly, not that it matters). So i got rid of the getPermissionsForOrigin call and removed it from the hooks

@jiexi jiexi marked this pull request as ready for review August 29, 2024 20:26
@jiexi jiexi requested a review from a team as a code owner August 29, 2024 20:26
@jiexi jiexi merged commit 26b4aa2 into caip-multichain Aug 29, 2024
16 of 18 checks passed
@jiexi jiexi deleted the jl/caip-multichain/test-cleanups branch August 29, 2024 20:27
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants