-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Conversation
7d2b6c9
to
9abf35c
Compare
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
9abf35c
to
7df71ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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 |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
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 thecontractExchangeRates
state even if the equivalent part ofcontractExchangeRatesByChainId
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
contractExchangeRates
state would sometimes be stale after callingupdateExchangeRatesByChainId
Checklist