-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bridged via USD rates from Coingecko.
- Loading branch information
Showing
2 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
/* global describe, it, expect */ | ||
|
||
import { | ||
FiatApiBridgedFiatCurrency, | ||
FiatApiSupportedCryptoCurrency, | ||
FiatApiSupportedFiatCurrency, | ||
getHistoricExchangeRates, | ||
} from '../src/fiat-api/FiatApi'; | ||
|
||
describe('FiatApi', () => { | ||
it('can fetch historic USD rates for BTC', async () => { | ||
const timestamps = [ | ||
new Date('2023-01-01T00:00:00.000Z').getTime(), | ||
new Date('2023-01-01T01:00:00.000Z').getTime(), | ||
new Date('2023-01-01T02:00:00.000Z').getTime(), | ||
new Date('2023-01-01T03:00:00.000Z').getTime(), | ||
new Date('2023-01-01T04:00:00.000Z').getTime(), | ||
new Date('2023-10-13T05:00:00.000Z').getTime(), | ||
new Date('2023-10-13T06:00:00.000Z').getTime(), | ||
new Date('2023-10-13T07:00:00.000Z').getTime(), | ||
new Date('2023-10-13T08:00:00.000Z').getTime(), | ||
new Date('2023-10-13T09:00:00.000Z').getTime(), | ||
]; | ||
const rates = await getHistoricExchangeRates( | ||
FiatApiSupportedCryptoCurrency.BTC, | ||
FiatApiSupportedFiatCurrency.USD, | ||
timestamps, | ||
); | ||
expect(rates.size).toBe(10); | ||
expect(rates.get(timestamps[0])).toBeDefined(); | ||
expect(rates.get(timestamps[5])).toBeDefined(); | ||
expect(rates.get(timestamps[1])).toBeGreaterThan(16500); | ||
expect(rates.get(timestamps[6])).toBeGreaterThan(16800); | ||
}, 30e3); | ||
|
||
it('can fetch historic CRC (bridged) rates for BTC', async () => { | ||
const timestamps = [ | ||
new Date('2023-01-01T00:00:00.000Z').getTime(), | ||
new Date('2023-01-01T01:00:00.000Z').getTime(), | ||
new Date('2023-01-01T02:00:00.000Z').getTime(), | ||
new Date('2023-01-01T03:00:00.000Z').getTime(), | ||
new Date('2023-01-01T04:00:00.000Z').getTime(), | ||
new Date('2023-10-13T05:00:00.000Z').getTime(), | ||
new Date('2023-10-13T06:00:00.000Z').getTime(), | ||
new Date('2023-10-13T07:00:00.000Z').getTime(), | ||
new Date('2023-10-13T08:00:00.000Z').getTime(), | ||
new Date('2023-10-13T09:00:00.000Z').getTime(), | ||
]; | ||
const rates = await getHistoricExchangeRates( | ||
FiatApiSupportedCryptoCurrency.BTC, | ||
FiatApiBridgedFiatCurrency.CRC, | ||
timestamps, | ||
); | ||
expect(rates.size).toBe(10); | ||
expect(rates.get(timestamps[0])).toBeDefined(); | ||
expect(rates.get(timestamps[5])).toBeDefined(); | ||
expect(rates.get(timestamps[1])).toBeGreaterThan(165000); // ~price in BTC * 10 | ||
expect(rates.get(timestamps[6])).toBeGreaterThan(168000); // ~price in BTC * 10 | ||
}, 30e3); | ||
}); |