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()

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.

Solidity code coverage tools

Static Analysis : tools

Solidity Static Analysis - Remix Plugin

  • Debug the code without execution.
  • Ensures proper coding standards, best practices, syntax errors,etc.

Solidity Static Analysis - Remix Plugin

Solidity Static Analysis - Remix Plugin

Solidity Static Analysis - Remix Plugin

  • False Positive on infinite gas for dynamic arrays such as string

Static Analysis : Echidna

  • Property testing to generate malicious inputs that break smart contracts
  • Generates inputs tailored to code
  • Optional corpus collection, mutation and coverage guidance to find deeper bugs
  • Powered by Slither to extract useful information before the fuzzing campaign

Static Analysis : Echidna

  • Automatic testcase minimization for quick triage
  • Seamless integration into the development workflow
  • Maximum gas usage reporting of the fuzzing campaign
  • Support for a complex contract initialization with Etheno and Truffle

Dynamic Analysis

  • Analysis is performed by executing the program
  • Unit testing is a type of dynamic analysis

Dynamic Analysis