Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.2.1/migrate tests typescript #429

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require("@nomiclabs/hardhat-waffle");

require("./tasks/accounts");
require("./tasks/deploy");

/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
networks: {
ganache: {
url: "http://127.0.0.1:7545", // Localhost (default: none)
},
rinkeby: {
url: "https://rinkeby.infura.io/v3/6d106b8213de41e9921e1198c69a5cc4",
gasPrice: 4000000000,
accounts: {
mnemonic: process.env.WALLET_MNEMONIC
}
},
ropsten: {
url: "https://ropsten.infura.io/v3/6d106b8213de41e9921e1198c69a5cc4",
gasPrice: 4000000000,
accounts: {
mnemonic: process.env.WALLET_MNEMONIC
}
}
},

solidity: {
version: "0.8.0",
settings: {
optimizer: {
enabled: true,
runs: 1000,
},
},
},
};
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
},
"devDependencies": {
"@nomiclabs/buidler": "^1.4.8",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/test-environment": "^0.1.9",
"@openzeppelin/test-helpers": "^0.5.10",
"@smartdec/smartcheck": "^2.0.1",
"@types/chai": "^4.2.22",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"dotenv": "^8.2.0",
"eth-gas-reporter": "^0.2.22",
"hardhat": "^2.6.4",
"install": "^0.13.0",
"mocha": "^8.3.2",
"np": "^7.5.0",
Expand All @@ -44,20 +49,22 @@
"truffle": "^5.3.2",
"truffle-abi": "^1.0.3",
"truffle-plugin-verify": "^0.5.8",
"ts-node": "^10.3.0",
"typescript": "^4.4.4",
"web3": "^1.3.5"
},
"scripts": {
"compile": "truffle compile",
"compile-abi": "truffle compile && truffle-abi",
"coverage": "DISABLE_SOLC_OPTIMIZER=true scripts/coverage.js",
"deploy:ganache": "truffle deploy --network ganache --reset 2>&1 | tee logs/ganache-deploy.log",
"deploy:rinkeby": "truffle deploy --network rinkeby --reset 2>&1 | tee logs/rinkeby-deploy.log",
"deploy:mainnet": "truffle deploy --network mainnet --reset 2>&1 | tee logs/mainnet-deploy.log",
"compile": "hardhat compile && scripts/prepack.sh",
"coverage": "scripts/coverage.js",
"deploy:ganache": "yarn compile && hardhat deploy --network ganache",
"deploy:rinkeby": "yarn compile && hardhat deploy --network rinkeby",
"deploy:ropsten": "yarn compile && hardhat deploy --network ropsten",
"deploy:mainnet": "yarn compile && hardaht deploy --network mainnet",
"ganache": "ganache-cli --deterministic -p 7545 --networkId 1337",
"lint": "prettier --list-different 'contracts/**/*.sol' '**/*.js' '**/*.md'",
"lint:fix": "prettier --write 'contracts/**/*.sol' '**/*.js' '**/*.md'",
"migrate": "truffle migrate --network",
"test": "mocha --timeout 2000000 --exit --recursive",
"test": "truffle compile && mocha -r ts-node/register test/**/*.test.ts --timeout 2000000 --exit --recursive",
"verify": "scripts/verify.js",
"release": "npm run lint:fix && np --no-publish --no-yarn"
},
Expand Down
11 changes: 11 additions & 0 deletions scripts/prepack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if [ -d "build/contracts" ]
then
rm -rf "build/contracts"
fi
mkdir -p "build/contracts"

find "artifacts/contracts" -type f -name "*.json" -exec cp "{}" build/contracts \;

find "build/contracts" -type f -name "*.dbg.json" -delete
7 changes: 7 additions & 0 deletions tasks/accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();

for (const account of accounts) {
console.log(account.address);
}
});
249 changes: 249 additions & 0 deletions tasks/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
const {
toBN,
toWei,
ETH_TOKEN,
maximumChunks,
unitPrice,
numberOfUnits,
} = require("../utils/ContractUtil.js");

const { deployDao, getNetworkDetails } = require("../utils/HardhatDeploymentUtil.js");

require("dotenv").config();

task("deploy", "Deply the list of contracts", async (taskArgs, hre) => {
const network = hre.hardhatArguments.network;
console.log(`Deploying tribute-contracts to ${network} network`);

const { contracts } = require(`../deployment/${network}.config`);
const hardHatImports = require("../utils/HardhatUtil.js")(contracts);
const DaoArtifacts = hardHatImports.DaoArtifacts;

let daoArtifacts;

if (process.env.DAO_ARTIFACTS_CONTRACT_ADDR) {
console.log(`Attach to existing DaoArtifacts contract`);
daoArtifacts = await DaoArtifacts.attatch(
process.env.DAO_ARTIFACTS_CONTRACT_ADDR
);
} else {
console.log(`Creating new DaoArtifacts contract`);
const daoArtifact = await (await DaoArtifacts).deploy();
daoArtifacts = await daoArtifact.deployed();
}

console.log(`DaoArtifacts: ${daoArtifacts.address}`);

const deployFunction = hardHatImports.deployFunctionFactory(
hre,
daoArtifacts
);

if (network === "mainnet") {
res = await deployMainnetDao(deployFunction, network, hardHatImports);
} else if (network === "ganache") {
const accounts = await hre.ethers.getSigners();
res = await deployGanacheDao(
deployFunction,
network,
accounts,
hardHatImports
);
} else if (network === "rinkeby") {
res = await deployRinkebyDao(deployFunction, network, hardHatImports);
} else if (network === "test" || network === "coverage") {
res = await deployTestDao(
deployFunction,
network,
accounts,
hardHatImports
);
}

let { dao, extensions, testContracts } = res;

if (dao) {
await dao.finalizeDao();
console.log("************************");
console.log(`DaoRegistry: ${dao.address}`);
console.log(
`Multicall: ${
testContracts.multicall ? testContracts.multicall.address : ""
}`
);
console.log(`BankExtension: ${extensions.bank.address}`);
console.log(
`NFTExtension: ${extensions.nft ? extensions.nft.address : ""}`
);
console.log(
`ERC20Extension: ${
extensions.erc20Ext ? extensions.erc20Ext.address : ""
}`
);
console.log("************************");
} else {
console.log("************************");
console.log("no migration for network " + network);
console.log("************************");
}
});

const deployRinkebyDao = async (deployFunction, network, hardHatImports) => {
if (!process.env.DAO_NAME)
throw Error("Missing env var: DAO_NAME");
if (!process.env.DAO_OWNER_ADDR)
throw Error("Missing env var: DAO_OWNER_ADDR");
if (!process.env.ERC20_TOKEN_NAME)
throw Error("Missing env var: ERC20_TOKEN_NAME");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Expected { after 'if' condition.

Suggested change
throw Error("Missing env var: ERC20_TOKEN_NAME");
{throw Error("Missing env var: ERC20_TOKEN_NAME");}

if (!process.env.ERC20_TOKEN_SYMBOL)
throw Error("Missing env var: ERC20_TOKEN_SYMBOL");
if (!process.env.ERC20_TOKEN_DECIMALS)
throw Error("Missing env var: ERC20_TOKEN_DECIMALS");

return await deployDao({
...hardHatImports,
deployFunction,
unitPrice: toBN(toWei("100", "finney")).toString(),
nbUnits: toBN("100000").toString(),
tokenAddr: ETH_TOKEN,
erc20TokenName: process.env.ERC20_TOKEN_NAME,
erc20TokenSymbol: process.env.ERC20_TOKEN_SYMBOL,
erc20TokenDecimals: process.env.ERC20_TOKEN_DECIMALS,
maxChunks: toBN("100000").toString(),
votingPeriod: 600, // 600 secs = 10 mins
gracePeriod: 600, // 600 secs = 10 mins
offchainVoting: true,
chainId: getNetworkDetails(network).chainId,
deployTestTokens: true,
finalize: false,
maxExternalTokens: 100,
couponCreatorAddress: process.env.COUPON_CREATOR_ADDR
? process.env.COUPON_CREATOR_ADDR
: process.env.DAO_OWNER_ADDR,
daoName: process.env.DAO_NAME,
owner: process.env.DAO_OWNER_ADDR,
offchainAdmin: "0xedC10CFA90A135C41538325DD57FDB4c7b88faf7",
});
};

const deployMainnetDao = async (deployFunction, network, hardHatImports) => {
if (!process.env.DAO_NAME)
throw Error("Missing env var: DAO_NAME");
if (!process.env.DAO_OWNER_ADDR)
throw Error("Missing env var: DAO_OWNER_ADDR");
if (!process.env.ERC20_TOKEN_NAME)
throw Error("Missing env var: ERC20_TOKEN_NAME");
if (!process.env.ERC20_TOKEN_SYMBOL)
throw Error("Missing env var: ERC20_TOKEN_SYMBOL");
if (!process.env.ERC20_TOKEN_DECIMALS)
throw Error("Missing env var: ERC20_TOKEN_DECIMALS");
if (!process.env.COUPON_CREATOR_ADDR)
throw Error("Missing env var: COUPON_CREATOR_ADDR");
if (!process.env.OFFCHAIN_ADMIN_ADDR)
throw Error("Missing env var: OFFCHAIN_ADMIN_ADDR");
if (!process.env.VOTING_PERIOD_SECONDS)
throw Error("Missing env var: VOTING_PERIOD_SECONDS");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Expected { after 'if' condition.

Suggested change
throw Error("Missing env var: VOTING_PERIOD_SECONDS");
{throw Error("Missing env var: VOTING_PERIOD_SECONDS");}

if (!process.env.GRACE_PERIOD_SECONDS)
throw Error("Missing env var: GRACE_PERIOD_SECONDS");

return await deployDao({
...hardHatImports,
deployFunction,
unitPrice: toBN(toWei("100", "finney")),
nbUnits: toBN("100000"),
tokenAddr: ETH_TOKEN,
erc20TokenName: process.env.ERC20_TOKEN_NAME,
erc20TokenSymbol: process.env.ERC20_TOKEN_SYMBOL,
erc20TokenDecimals: process.env.ERC20_TOKEN_DECIMALS,
maxChunks: toBN("100000"),
votingPeriod: parseInt(process.env.VOTING_PERIOD_SECONDS),
gracePeriod: parseInt(process.env.GRACE_PERIOD_SECONDS),
offchainVoting: true,
chainId: getNetworkDetails(network).chainId,
deployTestTokens: false,
finalize: false,
maxExternalTokens: 100,
couponCreatorAddress: process.env.COUPON_CREATOR_ADDR,
daoName: process.env.DAO_NAME,
owner: process.env.DAO_OWNER_ADDR,
offchainAdmin: process.env.OFFCHAIN_ADMIN_ADDR,
});
};

const deployGanacheDao = async (
deployFunction,
network,
accounts,
hardHatImports
) => {
if (!process.env.DAO_NAME)
throw Error("Missing env var: DAO_NAME");
if (!process.env.ERC20_TOKEN_NAME)
throw Error("Missing env var: ERC20_TOKEN_NAME");
if (!process.env.ERC20_TOKEN_SYMBOL)
throw Error("Missing env var: ERC20_TOKEN_SYMBOL");
if (!process.env.ERC20_TOKEN_DECIMALS)
throw Error("Missing env var: ERC20_TOKEN_DECIMALS");
return await deployDao({
...hardHatImports,
deployFunction,
unitPrice: toBN(toWei("100", "finney")).toString(),
nbUnits: toBN("100000").toString(),
tokenAddr: ETH_TOKEN,
erc20TokenName: process.env.ERC20_TOKEN_NAME,
erc20TokenSymbol: process.env.ERC20_TOKEN_SYMBOL,
erc20TokenDecimals: process.env.ERC20_TOKEN_DECIMALS,
maxChunks: toBN("100000").toString(),
votingPeriod: 120, // 120 secs = 2 mins
gracePeriod: 60, // 60 secs = 1 min
offchainVoting: true,
chainId: getNetworkDetails(network).chainId,
deployTestTokens: true,
finalize: false,
maxExternalTokens: 100,
couponCreatorAddress: process.env.COUPON_CREATOR_ADDR
? process.env.COUPON_CREATOR_ADDR
: accounts[0].address,
daoName: process.env.DAO_NAME,
owner: accounts[0].address,
offchainAdmin: "0xedC10CFA90A135C41538325DD57FDB4c7b88faf7",
});
};

const deployTestDao = async (
deployFunction,
network,
accounts,
hardHatImports
) => {
if (!process.env.DAO_NAME) throw Error("Missing env var: DAO_NAME");
if (!process.env.ERC20_TOKEN_NAME)
throw Error("Missing env var: ERC20_TOKEN_NAME");
if (!process.env.ERC20_TOKEN_SYMBOL)
throw Error("Missing env var: ERC20_TOKEN_SYMBOL");
if (!process.env.ERC20_TOKEN_DECIMALS)
throw Error("Missing env var: ERC20_TOKEN_DECIMALS");

return await deployDao({
...hardHatImports,
deployFunction,
unitPrice: unitPrice,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Expected property shorthand.

Suggested change
unitPrice: unitPrice,
unitPrice,

nbUnits: numberOfUnits,
tokenAddr: ETH_TOKEN,
erc20TokenName: process.env.ERC20_TOKEN_NAME,
erc20TokenSymbol: process.env.ERC20_TOKEN_SYMBOL,
erc20TokenDecimals: process.env.ERC20_TOKEN_DECIMALS,
maxChunks: maximumChunks,
votingPeriod: 10, // 10 secs
gracePeriod: 1, // 1 sec
offchainVoting: true,
chainId: getNetworkDetails(network).chainId,
deployTestTokens: false,
finalize: false,
maxExternalTokens: 100,
couponCreatorAddress: "0x7D8cad0bbD68deb352C33e80fccd4D8e88b4aBb8",
offchainAdmin: "0xedC10CFA90A135C41538325DD57FDB4c7b88faf7",
daoName: process.env.DAO_NAME,
owner: accounts[0],
});
};
Loading