-
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.
* Add new getloanscheme rpc * Improve comment * Improve code * Minor * Add correct error message
- Loading branch information
1 parent
a610cfb
commit 4fed144
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/jellyfish-api-core/__tests__/category/loan/getLoanScheme.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,42 @@ | ||
import { LoanMasterNodeRegTestContainer } from './loan_container' | ||
import BigNumber from 'bignumber.js' | ||
import { Testing } from '@defichain/jellyfish-testing' | ||
|
||
describe('Loan getLoanScheme', () => { | ||
const container = new LoanMasterNodeRegTestContainer() | ||
const testing = Testing.create(container) | ||
|
||
beforeAll(async () => { | ||
await testing.container.start() | ||
await testing.container.waitForWalletCoinbaseMaturity() | ||
}) | ||
|
||
afterAll(async () => { | ||
await testing.container.stop() | ||
}) | ||
|
||
it('should getLoanScheme', async () => { | ||
await testing.container.call('createloanscheme', [100, new BigNumber(1.5), 'scheme1']) | ||
await testing.container.generate(1) | ||
|
||
const data = await testing.rpc.loan.getLoanScheme('scheme1') | ||
expect(data).toStrictEqual( | ||
{ id: 'scheme1', interestrate: new BigNumber(1.5), mincolratio: new BigNumber(100) } | ||
) | ||
}) | ||
|
||
it('should not getLoanScheme if id does not exist', async () => { | ||
const promise = testing.rpc.loan.getLoanScheme('scheme2') | ||
await expect(promise).rejects.toThrow('RpcApiError: \'Cannot find existing loan scheme with id scheme2\', code: -8, method: getloanscheme') | ||
}) | ||
|
||
it('should not getLoanScheme if id is an empty string', async () => { | ||
const promise = testing.rpc.loan.getLoanScheme('') | ||
await expect(promise).rejects.toThrow('RpcApiError: \'id cannot be empty or more than 8 chars long\', code: -8, method: getloanscheme') | ||
}) | ||
|
||
it('should not getLoanScheme if id is more than 8 characters', async () => { | ||
const promise = testing.rpc.loan.getLoanScheme('x'.repeat(9)) | ||
await expect(promise).rejects.toThrow('RpcApiError: \'id cannot be empty or more than 8 chars long\', code: -8, method: getloanscheme') | ||
}) | ||
}) |
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