Skip to content

Commit

Permalink
Chore: Use buidler (#615)
Browse files Browse the repository at this point in the history
* chore: use buidler

* tests: link libraries with Truffle

* chore: use codecov

* chore: fix whitespace

Co-authored-by: Brett Sun <qisheng.brett.sun@gmail.com>
  • Loading branch information
facuspagnuolo and sohkai authored Aug 25, 2020
1 parent 847269c commit ce960e2
Show file tree
Hide file tree
Showing 7 changed files with 10,864 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci_contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:
run: yarn test
- name: coverage
run: yarn coverage
- name: codecov
uses: codecov/codecov-action@v1
with:
flags: unittests
fail_ci_if_error: true
- name: test:gas
continue-on-error: true
run: yarn test:gas:ci
Expand Down
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Dependencies
node_modules/
node_modules

# Lock files
# yarn
yarn-error.log

# Ignore package-lock files (only use yarn.lock)
package-lock.json
yarn.lock

# coverage
coverage/
Expand All @@ -12,9 +14,7 @@ coverage.json
allFiredEvents
scTopics

# truffle build artifacts
abi/
build/
bytecode/
bytecode_new/
flattened_contracts/
# build artifacts
abi
cache
artifacts
64 changes: 64 additions & 0 deletions buidler.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { usePlugin } = require('@nomiclabs/buidler/config')

usePlugin("@nomiclabs/buidler-ganache")
usePlugin('@nomiclabs/buidler-truffle5')
usePlugin('buidler-gas-reporter')
usePlugin('solidity-coverage')

module.exports = {
networks: {
// Local development network using ganache. You can set any of the
// Ganache's options. All of them are supported, with the exception
// of accounts.
// https://github.com/trufflesuite/ganache-core#options
ganache: {
url: 'http://localhost:8545',
gasLimit: 6000000000,
defaultBalanceEther: 100
},
// Local development network to test coverage. Solidity coverage
// pluging launches its own in-process ganache server.
// and expose it at port 8555.
coverage: {
url: 'http://localhost:8555',
},
// Mainnet network configured with Aragon node.
mainnet: {
url: 'https://mainnet.eth.aragon.network',
accounts: [
process.env.ETH_KEY ||
'0xa8a54b2d8197bc0b19bb8a084031be71835580a01e70a45a13babd16c9bc1563',
],
},
// Rinkeby network configured with Aragon node.
rinkeby: {
url: 'https://rinkeby.eth.aragon.network',
accounts: [
process.env.ETH_KEY ||
'0xa8a54b2d8197bc0b19bb8a084031be71835580a01e70a45a13babd16c9bc1563',
],
},
// Network configured to interact with Frame wallet. Requires
// to have Frame running on your machine. Download it from:
// https://frame.sh
frame: {
httpHeaders: { origin: 'buidler' },
url: 'http://localhost:1248',
}
},
solc: {
version: '0.4.24',
optimizer: {
enabled: true,
runs: 10000,
},
},
// The gas reporter plugin do not properly handle the buidlerevm
// chain yet. In the mean time we should 'npx buidler node' and
// then attach to running process using '--network localhost' as
// explained in: https://buidler.dev/buidler-evm/#connecting-to-buidler-evm-from-wallets-and-other-software.
// You can also run 'yarn devchain' and on a separate terminal run 'yarn test:gas'
gasReporter: {
enabled: process.env.REPORT_GAS ? true : false,
},
}
42 changes: 19 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,37 @@
],
"files": [
"/abi",
"/build",
"/artifacts",
"/contracts"
],
"scripts": {
"compile": "truffle compile",
"console": "buidler console",
"compile": "buidler compile --force",
"devchain": "buidler node",
"lint": "solium --dir ./contracts",
"test": "TRUFFLE_TEST=true yarn test:ganache-cli",
"test:gas": "GAS_REPORTER=true npm test",
"test": "buidler test",
"test:gas": "REPORT_GAS=true yarn test --network localhost",
"test:gas:ci": "yarn test:gas && npx codechecks",
"test:ganache-cli": "./node_modules/@aragon/contract-helpers-test/scripts/ganache-cli.sh",
"coverage": "npx truffle run coverage",
"abi:extract": "truffle-extract --output abi/ --keys abi",
"bytecode:extract": "truffle-bytecode extract -o bytecode",
"bytecode:extract:new": "truffle-bytecode extract -o bytecode_new",
"bytecode:compare": "yarn bytecode:extract:new && truffle-bytecode compare bytecode bytecode_new",
"prepublishOnly": "truffle compile --all && yarn abi:extract -- --no-compile"
"coverage": "buidler coverage --network coverage",
"abi:extract": "buidler-extract --output abi/ --keys abi",
"prepublishOnly": "yarn compile && yarn abi:extract -- --no-compile"
},
"dependencies": {},
"devDependencies": {
"@aragon/contract-helpers-test": "^0.1.0-rc.2",
"@aragon/truffle-config-v5": "^1.0.1",
"@aragon/contract-helpers-test": "^0.1.0-rc.3",
"@codechecks/client": "^0.1.5",
"@nomiclabs/buidler": "^1.4.3",
"@nomiclabs/buidler-ganache": "^1.3.3",
"@nomiclabs/buidler-truffle5": "^1.3.4",
"@nomiclabs/buidler-web3": "^1.3.4",
"buidler-gas-reporter": "^0.1.3",
"chai": "^4.2.0",
"coveralls": "^3.0.9",
"eth-ens-namehash": "^2.0.8",
"eth-gas-reporter": "^0.2.14",
"ethereumjs-abi": "^0.6.5",
"ganache-cli": "^6.9.0",
"mocha-lcov-reporter": "^1.3.0",
"solidity-coverage": "0.7.5",
"solium": "^1.2.3",
"truffle": "^5.0.34",
"truffle-bytecode-manager": "^1.1.1",
"truffle-extract": "^1.2.1",
"web3-eth-abi": "1.2.5",
"web3-utils": "1.2.5"
"solidity-coverage": "^0.7.9",
"solium": "^1.2.5",
"buidler-extract": "^1.0.0",
"web3": "^1.2.11"
}
}
32 changes: 11 additions & 21 deletions test/helpers/runSolidityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,8 @@ const processResult = (txReceipt, mustAssert) => {
* Modifies bytecode in place
*/
const linkLib = async (contract, libName) => {
const underscores = n => '_'.repeat(n)
const PREFIX_UNDERSCORES = 2
const ADDR_LENGTH = 40

const prefix = underscores(PREFIX_UNDERSCORES)
const suffix = underscores(ADDR_LENGTH - PREFIX_UNDERSCORES - libName.length)

const libPlaceholder = `${prefix}${libName}${suffix}`

const lib = await artifacts.require(libName).new()
const libAddr = lib.address.replace('0x', '').toLowerCase()

contract.bytecode = contract.bytecode.replace(new RegExp(libPlaceholder, 'g'), libAddr)
const library = await artifacts.require(libName).new()
await contract.link(library)
}

/**
Expand All @@ -84,15 +73,16 @@ function runSolidityTest(c, mochaContext) {
if (interface.type === 'function') {
if (['beforeAll', 'beforeEach', 'afterEach', 'afterAll'].includes(interface.name)) {
// Set up hooks
global[HOOKS_MAP[interface.name]](() =>
deployed[interface.name]()
.then(receipt => processResult(receipt, false))
)
global[HOOKS_MAP[interface.name]](async () => {
const receipt = await deployed[interface.name]()
processResult(receipt, false)
})
} else if (interface.name.startsWith('test')) {
it(interface.name, () =>
deployed[interface.name]()
.then(receipt => processResult(receipt, true))
)
it(interface.name, async () => {
const { tx } = await deployed[interface.name]()
const receipt = await web3.eth.getTransactionReceipt(tx)
processResult(receipt, true)
})
}
}
})
Expand Down
6 changes: 0 additions & 6 deletions truffle-config.js

This file was deleted.

Loading

0 comments on commit ce960e2

Please sign in to comment.