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

Commit

Permalink
fix migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b-pmcg committed Nov 15, 2021
1 parent 97fcea6 commit 5b6baef
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/dai-plugin-mcd/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Web3 from 'web3';
import { Currency } from '@makerdao/currency';
import { defaultTokens } from './tokens';
import { utils as ethersUtils } from 'ethers';
export { ethersUtils };

const web3Utils = new Web3().utils;

Expand Down
6 changes: 4 additions & 2 deletions packages/dai-plugin-migrations/src/migrations/ChiefMigrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ export default class ChiefMigrate {
const voteProxyAddress = await this._getVoteProxyAddress(address);

const mkrLockedDirectly = (MKR as any).wei(
await this._oldChief.deposits(address)
(await this._oldChief.deposits(address))._hex
);
const mkrLockedViaProxy = (MKR as any).wei(
voteProxyAddress ? await this._oldChief.deposits(voteProxyAddress) : 0
voteProxyAddress
? (await this._oldChief.deposits(voteProxyAddress))._hex
: 0
);

return { mkrLockedDirectly, mkrLockedViaProxy };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export default class GlobalSettlementCollateralClaims {
const tag = await end.tag(ilks[i]);
const ilk = await vat.ilks(ilks[i]);

const owed = new BigNumber(vatUrn.art)
.times(ilk.rate)
const owed = new BigNumber(vatUrn.art._hex)
.times(ilk.rate._hex)
.div(RAY)
.times(tag)
.div(RAY);
const redeemable =
tag.gt(0) && new BigNumber(vatUrn.ink).minus(owed).gt(0);
tag.gt(0) && new BigNumber(vatUrn.ink._hex).minus(owed).gt(0);
const tagDivRay = new BigNumber(tag).div(RAY);
return { id, owed, redeemable, ilk, urn, tag: tagDivRay };
})
Expand Down
3 changes: 2 additions & 1 deletion packages/dai-plugin-migrations/src/migrations/RedeemSai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default class RedeemSai {
}

off() {
return this._tap.off();
// _tap.off() has a name clash with the ethers Contract listener "BaseContract.off(eventName)"
return this._tap['off()']();
}

async getRate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default class SingleToMultiCdp {
this._getToken(MKR).address(),
MKR(mkrAmount).toFixed('wei')
)
.then(a => SAI.wei(a));
.then(a => SAI.wei(a._hex));
}

_getToken(symbol) {
Expand Down
3 changes: 2 additions & 1 deletion packages/dai-plugin-migrations/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import assert from 'assert';
import padStart from 'lodash/padStart';
import times from 'lodash/times';
import { utils as ethersUtils } from 'ethers';

export function stringToBytes(str) {
assert(!!str, 'argument is falsy');
assert(typeof str === 'string', 'argument is not a string');
return '0x' + Buffer.from(str).toString('hex');
return ethersUtils.formatBytes32String(str);
}

export function getIdBytes(id, prefix = true) {
Expand Down
16 changes: 12 additions & 4 deletions packages/dai-plugin-migrations/test/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Maker from '@makerdao/dai';
// import Maker from '@makerdao/dai';
import Maker from '../../../dai/src';
import MigrationPlugin from '../../src';
import { Migrations } from '../../src/constants';
import { createCurrencyRatio } from '@makerdao/currency';
Expand All @@ -7,13 +8,20 @@ import McdPlugin, {
ETH,
GNT,
USD
} from '@makerdao/dai-plugin-mcd';
import ScdPlugin from '@makerdao/dai-plugin-scd';
} from '../../../dai-plugin-mcd/src';
// import McdPlugin, {
// ServiceRoles,
// ETH,
// GNT,
// USD
// } from '@makerdao/dai-plugin-mcd';
import ScdPlugin from '../../../dai-plugin-scd/src';
// import ScdPlugin from '@makerdao/dai-plugin-scd';
import ethAbi from 'web3-eth-abi';
import { utils } from 'ethers';

export function stringToBytes(str) {
return '0x' + Buffer.from(str).toString('hex');
return utils.formatBytes32String(str);
}

export function bytesToString(hex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { migrationMaker, setupCollateral } from '../helpers';
import { mockContracts, globalSettlement } from '../helpers/mocks';
import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';
import { ServiceRoles, Migrations } from '../../src/constants';
import { DAI, ETH } from '@makerdao/dai-plugin-mcd';
// import { DAI, ETH } from '@makerdao/dai-plugin-mcd';
import { DAI, ETH } from '../../../dai-plugin-mcd/src';

let maker, migration, smartContract, cdpManager, snapshot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { migrationMaker, setupCollateral } from '../helpers';
import { mockContracts, globalSettlement } from '../helpers/mocks';
import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';
import { ServiceRoles, Migrations } from '../../src/constants';
import { DAI, ETH } from '@makerdao/dai-plugin-mcd';
// import { DAI, ETH } from '@makerdao/dai-plugin-mcd';
import { DAI, ETH } from '../../../dai-plugin-mcd/src';

jest.setTimeout(30000);

let maker, migration, smartContract, cdpManager, snapshot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { migrationMaker, setupCollateral } from '../helpers';
import { mockContracts, globalSettlement } from '../helpers/mocks';
import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers';
import { ServiceRoles, Migrations } from '../../src/constants';
import { ETH, DAI } from '@makerdao/dai-plugin-mcd';
// import { DAI, ETH } from '@makerdao/dai-plugin-mcd';
import { DAI, ETH } from '../../../dai-plugin-mcd/src';

let maker, migration, cdpManager, smartContract, snapshot;

Expand Down

0 comments on commit 5b6baef

Please sign in to comment.