From 32007311cd64bc9bae88b87dd75ae923bf0c15f2 Mon Sep 17 00:00:00 2001 From: Phil Bain Date: Mon, 15 Nov 2021 15:29:11 -0700 Subject: [PATCH] fix liquidations tests --- .../contracts/abis/Clipper.json | 3 +-- .../src/LiquidationService.ts | 15 +++++++++------ .../test/LiquidationService.test.js | 12 +++++++----- packages/dai-plugin-liquidations/test/utils.js | 3 ++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/dai-plugin-liquidations/contracts/abis/Clipper.json b/packages/dai-plugin-liquidations/contracts/abis/Clipper.json index a9492e328..cc58e1968 100644 --- a/packages/dai-plugin-liquidations/contracts/abis/Clipper.json +++ b/packages/dai-plugin-liquidations/contracts/abis/Clipper.json @@ -456,8 +456,7 @@ "name": "upchost", "outputs": [], "stateMutability": "nonpayable", - "type": "function", - "constant": true + "type": "function" }, { "inputs": [], diff --git a/packages/dai-plugin-liquidations/src/LiquidationService.ts b/packages/dai-plugin-liquidations/src/LiquidationService.ts index 93445d28e..a982e5108 100644 --- a/packages/dai-plugin-liquidations/src/LiquidationService.ts +++ b/packages/dai-plugin-liquidations/src/LiquidationService.ts @@ -2,8 +2,13 @@ import { PublicService } from '@makerdao/services-core'; import { bytes32ToNumber, numberToBytes32 -} from '@makerdao/dai/src/utils/conversion'; +} from '../../dai/src/utils/conversion'; +// import { +// bytes32ToNumber, +// numberToBytes32 +// } from '@makerdao/dai/src/utils/conversion'; import assert from 'assert'; +import { utils } from 'ethers'; import tracksTransactions from './utils/tracksTransactions'; const MAINNET_SERVER_URL = 'https://api.makerdao.com/graphql'; //const LOCAL_URL = 'http://localhost:3001/graphql'; @@ -15,11 +20,9 @@ export const RAY = new BigNumber('1e27'); export const nullBytes = '0x'; -export const stringToBytes = str => { - assert(!!str, 'argument is falsy'); - assert(typeof str === 'string', 'argument is not a string'); - return '0x' + Buffer.from(str).toString('hex'); -}; +export function stringToBytes(str) { + return utils.formatBytes32String(str); +} //hard-coded for now, but can get from pips, which you can get from ilk registry const medianizers = { diff --git a/packages/dai-plugin-liquidations/test/LiquidationService.test.js b/packages/dai-plugin-liquidations/test/LiquidationService.test.js index 937356121..fed3e5090 100644 --- a/packages/dai-plugin-liquidations/test/LiquidationService.test.js +++ b/packages/dai-plugin-liquidations/test/LiquidationService.test.js @@ -1,6 +1,8 @@ import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; -import Maker from '@makerdao/dai'; -import { McdPlugin, YFI } from '@makerdao/dai-plugin-mcd'; +// import Maker from '@makerdao/dai/'; +import Maker from '../../dai/src'; +// import { McdPlugin, YFI } from '@makerdao/dai-plugin-mcd'; +import { McdPlugin, YFI } from '../../dai-plugin-mcd/src'; import BigNumber from 'bignumber.js'; import liquidationPlugin from '../src'; import LiquidationService, { @@ -145,11 +147,11 @@ describe('LiquidationService', () => { test('can get status from on chain', async () => { const { needsRedo, price, lot, tab } = await service.getStatus(ilk, 1); - const collateralAmount = new BigNumber(lot).div(WAD); - const daiNeeded = new BigNumber(tab).div(RAD); + const collateralAmount = new BigNumber(lot._hex).div(WAD); + const daiNeeded = new BigNumber(tab._hex).div(RAD); expect(collateralAmount.gt(0)).toBe(true); - expect(new BigNumber(price).div(RAY).toString()).toEqual('19500'); + expect(new BigNumber(price._hex).div(RAY).toString()).toEqual('19500'); expect(daiNeeded.toNumber()).toBeCloseTo(1000); expect(needsRedo).toEqual(false); }); diff --git a/packages/dai-plugin-liquidations/test/utils.js b/packages/dai-plugin-liquidations/test/utils.js index f5d2e7716..d6ea0d94d 100644 --- a/packages/dai-plugin-liquidations/test/utils.js +++ b/packages/dai-plugin-liquidations/test/utils.js @@ -1,4 +1,5 @@ -import { DAI } from '@makerdao/dai-plugin-mcd'; +// import { DAI } from '@makerdao/dai-plugin-mcd'; +import { DAI } from '../../dai-plugin-mcd/src'; import { mineBlocks } from '../../test-helpers/src'; import BigNumber from 'bignumber.js'; import { stringToBytes } from '../src/LiquidationService';