---
tags: Legacy
---
# Smart Contract Testing Plan
## Goal
Define the testing BlockScience can build out to aid in stream agreement smart contract development.
## Summary
- There are two styles of testing to consider: micro (unit) and macro (integration/user) testing
- Relying on the mathematical specification, implementation specification, and the cadCAD model we can design tests for test driven development
- In this document we first define all possible aspects of testing that *could* be undertaken and then we give a tenative plan for what BlockScience likely would be most effective in collaboration on
## Classes of Possible Tests to Develop
### Security
Tests for access permission and ensuring that all user permissions are correctly configured
### Mechanism Tests
Tests to ensure the mechanisms are working as designed
### Incentives Testing
Tests designed to verify that the economic incentives are working as expected and the system is staying stable
## Micro/Unit Testing
Micro testing can be done to test specific functions or functionality where the results should be deterministic each time.
### Testing Enviroments/Methods
#### Hardhat
- Hardhat allows for writing javascript based tests to check smart contract functionality
- The stack trace gives back both the solidity as well as the javascript stack trace for identification of errors
- Can use mainnet forking to get a local copy of the mainnet
#### Dapptools
- Large benefit in the ability to write tests using solidity and not worry about things like number representation which javascript based tests struggle with
- Can also do mainnet forking
#### Symbolic Execution/hevm
- This method can be done within the Dapptools running hevm under the hood
- "The hevm project is an implementation of the Ethereum virtual machine (EVM) made specifically for symbolic execution, unit testing and debugging of smart contracts"
- Symbolic execution is an abstract testing type that takes the form of inputs and tests all that can happen along trees of actions
- Downside is it is much more complex to implement and it also can take a while to run the tests because of exponential explosion from combinations of paths
#### Other Options
- Truffle and forge serve as other options but we believe that the other tools provide better options
### Potential Tests
#### Security Tests
- Writing suites of tests to ensure that users only have access to what they are supposed to use
- Tests to see if vault relayers work
- Tests to see whether joins or leaves correctly change the permissions
#### Mechanisms Tests
- Testing vault integrations
- Testing pool mechanisms
#### Integration Tests
- Testing that the combined contracts between the vault and pool correctly work together
#### Incentive Testing
- Testing against attack vectors for nefarious brokers or nefarious delegators
- Ensuring that liquidity constraints are not too binding
- Ensuring that yield and payments do not allocate disproportionately
## Macro/Integration/User Testing
Macro testing can be done by deploying contracts to test networks and then querying the network with specialized tools to gather the history of system state related to the contracts.
### Testing Enviroments/Methods
#### TrueBlocks
- Benefit of avoiding burning through gas
- Easier to figure out actual user experience
- Best used when a rough/V1 version is created and can be deployed/interacted with instead of constantly re-deploying
#### The Graph
- Indexing based service where a subgraph can be created of the test network
- Tougher implementation
### Potential Tests
- Running long term incentive tests mirroring the micro incentive testing
- Getting closer to a true mainnet implementation to test performance bottlenecks
- Running user behavior studies to see metrics such as common usage patterns, pain points of the system and gaining insight into the overall behaviors.
## BlockScience Plan & Recommendations
### Testing Enviroment Recommendations
**Micro**: Utilize either Hardhat or DappTools
**Macro**: Utilize TrueBlocks
### BlockScience Focus
- Primary responsibility for designing incentive testing and user behavior testing
- Support role in integration testing and unit test building
- Enrich cadCAD model and specification documentation through iteration with testing and user experience studies
## Planned Milestones
1. Pseudo-code Tests / General Implementation Plan
2. Pre Smart Contract Micro Tests (likely implemented on the cadCAD model)
3. Smart Contract Micro Tests
4. After V1 smart contract development -> Smart Contract Macro Integration Tests
5. User Experience Study