Dev Environment (Web)
- IDE - Remix
- Dapp browsers- Metamask
- Smart contract language - solidity
- Simulator - ganache-cli
Dev Environment (Standalone)
- IDE - Visual Studio Code
- Frameworks- Nodejs
- Smart contract language - solidity
- Test framework - Mocha/chai
- Simulator - ganache-cli
- Library - web3.js
- Smart contract framework - Truffle
Truffle
- Contract compilation, linking, deployment and binary management
- Automated testing and rapid development
- Network management for deploying to public/private networks
- Package management with EthPM and NPM
- Interactive console for contract communication
- Build pipeline supports tight integration
- External script runner that executes scripts within truffle environment
Truffle framework
- Creating a project
- Exploring the project
- Testing
- Compiling
- Migrating with ganache
- Interacting with contract
Truffle - directory structure
contracts/
: Directory for solidity contracts
migrations/
: Directory for scriptable deployment files
test/
: Directory for test files for testing your application and contracts
truffle-config.js
: Truffle configuration file
Test frameworks (Truffle use them under hood)
Hooks in Mocha
before()
— Runs once before the first test case in the block
beforeEach()
— Runs before each test case
afterEach()
— Runs after each test case
after()
— Runs once after the last test case in the block
- Sequence of Hooks
before() -> beforeEach() -> test() -> afterEach() -> after()
Coverage
- Given the nature of smart contract development, where data is literal value, testing practises needs to be stringent. 100% code coverage is not maximum to aim, its must.
Achieving 100% Coverage
- Positive test
- Test that code behaves as expected when valid data is given.
- Negative tests
- Test that code behaves as expected when invalid data is given.
Tools
- Linting
- Coverage
- Helpers and utilities