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

Commit

Permalink
add total dai method to system service, add tests for total dai method
Browse files Browse the repository at this point in the history
  • Loading branch information
jparklev committed Aug 13, 2020
1 parent 1fd2a56 commit b97a180
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/dai-plugin-mcd/src/SystemDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export default class SystemDataService extends PublicService {
return DAI.rad(dai).minus(DAI.rad(sin));
}

async getTotalDai() {
return DAI.rad(await this.vat.debt());
}

// Helpers ----------------------------------------------

get cat() {
Expand Down
23 changes: 19 additions & 4 deletions packages/dai-plugin-mcd/test/SystemDataService.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { mcdMaker } from './helpers';
import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';

import { mcdMaker, setupCollateral } from './helpers';
import { ServiceRoles } from '../src/constants';
import { DAI } from '../src/index';
import { DAI, ETH } from '../src/index';

let service;
let maker;
let service, snapshotData, maker;

beforeAll(async () => {
maker = await mcdMaker();
service = maker.service(ServiceRoles.SYSTEM_DATA);
snapshotData = await takeSnapshot(maker);
});

afterAll(async () => {
await restoreSnapshot(snapshotData, maker);
});

test('get annual base rate', async () => {
Expand All @@ -29,3 +35,12 @@ test('get system surplus', async () => {
const surplus = await service.getSystemSurplus();
expect(surplus).toEqual(DAI(0)); //TODO change to expect non-zero number
});

test('get total dai', async () => {
expect((await service.getTotalDai()).toNumber()).toEqual(DAI(0).toNumber());
await setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 });
await maker
.service(ServiceRoles.CDP_MANAGER)
.openLockAndDraw('ETH-A', ETH(1), DAI(3));
expect((await service.getTotalDai()).toNumber()).toBe(DAI(3).toNumber());
});

0 comments on commit b97a180

Please sign in to comment.