Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from makerdao/vote-proxy-factory-tests
Browse files Browse the repository at this point in the history
WIP for testing VPFS methods
  • Loading branch information
b-pmcg authored Nov 21, 2018
2 parents 0702674 + 7ee08f3 commit 1ef2d0e
Show file tree
Hide file tree
Showing 12 changed files with 854 additions and 103 deletions.
34 changes: 34 additions & 0 deletions .eslintrc
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"
]
}
}
4 changes: 2 additions & 2 deletions contracts/addresses/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"mkr": "0xf104a50668c3b1026e8f9b0d9d404faf8e42e642",
"iou": "0xb8485421abc325d172652123dbd71d58b8117070",
"chief": "0x189a7fbb0038d4b55bd03840be0b0a38de034089",
"polling": "0xda81a8d72f1d9892aba62cd309f939f18a3635ef",
"proxy_factory": "0xbcfbac3f75778a6dc9e80a1c1138b853d30f6284"
"polling": "0x7ba25f791fa76c3ef40ac98ed42634a8bc24c238",
"proxy_factory": "0x3518632ebb387d77ff19de9bd1eee095f919d5a6"
}
10 changes: 10 additions & 0 deletions gov-testchain/deploy-gov
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ test -z $GOV && GOV=$(seth receipt $GOVtx contractAddress)
test -z $IOU && IOU=$(seth receipt $IOUtx contractAddress)
MAX_YAYS=5
CHIEF=$(dapp create DSChief $GOV $IOU $MAX_YAYS)
# Chief mints and burns IOUs, so it must be the owner of the token contract
seth send $IOU 'setOwner(address)' $CHIEF
# Seed our coinbase account with some Gov
seth send $GOV 'mint(uint256)' $(seth --to-uint256 $(seth --to-wei 100 eth))
cd -
Expand Down Expand Up @@ -63,6 +65,14 @@ cat > $CWD/../contracts/addresses/testnet.json <<- EOM
}
EOM

# Amend the sdk's mkr token testnet address so that we can interact with the mkr token we've deployed in this script
# NOTE: this likely can be better handled if the greater 'testchain' repo is updated to accommodate the gov contracts
cat > $CWD/../node_modules/@makerdao/dai/contracts/addresses/testnet.json <<- EOM
{
"GOV": "$GOV"
}
EOM

END_TIME=`date +%s`
ELAPSED=`echo $END_TIME - $START_TIME | bc`
echo "Created testnet in" $ELAPSED "seconds."
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
"dependencies": {
"@makerdao/dai": "^0.9.6",
"babel-runtime": "^6.26.0",
"ramda": "^0.25.0"
"ramda": "^0.25.0",
"web3-utils": "^1.0.0-beta.36"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^10.0.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1",
"copyfiles": "^2.1.0",
"eslint": "^5.9.0",
"ganache-cli": "^6.1.8",
"husky": "^1.1.4",
"jest": "^23.5.0",
Expand All @@ -26,7 +29,7 @@
"sane": "^4.0.1"
},
"scripts": {
"test": "jest",
"test": "jest --runInBand",
"testnet": "./gov-testchain/deploy-gov",
"ci": "./gov-testchain/deploy-gov --ci jest --coverage",
"build": "./scripts/build.sh",
Expand Down
95 changes: 95 additions & 0 deletions test/ChiefService.test.js
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);
});
34 changes: 13 additions & 21 deletions test/Polling.test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
import {
takeSnapshot,
restoreSnapshot,
ganacheAccounts,
ganacheCoinbase
setupTestMakerInstance
} from './helpers';
import Maker from '@makerdao/dai';
import GovService from '../src/index';
import PollingService from '../src/PollingService';

let snapshotId, maker, addresses;

beforeAll(async () => {
maker = Maker.create('test', {
accounts: {
owner: { type: 'privateKey', key: ganacheCoinbase.privateKey },
ali: { type: 'privateKey', key: ganacheAccounts[0].privateKey },
sam: { type: 'privateKey', key: ganacheAccounts[1].privateKey },
ava: { type: 'privateKey', key: ganacheAccounts[2].privateKey }
},
provider: { type: 'TEST' },
plugins: [GovService]
});
await maker.authenticate();
snapshotId = await takeSnapshot();

maker = await setupTestMakerInstance();

addresses = maker
.listAccounts()
.reduce((acc, cur) => ({ ...acc, [cur.name]: cur.address }), {});
});

// beforeEach(async () => {
// snapshotId = await takeSnapshot();
// });
afterAll(async () => {
await restoreSnapshot(snapshotId);
});

// afterEach(async () => {
// await restoreSnapshot(snapshotId);
// });
test('can create Polling Service', async () => {
const polling = maker.service('polling');
expect(polling).toBeInstanceOf(PollingService);
});

test('can create a poll', async () => {
const polling = maker.service('polling');
Expand Down
43 changes: 43 additions & 0 deletions test/VoteProxy.test.js
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());
});
61 changes: 0 additions & 61 deletions test/VoteProxyFactory.test.js

This file was deleted.

46 changes: 46 additions & 0 deletions test/VoteProxyFactoryService.test.js
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);
});
Loading

0 comments on commit 1ef2d0e

Please sign in to comment.