0.1.0 • Published 5 years ago
auditless.js v0.1.0
auditless.js
Collection of testing utilities that complement existing web3 frameworks.
Installation
npm i --save auditless.js
Property-based testing (EXPERIMENTAL)
auditless.js includes a simple helper for property-based testing. It uses fast-check
for state machine based
property testing and is compatible with truffle contracts.
This property checker automatically creates generators for function signatures using the contract ABI. It also:
- has minimal dependencies
- fits into existing truffle tests
- works with any interpreter
- doesn't require amending the contracts it tests
For example, we can try to check if state is an even number in the following contract.
pragma solidity ^0.4.24;
contract SimpleRandom {
uint private state = 0;
function increment(uint by) public returns (uint) {
state += 2 * by;
return state;
}
function reset() public returns (uint) {
state = 0;
return state;
}
}
with the following truffle test:
var SimpleRandom = artifacts.require("./SimpleRandom.sol"); // truffle import
const auditless = require('auditless.js');
it('should always have even state', async function() {
await auditless.assertProperty(SimpleRandom, 100, async (contract, output) => {
assert.strictEqual(output % 2, 0);
}, {verbose: true});
});
// This test should take less than a minute on a modern Mac
The last argument is the fast-check
settings and can be omitted.
0.1.0
5 years ago