|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { TEST_CLIENT } from "~test/test-clients.js"; |
| 3 | +import { base } from "../../chains/chain-definitions/base.js"; |
| 4 | +import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js"; |
| 5 | +import { convertCryptoToFiat } from "./cryptoToFiat.js"; |
| 6 | + |
| 7 | +describe.runIf(process.env.TW_SECRET_KEY)("Pay: crypto-to-fiat", () => { |
| 8 | + it("should convert ETH price to USD on Ethereum mainnet", async () => { |
| 9 | + const result = await convertCryptoToFiat({ |
| 10 | + chainId: 1, |
| 11 | + fromTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 12 | + fromAmount: 1, |
| 13 | + to: "usd", |
| 14 | + client: TEST_CLIENT, |
| 15 | + }); |
| 16 | + expect(result).toBeDefined(); |
| 17 | + // Should be a number |
| 18 | + expect(!Number.isNaN(Number(result))).toBe(true); |
| 19 | + // Since eth is around US$3000, we can add a test to check if the price is greater than $1500 (as a safe margin) |
| 20 | + // let's hope that scenario does not happen :( |
| 21 | + expect(Number(result) > 1500).toBe(true); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should convert ETH price to USD on Base mainnet", async () => { |
| 25 | + const result = await convertCryptoToFiat({ |
| 26 | + chainId: base.id, |
| 27 | + fromTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 28 | + fromAmount: 1, |
| 29 | + to: "usd", |
| 30 | + client: TEST_CLIENT, |
| 31 | + }); |
| 32 | + expect(result).toBeDefined(); |
| 33 | + // Should be a number |
| 34 | + expect(!Number.isNaN(Number(result))).toBe(true); |
| 35 | + // Since eth is around US$3000, we can add a test to check if the price is greater than $1500 (as a safe margin) |
| 36 | + // let's hope that scenario does not happen :( |
| 37 | + expect(Number(result) > 1500).toBe(true); |
| 38 | + }); |
| 39 | +}); |
0 commit comments