OpenZeppelin Test Helpers 使用教程
1. 项目的目录结构及介绍
OpenZeppelin Test Helpers 是一个用于帮助开发者编写智能合约测试的工具库。以下是其主要目录结构及介绍:
openzeppelin-test-helpers/
├── README.md
├── package.json
├── lib/
│ ├── assert.js
│ ├── balance.js
│ ├── blockchain.js
│ ├── ether.js
│ ├── expectRevert.js
│ ├── expectEvent.js
│ ├── time.js
│ ├── transaction.js
│ └── utils.js
├── test/
│ ├── assert.test.js
│ ├── balance.test.js
│ ├── blockchain.test.js
│ ├── ether.test.js
│ ├── expectRevert.test.js
│ ├── expectEvent.test.js
│ ├── time.test.js
│ ├── transaction.test.js
│ └── utils.test.js
└── .gitignore
- README.md: 项目介绍文档。
- package.json: 项目的依赖和脚本配置文件。
- lib/: 包含所有测试辅助工具的源代码文件。
- test/: 包含所有测试用例文件。
- .gitignore: Git 忽略文件配置。
2. 项目的启动文件介绍
OpenZeppelin Test Helpers 没有传统意义上的“启动文件”,因为它是一个库,需要集成到你的测试环境中使用。通常,你会在你的测试文件中引入所需的辅助工具,例如:
const { expectRevert, time } = require('openzeppelin-test-helpers');
3. 项目的配置文件介绍
OpenZeppelin Test Helpers 的配置主要通过 package.json
文件进行管理。以下是 package.json
文件的主要内容:
{
"name": "openzeppelin-test-helpers",
"version": "0.5.10",
"description": "A set of helpers for testing Ethereum smart contracts.",
"main": "lib/index.js",
"scripts": {
"test": "mocha --exit --recursive test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/OpenZeppelin/openzeppelin-test-helpers.git"
},
"keywords": [
"ethereum",
"smart",
"contracts",
"testing",
"solidity",
"zeppelin"
],
"author": "OpenZeppelin Community <maintainers@openzeppelin.org>",
"license": "MIT",
"bugs": {
"url": "https://github.com/OpenZeppelin/openzeppelin-test-helpers/issues"
},
"homepage": "https://github.com/OpenZeppelin/openzeppelin-test-helpers#readme",
"dependencies": {
"bn.js": "^5.1.1",
"chai": "^4.2.0",
"chai-bn": "^0.2.1",
"ethers": "^4.0.47",
"truffle": "^5.0.38"
},
"devDependencies": {
"mocha": "^6.2.2"
}
}
- name: 项目名称。
- version: 项目版本。
- description: 项目描述。
- main: 入口文件。
- scripts: 包含运行测试的脚本。
- dependencies: 项目依赖的其他库。
- devDependencies: 开发环境依赖的其他库。
通过以上配置,你可以安装所需的依赖并运行测试脚本来验证你的智能合约测试。