Skip to content

Commit

Permalink
Added prettier files and updated editor snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
ritave committed Apr 7, 2018
1 parent 1c71f20 commit a2447a0
Show file tree
Hide file tree
Showing 169 changed files with 6,160 additions and 6,385 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ To refresh the repository state as much as possible run:
yarn clean && yarn lerna clean --yes && rm -r node_modules && yarn install
```




🐙 was here.

[core-url]: /packages/core
4 changes: 1 addition & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"lerna": "2.9.0",
"packages": [
"packages/*"
],
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "independent"
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ Inside this package there are multiple smart-contracts from multiple open-source
While we're working to get everything under LGPLv2.1 this is not currently possible.
[`contracts`](./contracts) and [`test`](./test) folders are split into subfolders with specific names, code under those subfolders is licensed under licenses as follow:

| Subfolder | License | Original source |
| --------------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| `tcr/` | [![license](https://img.shields.io/badge/license-Apache%20v2.0-green.svg)](./licenses/LICENSE-tcr) | [skmgoldin/tcr](https://github.com/skmgoldin/tcr) |
| `multisig/` | [![license](https://img.shields.io/badge/license-LGPL%20v2.1-green.svg)](./licenses/LICENSE-general) | [gnosis/MultiSigWallet](https://github.com/gnosis/MultiSigWallet) |
| `anything else` | [![license](https://img.shields.io/badge/license-LGPL%20v2.1-green.svg)](./licenses/LICENSE-general) | [civil/Civil](https://github.com/joincivil/Civil) |
| Subfolder | License | Original source |
| --------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| `tcr/` | [![license](https://img.shields.io/badge/license-Apache%20v2.0-green.svg)](./licenses/LICENSE-tcr) | [skmgoldin/tcr](https://github.com/skmgoldin/tcr) |
| `multisig/` | [![license](https://img.shields.io/badge/license-LGPL%20v2.1-green.svg)](./licenses/LICENSE-general) | [gnosis/MultiSigWallet](https://github.com/gnosis/MultiSigWallet) |
| `anything else` | [![license](https://img.shields.io/badge/license-LGPL%20v2.1-green.svg)](./licenses/LICENSE-general) | [civil/Civil](https://github.com/joincivil/Civil) |

### Multisig

Expand Down
11 changes: 2 additions & 9 deletions packages/contracts/ethpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Set of contracts for Civil, including Newsroom and TCR",
"authors": [
"Nick Reynolds",
"Olaf Tomalka",
"Olaf Tomalka",
"Mike Goldin",
"Isaac Kang",
"Terry Li",
Expand All @@ -14,14 +14,7 @@
"Yorke Rhodes",
"Mira Zeitlin"
],
"keywords": [
"newsroom",
"civil",
"consensys",
"plcr",
"tokens",
"tcr"
],
"keywords": ["newsroom", "civil", "consensys", "plcr", "tokens", "tcr"],
"dependencies": {
"tokens": "1.0.0",
"dll": "1.0.3",
Expand Down
4 changes: 3 additions & 1 deletion packages/contracts/migrations/2_optional_for_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module.exports = (deployer: any, network: string, accounts: string[]) => {
allocation = totalSupply.div(new BN(originalCount, BASE_10));
await token.transfer(user, allocation);

if (addresses.length === 1) { return true; }
if (addresses.length === 1) {
return true;
}
return giveTokensTo(addresses.slice(1), originalCount);
}

Expand Down
7 changes: 2 additions & 5 deletions packages/contracts/migrations/4_deploy_plcr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global artifacts */

import { approveEverything, config, inTesting} from "./utils";
import { approveEverything, config, inTesting } from "./utils";
import { MAIN_NETWORK } from "./utils/consts";

const Token = artifacts.require("EIP20.sol");
Expand All @@ -20,10 +20,7 @@ module.exports = (deployer: any, network: string, accounts: string[]) => {
tokenAddress = Token.address;
}

await deployer.deploy(
PLCRVoting,
tokenAddress,
);
await deployer.deploy(PLCRVoting, tokenAddress);

if (inTesting(network)) {
await approveEverything(accounts, Token.at(tokenAddress), PLCRVoting.address);
Expand Down
10 changes: 4 additions & 6 deletions packages/contracts/migrations/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ import * as fs from "fs";

import { MAIN_NETWORK } from "./consts";

export const config = JSON.parse(
fs
.readFileSync("../../conf/config.json")
.toString());
export const config = JSON.parse(fs.readFileSync("../../conf/config.json").toString());

export function inTesting(network: string): boolean {
return network !== MAIN_NETWORK && !(network in config.testnets);
}

export async function approveEverything(addresses: string[], token: any, target: string): Promise<void> {
await Promise.all(
addresses.map(async (user) => {
addresses.map(async user => {
const balance = await token.balanceOf(user);
await token.approve(target, balance, { from: user });
}));
}),
);
}
33 changes: 18 additions & 15 deletions packages/contracts/test/multisig/multsigwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,63 @@ const INCLUDE_EXECUTED = true;
const sendTransactionAsync = promisify(web3.eth.sendTransaction, web3.eth);
const balanceAsync = promisify<BigNumber>(web3.eth.getBalance, web3.eth);

contract("MultiSigWallet", (accounts) => {
contract("MultiSigWallet", accounts => {
let instance: any;
const REQUIRED_CONFIRMATIONS = 2;
const NOT_WALLET_OWNER = accounts[9];

beforeEach(async () => {
instance = await MultiSigWallet.new(
[accounts[0], accounts[1], accounts[2]],
REQUIRED_CONFIRMATIONS);
instance = await MultiSigWallet.new([accounts[0], accounts[1], accounts[2]], REQUIRED_CONFIRMATIONS);
});

describe("executeTransaction", () => {
it("works after requirement change", async () => {
const DEPOSIT = 1000;

// Send money to the wallet contract
await sendTransactionAsync({to: instance.address, value: DEPOSIT, from: accounts[0]});
await sendTransactionAsync({ to: instance.address, value: DEPOSIT, from: accounts[0] });
const balance = await balanceAsync(instance.address);
expect(balance).to.be.bignumber.equal(DEPOSIT);

// Add owner number 4
const addOwnerData = instance.contract.addOwner.getData(accounts[3]);
const txIdAddOwner = getParamFromTxEvent<BigNumber>(
await instance.submitTransaction(instance.address, 0, addOwnerData, {from: accounts[0]}),
await instance.submitTransaction(instance.address, 0, addOwnerData, { from: accounts[0] }),
"transactionId",
"Submission",
);

// One pending transaction
expect(await instance.getTransactionIds(0, 1, INCLUDE_PENDING, EXCLUDE_EXECUTED))
.to.be.deep.equal([txIdAddOwner]);
expect(await instance.getTransactionIds(0, 1, INCLUDE_PENDING, EXCLUDE_EXECUTED)).to.be.deep.equal([
txIdAddOwner,
]);

// Updated required threshold to 1
const NEW_REQUIRED = 1;
const updateRequirementsData = instance.contract.changeRequirement.getData(NEW_REQUIRED);
const txIdChangeRequirement = getParamFromTxEvent(
await instance.submitTransaction(instance.address, 0, updateRequirementsData, {from: accounts[0]}),
await instance.submitTransaction(instance.address, 0, updateRequirementsData, { from: accounts[0] }),
"transactionId",
"Submission",
);

// Two pending transactios
expect(await instance.getTransactionIds(0, 2, INCLUDE_EXECUTED, EXCLUDE_EXECUTED))
.to.be.deep.equal([txIdAddOwner, txIdChangeRequirement]);
expect(await instance.getTransactionIds(0, 2, INCLUDE_EXECUTED, EXCLUDE_EXECUTED)).to.be.deep.equal([
txIdAddOwner,
txIdChangeRequirement,
]);

// Confirm change requirement
await instance.confirmTransaction(txIdChangeRequirement, { from: accounts[1] });
expect(await instance.required()).to.be.bignumber.equal(NEW_REQUIRED);

await expect(instance.executeTransaction(txIdAddOwner, {from: NOT_WALLET_OWNER})).to.eventually.be.rejected();
await expect(instance.executeTransaction(txIdAddOwner, { from: NOT_WALLET_OWNER })).to.eventually.be.rejected();

await instance.executeTransaction(txIdAddOwner, {from: accounts[0]});
expect(await instance.getTransactionIds(0, 2, EXCLUDE_PENDING, INCLUDE_EXECUTED))
.to.be.deep.equal([txIdAddOwner, txIdChangeRequirement]);
await instance.executeTransaction(txIdAddOwner, { from: accounts[0] });
expect(await instance.getTransactionIds(0, 2, EXCLUDE_PENDING, INCLUDE_EXECUTED)).to.be.deep.equal([
txIdAddOwner,
txIdChangeRequirement,
]);
});
});
});
13 changes: 4 additions & 9 deletions packages/contracts/test/newsroom/newsroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ contract("Newsroom", (accounts: string[]) => {
});

it("returns proper author", async () => {
await expect(
newsroom.author(id, { from: defaultAccount })).to.eventually.be.equal(accounts[1]);
await expect(newsroom.author(id, { from: defaultAccount })).to.eventually.be.equal(accounts[1]);
});

it("works for approved content", async () => {
Expand Down Expand Up @@ -219,9 +218,7 @@ contract("Newsroom", (accounts: string[]) => {
});

it("doesn't work without editor role", async () => {
await expect(
newsroom.approveContent(id, { from: accounts[1] }))
.to.be.rejectedWith(REVERTED);
await expect(newsroom.approveContent(id, { from: accounts[1] })).to.be.rejectedWith(REVERTED);
expect(await newsroom.isApproved(id)).to.be.false();
});

Expand Down Expand Up @@ -283,9 +280,7 @@ contract("Newsroom", (accounts: string[]) => {
});

it("doesn't work without role", async () => {
await expect(
newsroom.denyContent(id, { from: accounts[1] }))
.to.be.rejectedWith(REVERTED);
await expect(newsroom.denyContent(id, { from: accounts[1] })).to.be.rejectedWith(REVERTED);
});

it("fires an event", async () => {
Expand Down Expand Up @@ -422,7 +417,7 @@ contract("Newsroom", (accounts: string[]) => {
});

it("can't be used by non-owner", async () => {
await expect(newsroom.setName("something", {from: accounts[1]})).to.eventually.be.rejectedWith(REVERTED);
await expect(newsroom.setName("something", { from: accounts[1] })).to.eventually.be.rejectedWith(REVERTED);
});

it("fires an event", async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/test/newsroom/newsroomFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const CONTRACT_EVENT = "ContractInstantiation";
const NEWSROOM_NAME = "Newsroom name";

function createdContract(factory: any, txReceipt: Web3.TransactionReceipt): string {
const myLog = txReceipt.logs.find(
(log: any) => log.event === CONTRACT_EVENT && log.address === factory.address,
) as Web3.DecodedLogEntry<any>|undefined;
const myLog = txReceipt.logs.find((log: any) => log.event === CONTRACT_EVENT && log.address === factory.address) as
| Web3.DecodedLogEntry<any>
| undefined;

if (!myLog) {
throw new Error("ContractInstantation log not found");
Expand All @@ -33,7 +33,7 @@ async function codeMatches(instance: any, clazz: any): Promise<void> {
expect(code).to.be.equal(clazz.deployedBytecode);
}

contract("NewsroomFactory", (accounts) => {
contract("NewsroomFactory", accounts => {
const [owner, secondOwner, thirdOwner] = accounts;

let multisigFactoryInstance: any;
Expand All @@ -43,7 +43,7 @@ contract("NewsroomFactory", (accounts) => {
owners: string[],
required: number = 1,
name: string = NEWSROOM_NAME,
): Promise<{newsroom: any, multisig: any}> {
): Promise<{ newsroom: any; multisig: any }> {
const receipt = await instance.create(name, owners, required);
return {
newsroom: Newsroom.at(createdContract(instance, receipt)),
Expand Down
51 changes: 27 additions & 24 deletions packages/contracts/test/tcr/contractRegistry/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const NEWSROOM_NAME = "unused newsroom name";
const Newsroom = artifacts.require("Newsroom");
const AddressRegistry = artifacts.require("AddressRegistry");

contract("ContractAddressRegistry", (accounts) => {
contract("ContractAddressRegistry", accounts => {
describe("Function: apply", () => {
const [applicant, troll] = accounts;
const listing1 = "0x0000000000000000000000000000000000000001";
Expand All @@ -31,8 +31,9 @@ contract("ContractAddressRegistry", (accounts) => {
});

it("should allow contract owner to apply on behalf of contract", async () => {
await expect(registry.apply(testNewsroom.address, utils.paramConfig.minDeposit, "", {from: applicant }))
.to.eventually.be.fulfilled();
await expect(
registry.apply(testNewsroom.address, utils.paramConfig.minDeposit, "", { from: applicant }),
).to.eventually.be.fulfilled();

// get the struct in the mapping
const applicationExpiry = await registry.getListingApplicationExpiry(newsroomAddress);
Expand All @@ -48,26 +49,25 @@ contract("ContractAddressRegistry", (accounts) => {
});

it("should not allow a listing to apply which has a pending application", async () => {
await registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", {from: applicant });
await expect(registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", {from: applicant }))
.to.eventually.be.rejectedWith(REVERTED);
await registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", { from: applicant });
await expect(
registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", { from: applicant }),
).to.eventually.be.rejectedWith(REVERTED);
});

it(
"should add a listing to the whitelist which went unchallenged in its application period",
async () => {
await registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", {from: applicant });
await utils.advanceEvmTime(utils.paramConfig.applyStageLength + 1);
await registry.updateStatus(newsroomAddress);
const result = await registry.getListingIsWhitelisted(newsroomAddress);
expect(result).to.be.true("listing didn't get whitelisted");
},
);
it("should add a listing to the whitelist which went unchallenged in its application period", async () => {
await registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", { from: applicant });
await utils.advanceEvmTime(utils.paramConfig.applyStageLength + 1);
await registry.updateStatus(newsroomAddress);
const result = await registry.getListingIsWhitelisted(newsroomAddress);
expect(result).to.be.true("listing didn't get whitelisted");
});

it("should not allow a listing to apply which is already listed", async () => {
await utils.addToWhitelist(newsroomAddress, utils.paramConfig.minDeposit, applicant, registry);
await expect(registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", {from: applicant }))
.to.eventually.be.rejectedWith(REVERTED);
await expect(
registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", { from: applicant }),
).to.eventually.be.rejectedWith(REVERTED);
});
});

Expand All @@ -81,20 +81,23 @@ contract("ContractAddressRegistry", (accounts) => {
});

it("should allow a non-contract owner to apply", async () => {
await expect(registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", { from: applicant }))
.to.eventually.be.fulfilled();
await expect(
registry.apply(newsroomAddress, utils.paramConfig.minDeposit, "", { from: applicant }),
).to.eventually.be.fulfilled();
});
});

it("should prevent non-contract address from being listed", async () => {
await expect(registry.apply(listing1, utils.paramConfig.minDeposit, "", { from: applicant }))
.to.eventually.be.rejectedWith(REVERTED);
await expect(
registry.apply(listing1, utils.paramConfig.minDeposit, "", { from: applicant }),
).to.eventually.be.rejectedWith(REVERTED);
});

it("should prevent non-contract address from being listed when registry cast to AddressRegistry", async () => {
const parentRegistry = await AddressRegistry.at(registry.address);
await expect(parentRegistry.apply(listing1, utils.paramConfig.minDeposit, "", { from: applicant }))
.to.eventually.be.rejectedWith(REVERTED);
await expect(
parentRegistry.apply(listing1, utils.paramConfig.minDeposit, "", { from: applicant }),
).to.eventually.be.rejectedWith(REVERTED);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as utils from "../../utils/contractutils";
configureChai(chai);
const expect = chai.expect;

contract("Parameterizer", (accounts) => {
contract("Parameterizer", accounts => {
describe("Function: challengeCanBeResolved", () => {
const [proposer, challenger] = accounts;
let parameterizer: any;
Expand All @@ -21,9 +21,9 @@ contract("Parameterizer", (accounts) => {
utils.toBaseTenBigNumber(51),
parameterizer,
proposer,
);
);

await parameterizer.challengeReparameterization(propID, { from: challenger});
await parameterizer.challengeReparameterization(propID, { from: challenger });
await utils.advanceEvmTime(utils.paramConfig.pCommitStageLength);
await utils.advanceEvmTime(utils.paramConfig.pRevealStageLength + 1);

Expand All @@ -36,7 +36,8 @@ contract("Parameterizer", (accounts) => {
"voteQuorum",
utils.toBaseTenBigNumber(59),
parameterizer,
proposer);
proposer,
);

await parameterizer.challengeReparameterization(propID, { from: challenger });
await utils.advanceEvmTime(utils.paramConfig.pCommitStageLength);
Expand Down
Loading

0 comments on commit a2447a0

Please sign in to comment.