Skip to content

Add unit tests for incoming transaction block events#9755

Merged
Gudahtt merged 6 commits intodevelopfrom
add-incoming-transactions-controller-block-event-tests
Oct 30, 2020
Merged

Add unit tests for incoming transaction block events#9755
Gudahtt merged 6 commits intodevelopfrom
add-incoming-transactions-controller-block-event-tests

Conversation

@Gudahtt
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt commented Oct 29, 2020

Unit tests have been added to the incoming transactions controller to ensure that block updates are correctly resulting in state updates when incoming transactions are enabled. All other events that trigger state updates are tested as well.

The tests were written to be minimally dependent upon implementation details of the controller itself. nock was used to mock the API response from Etherscan. Each event is triggered asynchronously by sinon, as in production they are likely only triggered
asynchronously.

This was extracted from #9583

This PR includes a new waitUntilCalled module meant to help with writing asynchronous tests. It allows you to wait until a stub has been called.

@Gudahtt Gudahtt force-pushed the incoming-transaction-tests-replace-shared-mocks branch from d55dfd8 to a0a2dcb Compare October 29, 2020 06:21
@Gudahtt Gudahtt force-pushed the add-incoming-transactions-controller-block-event-tests branch 3 times, most recently from e187005 to a37c968 Compare October 29, 2020 06:30
@Gudahtt
Copy link
Copy Markdown
Member Author

Gudahtt commented Oct 29, 2020

This depends upon #9754
This is now ready for review

@Gudahtt Gudahtt force-pushed the add-incoming-transactions-controller-block-event-tests branch from a37c968 to fea2e1a Compare October 29, 2020 06:36
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [fea2e1a]
Page Load Metrics (402 ± 70 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint308337115
domContentLoaded24674140014770
load24774340214770
domInteractive24574140014770

Base automatically changed from incoming-transaction-tests-replace-shared-mocks to develop October 29, 2020 15:16
@Gudahtt Gudahtt force-pushed the add-incoming-transactions-controller-block-event-tests branch from fea2e1a to 6843e38 Compare October 29, 2020 15:16
@Gudahtt Gudahtt marked this pull request as ready for review October 29, 2020 15:22
@Gudahtt Gudahtt requested a review from a team as a code owner October 29, 2020 15:22
@Gudahtt Gudahtt requested a review from rekmarks October 29, 2020 15:22
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [6843e38]
Page Load Metrics (426 ± 61 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint297539126
domContentLoaded23859342512661
load23959542612661
domInteractive23859342412661

Copy link
Copy Markdown
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

These tests look good, I mainly have some questions/nits. My review should not be considered final, and I have a significant amount of work to do to fully understand the incoming transactions controller. It'd be great if someone with more context could do a full pass.

One general requested change for the test file:

We should update all existing assert.equal and deepEqual calls to their strict equivalents.

Unit tests have been added to the incoming transactions controller to
ensure that block updates are correctly resulting in state updates when
incoming transactions are enabled. All other events that trigger state
updates are tested as well.

The tests were written to be minimally dependent upon implementation
details of the controller itself. `nock` was used to mock the API
response from Etherscan. Each event is triggered asynchronously by
`sinon`, as in production they are likely only triggered
asynchronously.

This was extracted from #9583

This PR includes a new `waitUntilCalled` module meant to help with
writing asynchronous tests. It allows you to wait until a stub has been
called.
@Gudahtt Gudahtt force-pushed the add-incoming-transactions-controller-block-event-tests branch from 6843e38 to 28a3d43 Compare October 29, 2020 20:53
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [28a3d43]
Page Load Metrics (438 ± 73 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint298839136
domContentLoaded24674643615072
load24874743815173
domInteractive24674543515072

Gudahtt added a commit that referenced this pull request Oct 29, 2020
This comment block describes the responsibilities of this controller.
This was motivated by a suggestion made during review of #9755 [1]

[1]: #9755 (comment)
Copy link
Copy Markdown
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

My understanding of the incoming transactions controller is still poor, but I can't find a fault with how these tests are implemented.

Gudahtt added a commit that referenced this pull request Oct 30, 2020
This comment block describes the responsibilities of this controller.
This was motivated by a suggestion made during review of #9755 [1]

[1]: #9755 (comment)
@Gudahtt Gudahtt merged commit 59aab93 into develop Oct 30, 2020
@Gudahtt Gudahtt deleted the add-incoming-transactions-controller-block-event-tests branch October 30, 2020 14:17
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants