Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Commit

Permalink
Add loan vault get and list endpoints (#424)
Browse files Browse the repository at this point in the history
* 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
jingyi2811 and fuxingloh authored Nov 3, 2021
1 parent 024b98b commit a6f0f59
Show file tree
Hide file tree
Showing 14 changed files with 964 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ updates:
labels:
- "kind/dependencies"
ignore:
- dependency-name: "@defichain/whale-*"
- dependency-name: "@defichain/*"
versioning-strategy: 'increase'

- package-ecosystem: "github-actions"
Expand Down
119 changes: 119 additions & 0 deletions packages/whale-api-client/__tests__/api/address.vault.test.ts
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()
})
})
Loading

0 comments on commit a6f0f59

Please sign in to comment.