Testing Env for your Smart Contracts Audit
June 7, 2018 · View on GitHub
This is specific environment we use for running Solidity tests in the form of a Docker image that you can download and run on your project.
Prerequisites
- Smart contracts
- Docker installed and running (as a daemon)
Typical environment we use for testing
-
Environment
- Ethereum blockchain
- Solidity, Truffle
- Mocha/Chai as testing framework
-
Projects folders
/contractsfolder with smart contracts/testfolder with tests
-
Project files:
Migration.sol,1_initial_migration.js,2_deploy_contracts.jsfor truffle migrationtruffle.jswith networks settingspackage.jsonwith dependencies and scripts
-
Networks
- Testrpc, Ganache or Parity for testing
- Kovan/Ropsten/Rinkeby testnetwork with Infura
Installation and running
- Download/clone/fork this repository.
- Copy
npmcommands from this repo'spackage.jsonto your project. - Copy
testAll.shfrom this repo to your project. - Go to you project folder that contains
/contractsand/testfolders.-
Run
npm run blaTestfor dynamic testing -
Run
npm run blaCoveragefor test coverage report -
Run
npm run blaGasfor gas spending report -
Run
npm run blaAllfor simultaneous testing. Results will be printed to the same named files in the/auditfolder -
Run
npm run blaPlayto have your playground inside the containerThere are VI and nano editors installed, so, feel free to change something, help yourself, its all yours.
PressCntrl-Dto exit container.
-
Each run of these commands will create new Docker container, copy your contracts and tests from the project directory to the container’s volume and then run tests in our typical testing environment. Containers are self destroying on exit.
Updating your environment configuration
If your tests are not working in our environment, we need to figure out Why and change the environment. It will take some time. You can save that (paid) time and update the configuration by yourself:
- Go to the
/dockerfolder.
- Update the
package.jsonwith new dependencies from yourpackage.json, but keep it clean from unused dependencies (such as frontend packages, webpack configs and so on). - Check dockerfile and update it if needed.
- Build new docker image:
docker build -t yourcompanyname/projectname .from/dockerfolder. (don't forget ".") - Check that new Docker image is ready by running it in your project folder:
docker run --rm -it -v $(pwd)/contracts:/audit/contracts -v $(pwd)/test:/audit/test yourcompanyname/projectnamewith parameters you need.
Send us your configuration
We will rebuild the Docker image by ourselves, so please send us:
dockerfile(or files)package.json- only dependencies for the testing, not all of your dependencies
- your
package.jsonscripts section
truffle.jswith your networks congiguration
Push it back to the Github if you forked this repo before or achive it with zip/tar.
Send us the link to that commit (or .zip file)