Waffle is a library for writing and testing smart contracts. It is sweeter, simpler and faster.
Sweeter: Minimalistic, few dependencies.
Simpler: Nice syntax, easy to extend.
Faster: Focus on the speed of test execution.
Follow the below steps to get started with waffle:
1. Create a project structure
mkdir testNote: In case of truffle, truffle init creates all these directories plus migrations directory, however, there is no waffle init command as such, thus, creating the project structure is manual.
2. Install Dependencies
Ensure you are in the using-waffle directory.npm i ethereum-waffle -D
npm i chai -D
npm i mocha -D
3. Create the waffle.config.json file and add below code in it
4. Add below scripts to package.json
5. Let us create a SimpleStorage contract
Paste the below code in it.
6. Now, let us create the test file for the above contract
Paste the below code in it
- You might have noticed that we did not talk about any blockchain node (not even ganache) explicitly, this because of the functionality createMockProvider().
- Event emitted by the contracts can be tested out using one or two lines of code (Simpler-Waffle: Nice syntax easy to extend 😄)
- Reverting tests too are one-liners (Sweeter-Waffle: Minimalistic 😎)
7. Compile and Run Test
npm run compile
npm run test
Waffle comes with its own advantage. Abstraction in Waffle is higher as compared to Truffle, for instance, if you are using Truffle, all the migration scripts are kept under migrations directory, in case of waffle there is no migrations directory, waffle does it for you on the go. Capturing emitted events and testing reverting cases are one or two liners. Do give it a try, “Sweeter, Simpler and Faster — Waffle.”