This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add loan vault get and list endpoints (#424)
* Add vault endpoints * Add vault endpoints * Add vault endpoints * Stable code * Add back including_start * Temporarily remove including_start * Add ownerAddress, loanSchemeId and isUnderLiquidation parameter to list * Fix error raised after updating to the latest docker image * Minor * Stable version * Minor * revert conflict changes * added /loans/vaults added /loans/vaults/:id added /address/:address/vaults not tested * fixed missing imports * Improve code * Format code * fixed broken test * simplified loan.vault.service fixed address client and controller * remapped VaultState to LoanVaultState to move enum control to JS * ignore all defichain deps for dependabot due to mono repo design not updating * updated LoanVault with 2 types of struct * fixed package-lock.json * added liquidation details * added more test for vault with new structure * added more explicit testing to Vault requests * added additional wait for create.masternode.spec.ts * fixed listVault test fixed masternode.controller.e2e.ts test Co-authored-by: Fuxing Loh <[email protected]>
- Loading branch information
1 parent
024b98b
commit a6f0f59
Showing
14 changed files
with
964 additions
and
6 deletions.
There are no files selected for viewing
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
119 changes: 119 additions & 0 deletions
119
packages/whale-api-client/__tests__/api/address.vault.test.ts
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { StubWhaleApiClient } from '../stub.client' | ||
import { StubService } from '../stub.service' | ||
import { WhaleApiClient } from '../../src' | ||
import BigNumber from 'bignumber.js' | ||
import { Testing } from '@defichain/jellyfish-testing' | ||
import { LoanMasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { LoanVaultState } from '../../src/api/loan' | ||
|
||
let container: LoanMasterNodeRegTestContainer | ||
let service: StubService | ||
let client: WhaleApiClient | ||
let testing: Testing | ||
|
||
beforeAll(async () => { | ||
container = new LoanMasterNodeRegTestContainer() | ||
service = new StubService(container) | ||
client = new StubWhaleApiClient(service) | ||
|
||
await container.start() | ||
await container.waitForWalletCoinbaseMaturity() | ||
await service.start() | ||
|
||
testing = Testing.create(container) | ||
|
||
await testing.rpc.loan.createLoanScheme({ | ||
minColRatio: 100, | ||
interestRate: new BigNumber(2.5), | ||
id: 'default' | ||
}) | ||
await testing.generate(1) | ||
|
||
await testing.rpc.loan.createVault({ | ||
ownerAddress: await testing.address('vault'), | ||
loanSchemeId: 'default' | ||
}) | ||
await testing.generate(1) | ||
|
||
await testing.rpc.loan.createVault({ | ||
ownerAddress: await testing.address('vault'), | ||
loanSchemeId: 'default' | ||
}) | ||
await testing.generate(1) | ||
|
||
await testing.rpc.loan.createVault({ | ||
ownerAddress: await testing.address('vault'), | ||
loanSchemeId: 'default' | ||
}) | ||
await testing.generate(1) | ||
|
||
await testing.rpc.loan.createVault({ | ||
ownerAddress: await testing.address('vault'), | ||
loanSchemeId: 'default' | ||
}) | ||
await testing.generate(1) | ||
}) | ||
|
||
afterAll(async () => { | ||
try { | ||
await service.stop() | ||
} finally { | ||
await container.stop() | ||
} | ||
}) | ||
|
||
describe('list', () => { | ||
it('should listVault with size only', async () => { | ||
const address = await testing.address('vault') | ||
|
||
const result = await client.address.listVault(address) | ||
expect(result.length).toStrictEqual(4) | ||
|
||
result.forEach(e => | ||
expect(e).toStrictEqual({ | ||
vaultId: expect.any(String), | ||
loanSchemeId: 'default', | ||
ownerAddress: address, | ||
state: LoanVaultState.ACTIVE, | ||
informativeRatio: '-1', | ||
collateralRatio: '-1', | ||
collateralValue: '0', | ||
loanValue: '0', | ||
interestValue: '0', | ||
collateralAmounts: [], | ||
loanAmounts: [], | ||
interestAmounts: [] | ||
}) | ||
) | ||
}) | ||
|
||
it('should listVault with size and pagination', async () => { | ||
const address = await testing.address('vault') | ||
|
||
const vaultIds = (await client.address.listVault(address, 20)) | ||
.map(value => value.vaultId) | ||
|
||
const first = await client.address.listVault(address, 2) | ||
expect(first.length).toStrictEqual(2) | ||
expect(first.hasNext).toStrictEqual(true) | ||
expect(first.nextToken).toStrictEqual(vaultIds[1]) | ||
|
||
expect(first[0].vaultId).toStrictEqual(vaultIds[0]) | ||
expect(first[1].vaultId).toStrictEqual(vaultIds[1]) | ||
|
||
const next = await client.paginate(first) | ||
|
||
expect(next.length).toStrictEqual(2) | ||
expect(next.hasNext).toStrictEqual(true) | ||
expect(next.nextToken).toStrictEqual(vaultIds[3]) | ||
|
||
expect(next[0].vaultId).toStrictEqual(vaultIds[2]) | ||
expect(next[1].vaultId).toStrictEqual(vaultIds[3]) | ||
|
||
const last = await client.paginate(next) | ||
|
||
expect(last.length).toStrictEqual(0) | ||
expect(last.hasNext).toStrictEqual(false) | ||
expect(last.nextToken).toBeUndefined() | ||
}) | ||
}) |
Oops, something went wrong.