-
Notifications
You must be signed in to change notification settings - Fork 369
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
[BlockchainApi] Add ability to get exchange rates from/to cGLD or cUSD #2005
[BlockchainApi] Add ability to get exchange rates from/to cGLD or cUSD #2005
Conversation
WITHOUT mocking contractkit: - yarn test (clean cache): ~27secs - yarn test (populated cache): 23 secs WITH mocking contractkit: - yarn test (clean cache): ~8secs - yarn test (populated cache): ~4secs
Similar gains as seen in #2005
…hain-api-convert-gold
…hain-api-convert-gold
deploy runs yarn from packages/blockchain-api so ends up with slightly different node_modules
This is so blockchain-api in celo-testnet project can access the firebase db in celo-org-mobile project This is temporary until we migrate blockchain-api to celo-org-mobile too.
Codecov Report
@@ Coverage Diff @@
## master #2005 +/- ##
=======================================
Coverage 74.88% 74.88%
=======================================
Files 279 279
Lines 7797 7797
Branches 690 690
=======================================
Hits 5839 5839
Misses 1842 1842
Partials 116 116
Continue to review full report at Codecov.
|
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! Left some minor comments
// TODO: move project to celo-org-mobile | ||
// until then, using serviceAccountKey for all envs | ||
// tslint:disable-next-line: no-constant-condition | ||
if (true /* DEPLOY_ENV === 'local' */) { |
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.
Remove if (true) ? Or uncomment /* DEPLOY_ENV === 'local' */?
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.
I wanted to keep it this way so we can uncomment once we deploy it to celo-org-mobile
.
Makes sense?
} | ||
|
||
export default class GoldExchangeRateAPI<TContext = any> extends DataSource { | ||
// TODO(jeanregisser): memoize results |
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.
TODOs here and below for a future PR? Or left in for now?
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.
I left them for a future PR.
expect(mockGoldGetExchangeRate).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should retrieve rate for MXN/cGLD', async () => { |
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.
Does this test cover any additional logic from the MXN/cGLD
one given the mocks?
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.
They look really similar indeed but the idea was to cover both local to cGLD and cGLD to local.
expect(mockGoldGetExchangeRate).toHaveBeenCalledTimes(0) | ||
}) | ||
|
||
it('should retrieve rate for MXN/USD', async () => { |
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.
Same with this one- is there anything this test would catch that wouldn't be covered by the USD/MXN
one?
Could also consider adding some tests for getConversionSteps
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 similar to my comment above.
I decided not to test getConversionSteps
directly to avoid testing the internals too much.
const pair = `${fromCode}/${toCode}` | ||
|
||
if (pair === 'cUSD/USD' || pair === 'USD/cUSD') { | ||
// TODO: use real rates once we have the data |
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.
👍
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.
A few small comments but mostly looks good!
packages/blockchain-api/package.json
Outdated
@@ -23,6 +23,7 @@ | |||
"bignumber.js": "^7.2.0", | |||
"dotenv": "^6.1.0", | |||
"express": "^4.16.4", | |||
"firebase-admin": "^8.8.0", |
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.
Please use the same version we're using in other monorepo packages (8.6.1)
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.
👍
try { | ||
const serviceAccount = require('../serviceAccountKey.json') | ||
return admin.credential.cert(serviceAccount) | ||
} catch { |
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.
Should we catch and log the error object here?
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 probably, I blindly cut and pasted this from notification-service
@@ -0,0 +1 @@ | |||
export { default as CurrencyConversionAPI } from './CurrencyConversionAPI' |
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.
Why create this index file instead of having other files import from CurrencyConversionAPI directly?
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.
Mostly to hide the internal file organisation of currency conversion with its somewhat private internal modules (ExchangeRateAPI
and GoldExchangeRateAPI
).
But doesn't really matter.
* master: [Wallet] Use Charles proxy to see eth JSON rpc calls when using forno (#2204) [Wallet] Disable skip button when the user enable contact access (#2224) [Wallet] Redesigning notification lists (#1967) [Wallet] Fix crash on iOS when segment is enabled (#2222) Update documentation wrt. epoch rewards fractions (#2182) Improvement facilitating to run a full node (#2130) [BlockchainApi] Add ability to get exchange rates from/to cGLD or cUSD (#2005) Improve reliability of e2e governance test (#2208) Fix/protocol test flakyness (#2155) Fix bignumber display in CLI (#2212) Doc changes to address frequently asked questions (#2209) Upgrade TS version (#2196) Wait for only waitTime - 1 blocks (#2207) Minor baklava docs reconnection fixes (#2215) Update walletkit gateway fee to fix transactions in forno mode (#2211) Update baklava network ID in docs for 1.1 (#2214) Support more than 1 attesation bot at a time (#2192) Check sync status of attestation service (#2191) Indicate to run Twilio globally (#2193) Add Twilio and attestation bot envs (#2194)
Description
Add ability to get exchange rates from/to cGLD or cUSD.
For now the cUSD/USD and USD/cUSD rates are assumed to be 1.
Also going from cGLD to local currency (or vice versa) is currently assumed to be the same as cGLD -> cUSD -> USD -> local currency.
And similar to cUSD to local currency, but with one less step.
Tested
Added new tests.
Successfully deployed on integration: https://integration-dot-celo-testnet.appspot.com
Other changes
blockchain-api
incelo-testnet
project can access the firebase db incelo-org-mobile
project. This is temporary until we migrateblockchain-api
tocelo-org-mobile
too.WITHOUT mocking contractkit:
WITH mocking contractkit:
Related issues
Backwards compatibility
Yes