Framework: Waffle
Waffle is a Java web framework, one of the leading frameworks for smart contracts testing. It doesn’t use a proprietary language and does not require configuring XMLs. It is minimalistic with a small number of dependencies, easy to extend and focuses on the speed of text execution. Waffle also allows importing third party libraries during the creation of smart contracts. The framework features Solidity and Vyper compiling, writing tests with ENS, and working with Hardhat.
Waffle Features
- A nice set of Chai matchers
- Easy contract import from NPM modules
- Quick and easy compilations with native and dockerized solc and Viper
- Typescript compatible
- Fixtures, which help write maintainable test suites
- Command line flag and flag injection
- Various modules for integration (e.g. Redis, SQLAlchemy, Flask, etc.)
Waffle components and their use
Injector
One of the Waffle-specific characteristics is providing functionality for bootstrapping an application for the injector, a dependency injection framework widely appreciated for its simplicity and absence of global state. Injector modules are used by Waffle to apply flags and configure parameters of exported objects. The defaults of each flag in this case are redefined by a special function.
Using solc
Waffle uses solc for smart contract compilation, utilizing a package of JavaScript bindings for the Solidity compiler. There are two types of solc used in this case.
- native solc. It is the fastest variant, but not without issues. For instance, it may not work correctly on older architecture PCs.
- dockerized solc. This variant is recommended due to its flexibility. It is easy to set up, moreover, if Docker is already installed.
Dockerized Viper
Dockerized Viper can be also used, if smart contracts are developed in Viper. However, for this option it is necessary to install Docker and then tag its container with the necessary version.
Using Lerna
To work with Lerna using Waffle some extra configuration is required. Lerna creates special symbolic links to the original catalog, when it cross-links packs in mono-repositories (in general Waffle goes well with mono-repositories, common setting up of ‘nodeModuleDirectory’ is enough to run it). Those links will lead to source files, but this procedure breaks up the compilation with native solc.
Waffle Fixtures
In quite a number of cases it is necessary to have a proper scenario before performing smart contract code tests. For instance, while testing tokens, transfer ability must be checked first (which usually involves deploying the contract and transferring data or funds). To perform this and other procedures easier and faster, Waffle provides some fixtures. Among those are the following:
- config file. Although Waffle can do without special configurations, when more control is needed, Waffle can be configured and adjusted to any need quite easily. For that a config .json file must be written inside the project.
- sourceDirectory. It is used to specify a custom path to the directory with smart contracts.
- outputDirectory. The user may need it to make a custom path to the storage of the compilation output data.
- nodeModulesDirectory (already mentioned above). It is necessary to help Waffle resolve third party dependencies.
- cacheDirectory. Waffle is used to download binary files from a remote server or source. These files are cached to increase the speed of the following runs.
Modules to Use
Waffle executes a number of specific modules, available for the user, to make the developing process quicker and avoid inconveniences. Among them are:
- waffle.common.AppModules (composite. Installs waffle database module and logging module)
- waffle.web.common.WebModules (composite. Installs web modules)
- waffle.db.DatabaseModule (operates with SQLAlchemy and configures it to work with injections)
- waffle.log.LoggingModule (configures default basic logging)
- waffle.devel.DevelModule (modules the binds, which allows to use Python shell with the app)
- waffle.web.clastic.WebModule (the main module to provide application support)
- waffle.web.db.DatabaseSessionModule (resets the session in the end)
- waffle.web.template.TemplateModule (provides template loading, used for adding global debug variables and helps separate modules to fit the global template context)
About SmartState
Launched in 2019 and located in Dubai, SmartState provides enterprise level of Web3 security and is retaining the place of one of the leading DeFi security auditing companies. We carry out tests of security of the code core, smart contracts and blockchain for all types of errors or vulnerabilities.
We specialize in manual testing, so the SmartState’s tech team of white-hat security professionals carefully measures up a project’s git and supports clients with guidelines and recommendations for the further advancement.
Our security audit reports review the threats and vulnerabilities with which codebases may be exploited in the future, because the network achieves scalability and expands to accommodate more use cases and functionality.
Keep up to date with all the SmartState news & events, follow us on social media: