diff --git a/packages/jellyfish-api-core/__tests__/category/poolpair/addPoolLiquidity.test.ts b/packages/jellyfish-api-core/__tests__/category/poolpair/addPoolLiquidity.test.ts index 70248a8cfe..1bc049ba25 100644 --- a/packages/jellyfish-api-core/__tests__/category/poolpair/addPoolLiquidity.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/poolpair/addPoolLiquidity.test.ts @@ -39,7 +39,7 @@ describe('Poolpair', () => { const defaultMetadata = { tokenA: 'DFI', tokenB, - commission: 0, + commission: 0.02, status: true, ownerAddress: address } @@ -60,6 +60,33 @@ describe('Poolpair', () => { await container.generate(1) } + it('should give rewards after activation', async () => { + const shareAddress = await container.call('getnewaddress') + + await client.poolpair.addPoolLiquidity({ + '*': ['5@DFI', '100@DDAI'] + }, shareAddress) + await container.generate(1) + + const address = await container.getNewAddress() + await container.call('sendtokenstoaddress', [{}, { [address]: ['20@DFI'] }]) + await container.generate(1) + + await client.poolpair.poolSwap({ + from: address, + tokenFrom: 'DFI', + amountFrom: 10, + to: address, + tokenTo: 'DDAI' + }) + await container.generate(2) + + const accountHistory = (await client.account.listAccountHistory('all')).filter((item) => { + return item.type === 'Commission' + }) + expect(accountHistory).toHaveLength(1) + }) + it('should addPoolLiquidity', async () => { const shareAddress = await container.call('getnewaddress') const data = await client.poolpair.addPoolLiquidity({ diff --git a/packages/jellyfish-api-core/__tests__/category/poolpair/createPoolPair.test.ts b/packages/jellyfish-api-core/__tests__/category/poolpair/createPoolPair.test.ts index 50aa6ca81d..d139a36f07 100644 --- a/packages/jellyfish-api-core/__tests__/category/poolpair/createPoolPair.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/poolpair/createPoolPair.test.ts @@ -1,6 +1,7 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' import BigNumber from 'bignumber.js' +import { RpcApiError } from '../../../src' describe('Poolpair', () => { const container = new MasterNodeRegTestContainer() @@ -78,4 +79,19 @@ describe('Poolpair', () => { } expect(assertions).toStrictEqual(1) }) + + it('should throw error if name is too long', async () => { + const address = await container.call('getnewaddress') + const metadata = { + tokenA: 'DBTC', + tokenB: 'DFI', + commission: 1, + status: true, + ownerAddress: address, + pairSymbol: 'abcdefghijklmnopqrt' + } + const promise = client.poolpair.createPoolPair(metadata) + await expect(promise).rejects.toThrow(RpcApiError) + await expect(promise).rejects.toThrow('pairSymbol is larger than') + }) }) diff --git a/packages/jellyfish-api-core/__tests__/category/poolpair/poolswap.test.ts b/packages/jellyfish-api-core/__tests__/category/poolpair/poolswap.test.ts index 62fa9f1a42..e49f63d157 100644 --- a/packages/jellyfish-api-core/__tests__/category/poolpair/poolswap.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/poolpair/poolswap.test.ts @@ -710,4 +710,20 @@ describe('poolSwap asymmetric pool swap fee', () => { await checkCATtoDFI(poolPairBefore, receiverAddress, feeInPct, feeOutPct) }) + + it('should swap to sender if no recipient is specified', async () => { + await testing.fixture.createPoolPair({ + a: { amount: 1000, symbol: 'CAT' }, + b: { amount: 1000, symbol: 'DFI' } + }) + const swapper = await testing.generateAddress() + await utxosToAccount(container, 1, { address: swapper }) + + await container.call('compositeswap', [{ from: swapper, tokenFrom: 'DFI', amountFrom: 1, tokenTo: 'CAT' }]) + await container.generate(1) + + const swapperAccount = await client.account.getAccount(swapper) + expect(swapperAccount[0]).toContain('CAT') + expect(swapperAccount[0]).not.toContain('DFI') + }) }) diff --git a/packages/jellyfish-api-core/__tests__/category/poolpair/testpoolswap.test.ts b/packages/jellyfish-api-core/__tests__/category/poolpair/testpoolswap.test.ts index c056707b5d..b8eb89341c 100644 --- a/packages/jellyfish-api-core/__tests__/category/poolpair/testpoolswap.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/poolpair/testpoolswap.test.ts @@ -189,4 +189,42 @@ describe('Poolpair', () => { } }) }) + + it('should throw error when no tokenFrom', async () => { + const promise = client.poolpair.testPoolSwap({ + from: await getNewAddress(container), + tokenFrom: '', + amountFrom: 13, + to: await getNewAddress(container), + tokenTo: 'DFI' + }) + + await expect(promise).rejects.toThrow(RpcApiError) + await expect(promise).rejects.toMatchObject({ + payload: { + code: -8, + message: 'tokenFrom is empty', + method: 'testpoolswap' + } + }) + }) + + it('should throw error when no tokenTo', async () => { + const promise = client.poolpair.testPoolSwap({ + from: await getNewAddress(container), + tokenFrom: 'DFI', + amountFrom: 13, + to: await getNewAddress(container), + tokenTo: '' + }) + + await expect(promise).rejects.toThrow(RpcApiError) + await expect(promise).rejects.toMatchObject({ + payload: { + code: -8, + message: 'tokenTo is empty', + method: 'testpoolswap' + } + }) + }) })