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

fix(assets-controllers): TokenRatesController state consistency #3624

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Dec 6, 2023

Explanation

The TokenRatesController has been updated to ensure that the two sets of exchange rate state are always consistent with each other. Previously if the method updateExchangeRatesByChainId was called directly, it would not update the contractExchangeRates state even if the equivalent part of contractExchangeRatesByChainId was updated by that call.

The tests have undergone a substantial refactor to ensure that we cover all cases between both of these update methods. The test cases written previously left out many test cases. We should now have better (but not perfect) coverage, and the tests are now shared between the two methods because they have identical test cases.

References

Fixes #3597

Changelog

@metamask/assets-controllers

  • Fixed: Fixed bug where the contractExchangeRates state would sometimes be stale after calling updateExchangeRatesByChainId

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

@Gudahtt Gudahtt force-pushed the keep-token-rates-state-consistent branch 10 times, most recently from 7d2b6c9 to 9abf35c Compare December 7, 2023 15:18
The TokenRatesController has been updated to ensure that the two sets
of exchange rate state are always consistent with each other.
Previously if the method `updateExchangeRatesByChainId` was called
directly, it would not update the `contractExchangeRates` state even if
the equivalent part of `contractExchangeRatesByChainId` was updated by
that call.

The tests have undergone a substantial refactor to ensure that we cover
all cases between both of these update methods. The test cases written
previously left out many test cases. We should now have better (but not
perfect) coverage, and the tests are now shared between the two methods
because they have identical test cases.

Fixes #3597
@Gudahtt Gudahtt force-pushed the keep-token-rates-state-consistent branch from 9abf35c to 7df71ef Compare December 7, 2023 15:19
@Gudahtt Gudahtt marked this pull request as ready for review December 7, 2023 15:19
@Gudahtt Gudahtt requested a review from a team as a code owner December 7, 2023 15:19
cryptodev-2s
cryptodev-2s previously approved these changes Dec 7, 2023
Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

One thing but otherwise looks good!

}),
validateCurrencySupported: jest.fn().mockReturnValue(
false,
// Cast used because this method has an assertion in the return
Copy link
Contributor

@mcmire mcmire Dec 7, 2023

Choose a reason for hiding this comment

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

Hmm, yes, okay, I can investigate this. Seems fine for now though.

'0x0000000000000000000000000000000000000002',
];
const tokenPricesService = buildMockTokenPricesService({
fetchTokenPrices: jest.fn().mockResolvedValue({
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this is better than my silly fetchTokenPricesWithIncreasingPriceForEachToken function 😂

Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants