-
Notifications
You must be signed in to change notification settings - Fork 136
Testing Solidity contracts developed with Truffle
Using KEVM and kprove, you can write tests for EVM bytecode the same way you can write specifications, the only difference is that tests may contain mostly concrete variables. The bytecode will, obviously, run on the KEVM using the algorithm implemented by kprove.
However, you may be interested in writing/running tests in an actual Ethereum development environment.
If the code you're testing is Solidity code, one of the most popular development frameworks for Solidity applications is a Node.js-based framework called Truffle. It includes a testing framework with which you can write and run tests on a local development Ethereum blockchain such as Ganache. The tests can be written either in JavaScript using Mocha and Chai, or in Solidity. If you're curious about how the interaction between Node and Solidity contracts is achieved, you can check out the documentation on contract abstraction.
- Install Node.js and npm. If installing npm on Ubuntu 18.04, you might have user permissions issues, e.g. installing packages might require root privileges. Install nvm first and you shouldn't run into these issues.
- Install Truffle:
npm install -g truffle
- Install Ganache.
- Create your own Solidity project or clone an existing project (which was developed using Truffle). First run Ganache and make sure that the port number Ganache uses is the one specified in
truffle-config.js
or intruffle.js
. Usetruffle test
in the project's root directory to run all the tests. If compilation fails you might need to install additional dependencies, you can do this usingnpm install <name-of-package>
.