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

Commit

Permalink
Fix errors from removed cdp types
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbennett committed Nov 12, 2019
1 parent 6dc0dbd commit f961d3d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 43 deletions.
15 changes: 8 additions & 7 deletions packages/dai-plugin-mcd/test/CdpManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import findIndex from 'lodash/findIndex';
import { mcdMaker, setupCollateral } from './helpers';
import { setMethod, transferToBag } from '../src/CdpManager';
import { ServiceRoles } from '../src/constants';
import { ETH, MDAI, GNT, DGD } from '../src';
import { ETH, MDAI, GNT, DGD, BAT } from '../src';
import { dummyEventData, formattedDummyEventData } from './fixtures';
import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';

Expand All @@ -14,9 +14,10 @@ beforeAll(async () => {
maker = await mcdMaker({
cdpTypes: [
{ currency: ETH, ilk: 'ETH-A' },
{ currency: ETH, ilk: 'ETH-B' },
{ currency: DGD, ilk: 'DGD-A', decimals: 9 },
{ currency: GNT, ilk: 'GNT-A' }
{ currency: BAT, ilk: 'BAT-A' }
// { currency: ETH, ilk: 'ETH-B' },
// { currency: DGD, ilk: 'DGD-A', decimals: 9 },
// { currency: GNT, ilk: 'GNT-A' }
]
});
cdpMgr = maker.service(ServiceRoles.CDP_MANAGER);
Expand All @@ -37,7 +38,7 @@ test('getCdpIds gets empty CDP data from a proxy', async () => {

test('getCdpIds gets all CDP data from the proxy', async () => {
const cdp1 = await cdpMgr.open('ETH-A');
const cdp2 = await cdpMgr.open('ETH-B');
const cdp2 = await cdpMgr.open('BAT-A');
cdpMgr.reset();
const currentProxy = await maker.currentProxy();
const cdps = await cdpMgr.getCdpIds(currentProxy);
Expand Down Expand Up @@ -110,7 +111,7 @@ test('transaction tracking for openLockAndDraw', async () => {
expect(handlers.mined).toBeCalled();
});

test('set precision arguments according to decimals', () => {
xtest('set precision arguments according to decimals', () => {
expect(cdpMgr._precision(ETH(1))).toBe('wei');
expect(cdpMgr._precision(GNT(1))).toBe(18);
expect(cdpMgr._precision(DGD(1))).toBe(9);
Expand All @@ -124,7 +125,7 @@ test('set method correctly', () => {
expect(setMethod(false, true)).toBe('openLockGNTAndDraw');
});

test('transferToBag for GNT CDPs', async () => {
xtest('transferToBag for GNT CDPs', async () => {
const gntToken = maker.service('token').getToken(GNT);
const proxyAddress = await maker.service('proxy').currentProxy();
const bagAddress = await maker
Expand Down
8 changes: 4 additions & 4 deletions packages/dai-plugin-mcd/test/CdpType.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ beforeAll(async () => {

// these CDP types should be available to the Maker instance because
// of the configuration passed into it (see test/helpers.js)
const scenarios = [['ETH-A', ETH], ['ETH-B', ETH], ['BAT-A', BAT]];
const scenarios = [['ETH-A', ETH], ['BAT-A', BAT]];

/*
The following arrays are expected values for each tested
Expand All @@ -24,7 +24,7 @@ const scenarios = [['ETH-A', ETH], ['ETH-B', ETH], ['BAT-A', BAT]];
*/
const systemValues = {
'ETH-A': [2, 4, 100000, 1.5, 0.05, '5.0'],
'ETH-B': [2, 4, 100000, 2, 0.05, '4.0'],
// 'ETH-B': [2, 4, 100000, 2, 0.05, '4.0'],
'BAT-A': [2, 4, 5000, 2, 0.08, '10.5']
};

Expand Down Expand Up @@ -106,11 +106,11 @@ describe.each(scenarios)('%s', (ilk, GEM) => {
});

test('get system-wide debt', () => {
expect(service.totalDebtAllCdpTypes.toNumber()).toBeCloseTo(12);
expect(service.totalDebtAllCdpTypes.toNumber()).toBeCloseTo(8);
});

test('get system-wide collateral value', () => {
expect(service.totalCollateralValueAllCdpTypes.toNumber()).toBeCloseTo(60);
expect(service.totalCollateralValueAllCdpTypes.toNumber()).toBeCloseTo(40);
});

test('get system-wide collateralization ratio', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/dai-plugin-mcd/test/CdpTypeService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('getCdpType with no matches throws an error', () => {
}).toThrowError(/matches no cdp type/);
});

test('getCdpType with too many matches throws an error', () => {
xtest('getCdpType with too many matches throws an error', () => {
expect(() => {
service.getCdpType(ETH);
}).toThrowError(/matches more than one cdp type/);
Expand Down
63 changes: 32 additions & 31 deletions packages/dai-plugin-mcd/test/ManagedCdp.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';
import { mcdMaker, setupCollateral } from './helpers';
import { ETH, REP, MDAI, USD, GNT, OMG, DGD } from '../src';
import { ETH, REP, MDAI, USD, GNT, OMG, DGD, BAT } from '../src';
import { ServiceRoles } from '../src/constants';
import { dummyEventData, formattedDummyEventData } from './fixtures';
import { createCurrencyRatio } from '@makerdao/currency';
Expand All @@ -13,10 +13,11 @@ beforeAll(async () => {
maker = await mcdMaker({
cdpTypes: [
{ currency: ETH, ilk: 'ETH-A' },
{ currency: REP, ilk: 'REP-A' },
{ currency: OMG, ilk: 'OMG-A' },
{ currency: DGD, ilk: 'DGD-A', decimals: 9 },
{ currency: GNT, ilk: 'GNT-A' }
{ currency: BAT, ilk: 'BAT-A' }
// { currency: REP, ilk: 'REP-A' },
// { currency: OMG, ilk: 'OMG-A' },
// { currency: DGD, ilk: 'DGD-A', decimals: 9 },
// { currency: GNT, ilk: 'GNT-A' }
]
});
dai = maker.getToken(MDAI);
Expand All @@ -32,29 +33,29 @@ afterAll(async () => {
});

test('prevent locking the wrong collateral type', async () => {
const cdp = await maker.service(CDP_MANAGER).open('REP-A');
const cdp = await maker.service(CDP_MANAGER).open('BAT-A');
expect.assertions(1);
try {
await cdp.lockCollateral(ETH(1));
} catch (err) {
expect(err.message).toMatch(/Can't cast 1.00 ETH as REP/);
expect(err.message).toMatch(/Can't cast 1.00 ETH as BAT/);
}
});

test('prevent freeing the wrong collateral type', async () => {
const cdp = await maker.service(CDP_MANAGER).open('REP-A');
const cdp = await maker.service(CDP_MANAGER).open('BAT-A');
expect.assertions(1);
try {
await cdp.freeCollateral(ETH(1));
} catch (err) {
expect(err.message).toMatch(/Can't cast 1.00 ETH as REP/);
expect(err.message).toMatch(/Can't cast 1.00 ETH as BAT/);
}
});

test('liquidationPrice and collateralizationRatio are infinite with 0 collateral and 0 debt', async () => {
const cdp = await maker.service(CDP_MANAGER).open('REP-A');
const cdp = await maker.service(CDP_MANAGER).open('BAT-A');
await cdp.prefetch();
const ratio = createCurrencyRatio(USD, REP);
const ratio = createCurrencyRatio(USD, BAT);
const ratio2 = createCurrencyRatio(USD, MDAI);
expect(cdp.liquidationPrice).toEqual(ratio(Infinity));
expect(cdp.collateralizationRatio).toEqual(ratio2(Infinity));
Expand Down Expand Up @@ -127,27 +128,27 @@ describe.each([
'ETH-A',
ETH,
async () => setupCollateral(maker, 'ETH-A', { price: 150, debtCeiling: 50 })
],
[
'REP-A',
REP,
async () => setupCollateral(maker, 'REP-A', { price: 100, debtCeiling: 50 })
],
[
'GNT-A',
GNT,
async () => setupCollateral(maker, 'GNT-A', { price: 100, debtCeiling: 50 })
],
[
'OMG-A',
OMG,
async () => setupCollateral(maker, 'OMG-A', { price: 100, debtCeiling: 50 })
],
[
'DGD-A',
DGD,
async () => setupCollateral(maker, 'DGD-A', { price: 100, debtCeiling: 50 })
]
// [
// 'REP-A',
// REP,
// async () => setupCollateral(maker, 'REP-A', { price: 100, debtCeiling: 50 })
// ],
// [
// 'GNT-A',
// GNT,
// async () => setupCollateral(maker, 'GNT-A', { price: 100, debtCeiling: 50 })
// ],
// [
// 'OMG-A',
// OMG,
// async () => setupCollateral(maker, 'OMG-A', { price: 100, debtCeiling: 50 })
// ],
// [
// 'DGD-A',
// DGD,
// async () => setupCollateral(maker, 'DGD-A', { price: 100, debtCeiling: 50 })
// ]
])('%s', (ilk, GEM, setup) => {
let startingGemBalance, startingDaiBalance;

Expand Down

0 comments on commit f961d3d

Please sign in to comment.