# test-assistant

> test-assistant contains useful unit test patterns that developers can detect common smart contract vulnerabilities within the development phase

Latest version **1.1.7** (published 2022-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install test-assistant
pnpm add test-assistant
yarn add test-assistant
bun add test-assistant
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.7 |
| Published | 2022-06-27 |
| First published | 2022-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 27.8 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | buggerbag team |
| Maintainers | buggerbag |
| Keywords | Ethereum, smart contracts, smart contract test assistant, hardhat, hardhat test assistant, hardhat plugin, vulnerability detector, smart contract security |

## Links

- npm: https://www.npmjs.com/package/test-assistant
- npm.io page: https://npm.io/package/test-assistant

## Dependencies (10)

- [web3](https://npm.io/package/web3.md) ^0.20.7
- [ethers](https://npm.io/package/ethers.md) ^5.6.9
- [hardhat](https://npm.io/package/hardhat.md) ^2.9.9
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.1.0
- [web3-eth](https://npm.io/package/web3-eth.md) ^1.7.4
- [web3-utils](https://npm.io/package/web3-utils.md) ^1.7.4
- [web3-eth-abi](https://npm.io/package/web3-eth-abi.md) ^1.7.4
- [node-color-log](https://npm.io/package/node-color-log.md) ^9.0.0
- [web3-core-method](https://npm.io/package/web3-core-method.md) ^1.7.4
- [web3-eth-contract](https://npm.io/package/web3-eth-contract.md) ^1.7.4

## Recent versions

- 1.1.7 (latest) — 2022-06-27
- 1.1.6 — 2022-06-18
- 1.1.5 — 2022-06-16
- 1.1.4 — 2022-06-13
- 1.1.3 — 2022-06-10
- 1.1.2 — 2022-06-08
- 1.1.1 — 2022-06-08
- 1.1.0 — 2022-06-08
- 1.0.22 — 2022-06-07
- 1.0.21 — 2022-05-28
- 1.0.20 — 2022-05-20
- 1.0.19 — 2022-05-20
- 1.0.18 — 2022-05-20
- 1.0.17 — 2022-05-15
- 1.0.16 — 2022-05-15
- … 16 more at https://npm.io/package/test-assistant/versions

## README

#### [<img src="https://www.clickcease.com/img/Wolf.36eec52b.png" width="35"/>](test-assistant.png) test-assistant is a unit test suite for detecting common vulnerabilities from the aspect of smart contract
![npm](https://img.shields.io/npm/dm/test-assistant?style=flat-square)
![npm](https://img.shields.io/npm/v/test-assistant?color=%2356d8ba&label=test-assistant%20%40version&logo=test-assistant%20%40version&style=flat-square)
![npm collaborators](https://img.shields.io/npm/collaborators/test-assistant?color=%23d5e03a&label=%40collaborators&style=flat-square)
#### 📦 test-assistant contains the following:
✓ pattern manager of unit test and attacker payloads \
✓ has on-demand utility for test development
  1. reveal reentrancy <br>
     detect reentrancy vulnerability: [SWC-107](https://swcregistry.io/docs/SWC-107)
  2. reveal origin <br>
     detect phishable tx.origin vulnerability: [SWC-115](https://swcregistry.io/docs/SWC-115)
  3. reveal signature replay <br>
     detect missing protection against signature replay attacks: [SWC-121](https://swcregistry.io/docs/SWC-121)

#### 🔥 Setup:
1. Install hyper terminal: [hyper terminal](https://hyper.is)<br>
2. Install visual code software: [vs code](https://code.visualstudio.com/Download) <br>
3. Install Nodejs: [Nodejs](https://nodejs.org/en/download) <br>
4. Follow the instruction of Hardhat: [hardhat environment](https://hardhat.org/tutorial) <br>
    Setup the environment and use the local environment. <br>
5. Install the ```test-assistant``` npm package <br>
6. Goto Hardhat directory creates three folders: ```contracts```, ```test```, and ```test-assistant```.<br>
    The ```contracts``` folder is related to smart contracts. <br>
    The ```test``` folder is related to unit tests and requires test packages. <br>
    The ```test-assistant``` folder is related to our test-assistant script. <br>
7. Create a new file in the test-assistant folder as assistant.js. <br>
8. Write the ```test-assistant script``` and pick a unit test pattern. <br>
    For simplicity, write the script below: <br>
    •	Toolbox: ```reveal reentrancy```, ```reveal origin```, ```reveal signature replay``` <br>
    ```js
    var assistant = require('test-assistant');
    const wait = ms => new Promise(res => setTimeout(res, ms));
    async function done(){
      await wait(1000)
    }
    async function serve(){
      //preparation 
      const hardhat_test ='./test/test.js';
      const hardhat_contracts ='./contracts/test.sol';
      var pick = { "reveal reentrancy":true }; 
  
      //set the configuration and pick the patterns
      assistant.setconfig(pick, hardhat_test, hardhat_contracts);
      await done()

      //insert following patterns that were picked before
      await assistant.insert()
      await done()
    }
    
    serve()
    ```

    For running the script, open the hyper terminal in the Hardhat directory and write the following: <br>
    ```node test-assistant/assistant.js``` <br>
9. Follow the inline comment and construct the ```unit test``` and ```payload contract```. <br>
   In this step, insert the required aspect. <br>
10. Runs ```npx hardhat test``` within the hyper terminal. <br>
11. View the hardhat result within the hyper terminal. <br>


#### 🔥 Installation
```
npm i test-assistant
```

#### 🔥 Usage

```js
var assistant = require('test-assistant');

const wait = ms => new Promise(res => setTimeout(res, ms));
async function done(){
    await wait(1000)
}

async function serve(){
  /* test-assistant Actions */
}

serve()
```

#### 🔥 List of Actions
```js
//get list of unit test patterns
assistant.pattern_list()
await done()

//preparation 
const hardhat_test ='./test/test.js';
const hardhat_contracts ='./contracts/test.sol';
var pick = { "reveal reentrancy":true, "reveal destruct":true}; 

//set the configuration and pick the patterns
assistant.setconfig(pick, hardhat_test, hardhat_contracts);
await done()

//import new pattern to a test-assistant repository
await assistant.add_new_pattern('reveal reentrancy',
                                `${__dirname}/test/test.js`, 
                                `${__dirname}/contracts/test.sol`)
await done()

//insert following patterns that were picked before
await assistant.insert()
await done()

//export all the patterns of the test-assistant repository to new path
await assistant.export_all(`${__dirname}/@unit test/`,`${__dirname}/@payload/`)
await done()

//remove patterns
await assistant.remove_pattern('reveal reentrancy')
await done()

//assistance info
await assistant.info()
```

#### 🔥 Test Utility
```js
/*
@dev: test-assistant has several utilities such as:
  library: Web3, ethers, Web3Utils, Web3Eth, Web3EthAbi, Web3EthContract, Web3Method
  usage:   web3, ethers, utils, eth, ethabi, ethcontract, method
*/

//util
assistant.utils.toWei('1', 'ether') //assistant.toWei, assistant.fromWei
assistant.utils.randomHex(32)
assistant.utils.hexToUtf8('0x49206861766520313030e282ac')

var BN = assistant.utils.BN;
new BN(1234).toString()

//ethabi
assistant.ethabi.encodeFunctionSignature('myMethod(uint256,string)')

//log utility
const [owner, attacker] = await ethers.getSigners()
const Contract = await ethers.getContractFactory("smart_contract")
const Attacker = await ethers.getContractFactory("attacker_contract")

const hardhatContract = await Contract.connect(owner).deploy()
const hardhatAttacker = await Attacker.connect(attacker).deploy()

watch({'owner':owner,'attacker':attacker})
watch({'Smart contract':hardhatContract, 'Attacker contract':hardhatAttacker})

await assistant.getContractBalance({'contract':hardhatContract, 'Attacker':hardhatAttacker})
await assistant.getPartyBalance(attacker)
```



[<img src="https://www.clickcease.com/img/hacker.eba0f43b.png" width="35"/>](test-assistant.png) <br> 
Last version: ```1.1.7``` <br>
Github: [buggerbag team](https://github.com/BuggerBag) <br>

---
_Source: https://npm.io/package/test-assistant · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
