diff --git a/packages/dai-plugin-mcd/src/SystemDataService.js b/packages/dai-plugin-mcd/src/SystemDataService.js index 3842ec903..f02f0eb17 100644 --- a/packages/dai-plugin-mcd/src/SystemDataService.js +++ b/packages/dai-plugin-mcd/src/SystemDataService.js @@ -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() { diff --git a/packages/dai-plugin-mcd/test/SystemDataService.spec.js b/packages/dai-plugin-mcd/test/SystemDataService.spec.js index 0928f7b00..011885e86 100644 --- a/packages/dai-plugin-mcd/test/SystemDataService.spec.js +++ b/packages/dai-plugin-mcd/test/SystemDataService.spec.js @@ -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 () => { @@ -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()); +});