-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@defichain/testing
new add/remove PoolLiquidity for testing (#235)
* @defichain/testing added add/remove PoolLiquidity for testing * changed to use options for poolpair
- Loading branch information
Showing
5 changed files
with
130 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,47 +1,66 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { | ||
createToken, | ||
createPoolPair | ||
} from '../src' | ||
import { createToken, createPoolPair, addPoolLiquidity, mintTokens, utxosToAccount, removePoolLiquidity } from '../src' | ||
|
||
describe('utils', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const container = new MasterNodeRegTestContainer() | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForReady() | ||
await container.waitForWalletCoinbaseMaturity() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
describe('createPoolPair', () => { | ||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForReady() | ||
await container.waitForWalletCoinbaseMaturity() | ||
await container.waitForWalletBalanceGTE(300) | ||
await createToken(container, 'DOG') | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
it('should createPoolPair', async () => { | ||
const before = await container.call('listpoolpairs') | ||
|
||
describe('createPoolPair', () => { | ||
beforeAll(async () => { | ||
await createToken(container, 'DOG') | ||
}) | ||
const txid = await createPoolPair(container, 'DFI', 'DOG') | ||
expect(typeof txid).toBe('string') | ||
|
||
it('should createPoolPair', async () => { | ||
let assertions = 0 | ||
const after: Record<string, any> = await container.call('listpoolpairs') | ||
expect(Object.keys(after).length).toBe(Object.keys(before).length + 1) | ||
|
||
const poolpairsBefore = await container.call('listpoolpairs') | ||
const poolpairsLengthBefore = Object.keys(poolpairsBefore).length | ||
for (const poolpair of Object.values(after)) { | ||
expect(poolpair.name).toBe('Default Defi token-DOG') | ||
} | ||
|
||
const data = await createPoolPair(container, 'DFI', 'DOG') | ||
expect(typeof data).toBe('string') | ||
expect.assertions(3) | ||
}) | ||
}) | ||
|
||
describe('add/remove pool pair liquidity', () => { | ||
beforeAll(async () => { | ||
await createToken(container, 'LPT') | ||
await mintTokens(container, 'LPT', { mintAmount: 100 }) | ||
await utxosToAccount(container, 100) | ||
await createPoolPair(container, 'DFI', 'LPT') | ||
}) | ||
|
||
const poolpairsAfter = await container.call('listpoolpairs') | ||
expect(Object.keys(poolpairsAfter).length).toBe(poolpairsLengthBefore + 1) | ||
it('should add and remove liquidity', async () => { | ||
const address = await container.getNewAddress() | ||
const amount = await addPoolLiquidity(container, { | ||
tokenA: 'DFI', | ||
amountA: 50, | ||
tokenB: 'LPT', | ||
amountB: 50, | ||
shareAddress: address | ||
}) | ||
expect(amount.toFixed(8)).toBe('49.99999000') | ||
|
||
for (const k in poolpairsAfter) { | ||
const poolpair = poolpairsAfter[k] | ||
if (poolpair.name === 'Default Defi token-DOG') { | ||
assertions += 1 | ||
} | ||
} | ||
expect(assertions).toBe(1) | ||
await removePoolLiquidity(container, { | ||
address: address, | ||
amountLP: amount, | ||
tokenLP: 'DFI-LPT' | ||
}) | ||
|
||
const shares: Record<string, any> = await container.call('listpoolshares') | ||
expect(Object.keys(shares).length).toBe(0) | ||
}) | ||
}) |
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
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