diff --git a/packages/jellyfish-api-core/__tests__/category/poolpair/compositeSwap.test.ts b/packages/jellyfish-api-core/__tests__/category/poolpair/compositeSwap.test.ts index b1699ae444..63752c9412 100644 --- a/packages/jellyfish-api-core/__tests__/category/poolpair/compositeSwap.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/poolpair/compositeSwap.test.ts @@ -594,4 +594,60 @@ describe('compositeSwap', () => { await expect(promise).rejects.toThrow(RpcApiError) await expect(promise).rejects.toThrow('TokenTo was not found') }) + + it('should not compositeSwap for more than 3 pools', async () => { + await testing.generate(20) + const [toAddress, fromAddress] = await testing.generateAddress(2) + await testing.token.create({ symbol: 'T1' }) + await testing.token.create({ symbol: 'T2' }) + await testing.token.create({ symbol: 'T3' }) + await testing.token.create({ symbol: 'T4' }) + await testing.token.create({ symbol: 'T5' }) + await testing.generate(1) + + await testing.token.mint({ symbol: 'T1', amount: 20 }) + await testing.token.mint({ symbol: 'T2', amount: 20 }) + await testing.token.mint({ symbol: 'T3', amount: 20 }) + await testing.token.mint({ symbol: 'T4', amount: 20 }) + await testing.token.mint({ symbol: 'T5', amount: 10 }) + await testing.generate(1) + + await testing.poolpair.create({ tokenA: 'T1', tokenB: 'T2' }) + await testing.poolpair.create({ tokenA: 'T2', tokenB: 'T3' }) + await testing.poolpair.create({ tokenA: 'T3', tokenB: 'T4' }) + await testing.poolpair.create({ tokenA: 'T4', tokenB: 'T5' }) + await testing.generate(1) + + await testing.poolpair.add({ + a: { symbol: 'T1', amount: 10 }, + b: { symbol: 'T2', amount: 10 } + }) + await testing.poolpair.add({ + a: { symbol: 'T2', amount: 10 }, + b: { symbol: 'T3', amount: 10 } + }) + await testing.poolpair.add({ + a: { symbol: 'T3', amount: 10 }, + b: { symbol: 'T4', amount: 10 } + }) + await testing.poolpair.add({ + a: { symbol: 'T4', amount: 10 }, + b: { symbol: 'T5', amount: 10 } + }) + await testing.generate(1) + + await testing.token.send({ symbol: 'T1', amount: 1, address: fromAddress }) + await testing.generate(1) + + const metadata: poolpair.PoolSwapMetadata = { + from: fromAddress, + tokenFrom: 'T1', + amountFrom: 1, + to: toAddress, + tokenTo: 'T5', + maxPrice: 1 + } + + await client.poolpair.testPoolSwap(metadata) + }) })