1.1.7 • Published 2 years ago
test-assistant v1.1.7
test-assistant is a unit test suite for detecting common vulnerabilities from the aspect of smart contract
test-assistant contains the following:
✓ pattern manager of unit test and attacker payloads \ ✓ has on-demand utility for test development
installation
npm i test-assistant
usage
var assistant = require('test-assistant');
const wait = ms => new Promise(res => setTimeout(res, ms));
async function done(){
await wait(1000)
}
async function serve(){
/*
@dev: test-assistant actions
*/
}
serve()
list of actions
//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
/*
@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 getContractBalance({'contract':hardhatContract, 'Attacker':hardhatAttacker})
await getPartyBalance(attacker)
1.1.1
2 years ago
1.0.19
2 years ago
1.1.0
2 years ago
1.0.18
2 years ago
1.1.7
2 years ago
1.1.6
2 years ago
1.1.5
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.0.22
2 years ago
1.0.21
2 years ago
1.0.20
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago