From 4c6c259d82b8486ef1f2447daba71faf18b35bb7 Mon Sep 17 00:00:00 2001 From: Josh Levine Date: Tue, 17 Dec 2019 03:31:52 -0500 Subject: [PATCH] add test for vote proxy mkr deposit check --- .../src/migrations/ChiefMigrate.js | 9 +-- .../test/migrations/ChiefMigrate.spec.js | 80 ++++++++++++------- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/packages/dai-plugin-migrations/src/migrations/ChiefMigrate.js b/packages/dai-plugin-migrations/src/migrations/ChiefMigrate.js index 758ca2d0c..e4b209241 100644 --- a/packages/dai-plugin-migrations/src/migrations/ChiefMigrate.js +++ b/packages/dai-plugin-migrations/src/migrations/ChiefMigrate.js @@ -6,7 +6,7 @@ export default class ChiefMigrate { constructor(manager) { this._manager = manager; this._oldChief = manager.get('smartContract').getContract('OLD_CHIEF'); - this._proxyFactoryContract = manager + this._oldProxyFactoryContract = manager .get('smartContract') .getContractByName('OLD_VOTE_PROXY_FACTORY'); return this; @@ -14,7 +14,6 @@ export default class ChiefMigrate { async check() { const address = this._manager.get('accounts').currentAddress(); - const voteProxyAddress = await this._getVoteProxyAddress(address); const mkrLockedDirectly = MKR.wei(await this._oldChief.deposits(address)); @@ -25,12 +24,10 @@ export default class ChiefMigrate { return { mkrLockedDirectly, mkrLockedViaProxy }; } - async execute() {} - async _getVoteProxyAddress(walletAddress) { const [proxyAddressCold, proxyAddressHot] = await Promise.all([ - this._proxyFactoryContract.coldMap(walletAddress), - this._proxyFactoryContract.hotMap(walletAddress) + this._oldProxyFactoryContract.coldMap(walletAddress), + this._oldProxyFactoryContract.hotMap(walletAddress) ]); if (proxyAddressCold !== ZERO_ADDRESS) return proxyAddressCold; diff --git a/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js b/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js index 87c6e0710..81c56fdf1 100644 --- a/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js +++ b/packages/dai-plugin-migrations/test/migrations/ChiefMigrate.spec.js @@ -1,8 +1,12 @@ import { migrationMaker } from '../helpers'; import { ServiceRoles, Migrations } from '../../src/constants'; -import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; +import { + takeSnapshot, + restoreSnapshot, + TestAccountProvider +} from '@makerdao/test-helpers'; import { MKR } from '../../src'; -// import voteProxyAbi from '../../contracts/abis/VoteProxy.json'; +import voteProxyAbi from '../../contracts/abis/VoteProxy.json'; let maker, migration, snapshot; @@ -11,14 +15,17 @@ describe('Chief Migration', () => { maker = await migrationMaker(); const service = maker.service(ServiceRoles.MIGRATION); migration = service.getMigration(Migrations.CHIEF_MIGRATE); + }); + + beforeEach(async () => { snapshot = await takeSnapshot(maker); }); - afterAll(async () => { + afterEach(() => { restoreSnapshot(snapshot, maker); }); - test('if the account has no MKR in old chief, return 0', async () => { + test('if the account has no MKR locked in old chief, return 0', async () => { const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check(); expect(mkrLockedDirectly.toNumber()).toBe(0); expect(mkrLockedViaProxy.toNumber()).toBe(0); @@ -42,32 +49,43 @@ describe('Chief Migration', () => { expect(mkrLockedViaProxy.toNumber()).toBe(0); }); - // TODO - test.skip('if the account has some MKR locked via proxy in old chief, return the amount', async () => { - // const oldChief = maker - // .service('smartContract') - // .getContractByName('OLD_CHIEF'); - // const voteProxyFactory = maker - // .service('smartContract') - // .getContractByName('VOTE_PROXY_FACTORY'); - // cold - // voteProxyFactory.initiateLink(hot); - // hot - // voteProxyFactory.approveLink(cold); - // back to cold - // const voteProxyAddress = migration._getVoteProxyAddress(cold); - // console.log('voteProxyAbi', voteProxyAbi); - // const voteProxy = maker - // .service('smartContract') - // .getContractByAddressAndAbi(voteProxyAddress, voteProxyAbi); - // await maker - // .service('token') - // .getToken(MKR) - // .approveUnlimited(voteProxyAddress); - // const LOCK_AMOUNT = MKR('5.123456789123456789'); - // await voteProxy.lock(LOCK_AMOUNT.toFixed('wei')); - // const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check(); - // expect(mkrLockedDirectly.toNumber()).toBe(0); - // expect(mkrLockedViaProxy.isEqual(LOCK_AMOUNT)).toBeTruthy(); + test('if the account has some MKR locked via proxy in old chief, return the amount', async () => { + const oldVoteProxyFactory = maker + .service('smartContract') + .getContractByName('OLD_VOTE_PROXY_FACTORY'); + + const coldAccount = maker.currentAccount(); + const hotAccount = TestAccountProvider.nextAccount(); + await maker.addAccount({ ...hotAccount, type: 'privateKey' }); + + // initiate from cold + maker.useAccount('default'); + await oldVoteProxyFactory.initiateLink(hotAccount.address); + + // switch to hot + maker.useAccount(hotAccount.address); + await oldVoteProxyFactory.approveLink(coldAccount.address); + + // and back to cold + maker.useAccount('default'); + const voteProxyAddress = await migration._getVoteProxyAddress( + coldAccount.address + ); + + const voteProxy = maker + .service('smartContract') + .getContractByAddressAndAbi(voteProxyAddress, voteProxyAbi); + + await maker + .service('token') + .getToken(MKR) + .approveUnlimited(voteProxyAddress); + + const LOCK_AMOUNT = MKR('5.123456789123456789'); + await voteProxy.lock(LOCK_AMOUNT.toFixed('wei')); + + const { mkrLockedDirectly, mkrLockedViaProxy } = await migration.check(); + expect(mkrLockedDirectly.toNumber()).toBe(0); + expect(mkrLockedViaProxy.isEqual(LOCK_AMOUNT)).toBeTruthy(); }); });