Skip to content

Fix misaligned mock eth query types in controller tests - #2037

Merged
MajorLift merged 5 commits into
mainfrom
231114-fix-mock-eth-query
Nov 15, 2023
Merged

Fix misaligned mock eth query types in controller tests#2037
MajorLift merged 5 commits into
mainfrom
231114-fix-mock-eth-query

Conversation

@MajorLift

@MajorLiftMajorLift commented Nov 14, 2023

Copy link
Copy Markdown
Contributor

Explanation

Fixes // @ts-expect-error Mock eth query does not fulfill type requirements annotations throughout core repo.

References

Changelog

N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@MajorLiftMajorLift added the team-wallet-framework Deprecated: Please use `team-core-platform` instead. label Nov 14, 2023
@MajorLiftMajorLift self-assigned this Nov 14, 2023
@MajorLift
MajorLift requested a review from a team as a code ownerNovember 14, 2023 17:05

@mcmiremcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These tests aren't set up very well :( I'm curious whether jest.mock would be a better approach to mock eth-query rather than making fake versions. That would be a bigger refactor though, so for now I've tried to suggest changes that I hope wouldn't take too long to resolve.

Comment on lines 440 to 446

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm. Now that we have a fake provider, I'm wondering if a better way to achieve this without the type assertion would be something like this:

Suggested change
classMockEthQueryextendsEthQuery{
getBlockByHash(blockId: any,cb: any){
cb(null,{id: blockId});
}
}
// @ts-expect-error Mock eth query does not fulfill type requirements
constresult=awaitutil.query(newEthQuery(),'getBlockByHash',[
'0x1234',
]);
constresult=awaitutil.query(
newMockEthQuery({}asProvider),
constethQuery=newEthQuery(newFakeProvider());
jest.spyOn(ethQuery,'getBlockByHash').mockResolvedValue({id: '0x1234'});
constresult=awaitutil.query(
ethQuery,

(We'll have to import FakeProvider at the top of course)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Is this the FakeProvider in network-controller? I'm getting this error:

errorTS2345: Argumentoftype'FakeProvider'isnotassignabletoparameteroftype'Provider'.

It's also currently not exported from network-controller so ideally we'd need to create a new release to add the export.

@MajorLiftMajorLiftNov 14, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@mcmiremcmireNov 14, 2023

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I had thought that FakeProvider was defined at the top level like FakeBlockTracker. We'd have to pull it out to use it like this, so never mind :(

The way you had it is probably fine for now, and we can refactor it later.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We could keep this PR open until that's done. FakeProvider seems like a definite improvement over {} as Provider.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, new PR created here: #2039

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Didn't realize it would be that simple.😅 Just added a review.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've merged #2039 so these changes should now work.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed all of the mock eth queries to use FakeProvider: 687d3eb

Comment threadpackages/gas-fee-controller/src/fetchBlockFeeHistory.test.ts Outdated
Comment threadpackages/gas-fee-controller/src/fetchGasEstimatesViaEthFeeHistory.test.ts Outdated
Comment threadpackages/transaction-controller/src/utils/transaction-type.test.ts Outdated
@MajorLift
MajorLiftforce-pushed the 231114-fix-mock-eth-query branch from a43b654 to 0a03684CompareNovember 14, 2023 19:28
@socket-security

socket-securityBot commented Nov 14, 2023

Copy link
Copy Markdown

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

@MajorLift
MajorLiftforce-pushed the 231114-fix-mock-eth-query branch from 6de0c76 to 699e88bCompareNovember 15, 2023 17:18
@MajorLift
MajorLiftforce-pushed the 231114-fix-mock-eth-query branch from 699e88b to 687d3ebCompareNovember 15, 2023 17:22

@mcmiremcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good!

@MajorLift
MajorLift merged commit 5f62ad4 into mainNov 15, 2023
@MajorLift
MajorLift deleted the 231114-fix-mock-eth-query branch November 15, 2023 18:56
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-wallet-frameworkDeprecated: Please use `team-core-platform` instead.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix misaligned mock eth query types in controller tests

2 participants

@MajorLift@mcmire