This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from makerdao/vote-proxy-factory-tests
WIP for testing VPFS methods
- Loading branch information
Showing
12 changed files
with
854 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es6": true, | ||
"jest": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 8, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true | ||
} | ||
}, | ||
"rules": { | ||
"no-console": "off", | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single", | ||
{ "avoidEscape": true } | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { | ||
takeSnapshot, | ||
restoreSnapshot, | ||
setupTestMakerInstance, | ||
setUpAllowance | ||
} from './helpers'; | ||
import { ZERO_ADDRESS } from '../src/utils/constants'; | ||
import ChiefService from '../src/ChiefService'; | ||
import * as web3utils from 'web3-utils'; | ||
|
||
let snapshotId, maker, chiefService; | ||
|
||
const picks = [ | ||
'0x26EC003c72ebA27749083d588cdF7EBA665c0A1D', | ||
'0x54F4E468FB0297F55D8DfE57336D186009A1455a' | ||
]; | ||
const mkrToLock = 3; | ||
|
||
beforeAll(async () => { | ||
snapshotId = await takeSnapshot(); | ||
|
||
maker = await setupTestMakerInstance(); | ||
|
||
chiefService = maker.service('chief'); | ||
}); | ||
|
||
afterAll(async () => { | ||
await restoreSnapshot(snapshotId); | ||
}); | ||
|
||
test('can create Chief Service', async () => { | ||
const chief = maker.service('chief'); | ||
expect(chief).toBeInstanceOf(ChiefService); | ||
}); | ||
|
||
test('can cast vote with an array of addresses', async () => { | ||
// owner casts vote with picks array | ||
await chiefService.vote(picks); | ||
|
||
const slate = await chiefService.getVotedSlate( | ||
maker.currentAccount().address | ||
); | ||
const addrs = await chiefService.getSlateAddresses(slate); | ||
|
||
expect(addrs).toEqual(picks); | ||
}); | ||
|
||
test('can cast vote with a slate hash', async () => { | ||
// etch the picks | ||
await chiefService.etch(picks); | ||
|
||
// hash the picks to get slate hash | ||
const hash = web3utils.soliditySha3({ type: 'address[]', value: picks }); | ||
|
||
// cast a vote for the slate hash | ||
await chiefService.vote(hash); | ||
|
||
const slate = await chiefService.getVotedSlate( | ||
maker.currentAccount().address | ||
); | ||
expect(slate).toBe(hash); | ||
expect(slate).not.toBe(ZERO_ADDRESS); | ||
|
||
const addresses = await chiefService.getSlateAddresses(slate); | ||
|
||
expect(addresses).toEqual(picks); | ||
}); | ||
|
||
test('number of deposits for a proxy contract address should equal locked MKR amount', async () => { | ||
await setUpAllowance(maker, chiefService._chiefContract().address); | ||
await chiefService.lock(mkrToLock); | ||
|
||
const numDeposits = await chiefService.getNumDeposits( | ||
maker.currentAccount().address | ||
); | ||
|
||
expect(numDeposits.toNumber()).toBe(mkrToLock); | ||
}); | ||
|
||
test('approval count for a voted-on address should equal locked MKR amount', async () => { | ||
const approvalCount = await chiefService.getApprovalCount(picks[0]); | ||
expect(approvalCount.toNumber()).toBe(mkrToLock); | ||
}); | ||
|
||
test('get hat should return lifted address', async () => { | ||
const addressToLift = picks[0]; | ||
|
||
const oldHat = await chiefService.getHat(); | ||
expect(oldHat).toBe(ZERO_ADDRESS); | ||
|
||
await chiefService.lift(addressToLift); | ||
|
||
const newHat = await chiefService.getHat(); | ||
expect(newHat).toBe(addressToLift); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
takeSnapshot, | ||
restoreSnapshot, | ||
setupTestMakerInstance, | ||
linkAccounts | ||
} from './helpers'; | ||
import VoteProxy from '../src/VoteProxy'; | ||
|
||
let snapshotId, maker, addresses, voteProxyService; | ||
|
||
beforeAll(async () => { | ||
snapshotId = await takeSnapshot(); | ||
|
||
maker = await setupTestMakerInstance(); | ||
|
||
voteProxyService = maker.service('voteProxy'); | ||
|
||
addresses = maker | ||
.listAccounts() | ||
.reduce((acc, cur) => ({ ...acc, [cur.name]: cur.address }), {}); | ||
|
||
await linkAccounts(maker, addresses.ali, addresses.ava); | ||
}); | ||
|
||
afterAll(async () => { | ||
await restoreSnapshot(snapshotId); | ||
}); | ||
|
||
test('Vote proxy instance returns correct information about itself', async () => { | ||
const { voteProxy } = await voteProxyService.getVoteProxy(addresses.ali); | ||
expect(voteProxy).toBeInstanceOf(VoteProxy); | ||
|
||
const vpAddress = voteProxy.getProxyAddress(); | ||
expect(vpAddress).toBeTruthy(); | ||
|
||
// Hot address should be the same as the approver | ||
const hotAddress = voteProxy.getHotAddress(); | ||
expect(hotAddress.toLowerCase()).toBe(addresses.ava.toLowerCase()); | ||
|
||
// Cold address should be the same as the initiator | ||
const coldAddress = voteProxy.getColdAddress(); | ||
expect(coldAddress.toLowerCase()).toBe(addresses.ali.toLowerCase()); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
takeSnapshot, | ||
restoreSnapshot, | ||
setupTestMakerInstance, | ||
linkAccounts | ||
} from './helpers'; | ||
import VoteProxyFactoryService from '../src/VoteProxyFactoryService'; | ||
|
||
let snapshotId, maker, addresses, voteProxyFactory, voteProxyService; | ||
|
||
beforeAll(async () => { | ||
snapshotId = await takeSnapshot(); | ||
|
||
maker = await setupTestMakerInstance(); | ||
|
||
addresses = maker | ||
.listAccounts() | ||
.reduce((acc, cur) => ({ ...acc, [cur.name]: cur.address }), {}); | ||
|
||
voteProxyFactory = maker.service('voteProxyFactory'); | ||
voteProxyService = maker.service('voteProxy'); | ||
}); | ||
|
||
afterAll(async () => { | ||
await restoreSnapshot(snapshotId); | ||
}); | ||
|
||
test('can create VPFS Service', async () => { | ||
const vpfs = maker.service('voteProxyFactory'); | ||
expect(vpfs).toBeInstanceOf(VoteProxyFactoryService); | ||
}); | ||
|
||
test('can create a vote proxy linking two addressses', async () => { | ||
await linkAccounts(maker, addresses.ali, addresses.ava); | ||
|
||
const { hasProxy } = await voteProxyService.getVoteProxy(addresses.ali); | ||
expect(hasProxy).toBeTruthy(); | ||
}); | ||
|
||
test('can break a link between linked accounts', async () => { | ||
maker.useAccount('ali'); | ||
await voteProxyFactory.breakLink(); | ||
|
||
const { hasProxy } = await voteProxyService.getVoteProxy(addresses.ali); | ||
expect(hasProxy).toBe(false); | ||
}); |
Oops, something went wrong.