From fcdabed84078f06fa4eaa186123b28def3128c48 Mon Sep 17 00:00:00 2001 From: JD Date: Wed, 14 Feb 2024 10:47:38 +0100 Subject: [PATCH] add tests and ci --- .github/workflows/publish.yml | 1 + package.json | 1 + src/quote/indexQuoteProvider.ts | 2 ++ src/tests/btc2x.test.ts | 42 +++++++++++++++++++++++++++++++++ src/tests/utils/quoteTokens.ts | 8 +++++++ 5 files changed, 54 insertions(+) create mode 100644 src/tests/btc2x.test.ts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a4640519..07e2d86e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,6 +32,7 @@ jobs: - run: npm ci - run: npm run lint - run: npm run build --if-present + - run: npm run hardhat & npm run test:btc2x - run: npm run hardhat & npm run test:cdeti - run: npm run hardhat & npm run test:dseth - run: npm run hardhat & npm run test:eth2x diff --git a/package.json b/package.json index 843a0be4..beeb86d8 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "lint": "prettier -c . && eslint ./src", "lint:fix": "prettier -w . && eslint ./src --fix", "test": "jest", + "test:btc2x": "npm test src/tests/btc2x.test.ts", "test:cdeti": "npm test src/tests/cdeti", "test:dseth": "npm test src/tests/dseth", "test:eth2x": "npm test src/tests/eth2x.test.ts", diff --git a/src/quote/indexQuoteProvider.ts b/src/quote/indexQuoteProvider.ts index 1c32bd27..dd12ff28 100644 --- a/src/quote/indexQuoteProvider.ts +++ b/src/quote/indexQuoteProvider.ts @@ -10,6 +10,7 @@ import { DiversifiedStakedETHIndex, ETH2xFlexibleLeverageIndex, GitcoinStakedETHIndex, + IndexCoopBitcoin2xIndex, IndexCoopEthereum2xIndex, InterestCompoundingETHIndex, LeveragedrEthStakingYield, @@ -178,6 +179,7 @@ function getContractType(token: string): FlashMintContractType | null { if ( token === BTC2xFlexibleLeverageIndex.symbol || token === ETH2xFlexibleLeverageIndex.symbol || + token === IndexCoopBitcoin2xIndex.symbol || token === IndexCoopEthereum2xIndex.symbol || token === InterestCompoundingETHIndex.symbol || token === LeveragedrEthStakingYield.symbol diff --git a/src/tests/btc2x.test.ts b/src/tests/btc2x.test.ts new file mode 100644 index 00000000..ebb9a73d --- /dev/null +++ b/src/tests/btc2x.test.ts @@ -0,0 +1,42 @@ +import { + LocalhostProvider, + QuoteTokens, + SignerAccount4, + TestFactory, + wei, + ZeroExApiSwapQuote, +} from './utils' + +const { btc2x, eth } = QuoteTokens +const zeroExApi = ZeroExApiSwapQuote + +describe('BTC2X (mainnet)', () => { + let factory: TestFactory + beforeEach(async () => { + const provider = LocalhostProvider + const signer = SignerAccount4 + factory = new TestFactory(provider, signer, zeroExApi) + }) + + test('can mint with ETH', async () => { + await factory.fetchQuote({ + isMinting: true, + inputToken: eth, + outputToken: btc2x, + indexTokenAmount: wei('1'), + slippage: 0.5, + }) + await factory.executeTx() + }) + + test('can redeem with ETH', async () => { + await factory.fetchQuote({ + isMinting: false, + inputToken: btc2x, + outputToken: eth, + indexTokenAmount: wei('1'), + slippage: 0.5, + }) + await factory.executeTx() + }) +}) diff --git a/src/tests/utils/quoteTokens.ts b/src/tests/utils/quoteTokens.ts index 6ef4147d..67fc3846 100644 --- a/src/tests/utils/quoteTokens.ts +++ b/src/tests/utils/quoteTokens.ts @@ -8,6 +8,7 @@ import { ETH, ETH2xFlexibleLeverageIndex, GitcoinStakedETHIndex, + IndexCoopBitcoin2xIndex, IndexCoopEthereum2xIndex, InterestCompoundingETHIndex, LeveragedrEthStakingYield, @@ -22,6 +23,12 @@ import { } from 'constants/tokens' import { QuoteToken } from 'quote/quoteToken' +const btc2x: QuoteToken = { + address: IndexCoopBitcoin2xIndex.address!, + decimals: 18, + symbol: IndexCoopBitcoin2xIndex.symbol, +} + const btc2xfli: QuoteToken = { address: BTC2xFlexibleLeverageIndex.address!, decimals: 18, @@ -136,6 +143,7 @@ const wseth: QuoteToken = { } export const QuoteTokens = { + btc2x, btc2xfli, cdeti, dai,