Skip to content

Commit dd889cd

Browse files
authored
Merge pull request #748 from LiuN1an/task/liun1an
translate task 6
2 parents 7915d99 + 44173e6 commit dd889cd

File tree

2 files changed

+131
-34
lines changed

2 files changed

+131
-34
lines changed

basic/06-ethersjs-waffle/README-cn.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[English](https://github.com/Dapp-Learning-DAO/Dapp-Learning/main/basic/06-ethersjs-waffle/README.md)
2+
3+
## 前言
4+
5+
Waffle 是一款适配 ehter.js 的智能合约测试库。本样例演示了使用 Waffle 进行测试的基本流程及使用方法.
6+
Waffle 详细使用方法可以参考 [Waffle 官网](https://ethereum-waffle.readthedocs.io/en/latest/getting-started.html) , 对于不熟悉 Waffle 测试框架的开发者, 可以根据本样例进行基础的操作, 阅读样例代码, 形成初步的流程概念, 之后再参考官网进行更加深入的了解.
7+
8+
## 合约介绍
9+
10+
- contract/SimpleToken.sol
11+
一个标准的 ERC20 合约, 实现了 ERC20 的所有接口, 用户可以使用这个合约进行 ERC20 代币的发放.
12+

13+
14+
## 脚本介绍
15+
16+
- test/simpleTokenTest.js
17+
SimpleToken.sol 合约的单元测试代码. 这里只写了一个测试脚本, 实际开发中, 可以在 test 目录下, 针对不同的合约, 编写多个单元测试脚本, 之后使用 yarn test 命令即可执行 test 目录下所有的单元测试脚本.
18+
在 simpleTokenTest.js 脚本中, 对 SimpleToken.sol 合约的各个接口进行简单的测试, 可以参考此样例编写其他合约的单元测试代码.
19+
20+
- index.js
21+
外部合约, 需要单独进行调用. 对应实际生产环境中, 当单元测试通过后, 就可以调用此脚本进行实际的生成操作.
22+
此脚本名字自行进行定义, 这里是使用 index.js 进行指定
23+
24+
## 操作步骤
25+
26+
- 1 安装依赖
27+
28+
```bash
29+
yarn install
30+
```
31+
32+
- 2 编译合约
33+
34+
```bash
35+
yarn build
36+
```
37+
38+
- 3 配置环境变量
39+
40+
```bash
41+
cp .env.example .env
42+
43+
## 然后修改 .env ,在其中配置 PRIVATE_KEY 和 INFURA_ID
44+
```
45+
46+
- 4 执行测试
47+
48+
```bash
49+
yarn test
50+
```
51+
52+
- 5 测试 index.js
53+
54+
```bash
55+
node index.js
56+
```
57+
## 说明
58+
在使用命yarn install命令,提示无法找到yarn命令时(比如在VMware上跑),可以尝试执行:
59+
1. $ sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.rep
60+
2. $ sudo yum install yarn
61+
62+
之后查看yarn 版本:
63+
$ yarn --versionyarn --version
64+
65+
66+
- 如果在windows上跑yarn test命令时,要把package.json文件中script脚本中test命令中的export命令修改为set命令,否则会报找不到命令。
67+
68+
修改前:
69+
70+
```
71+
"scripts": {
72+
"build": "waffle",
73+
"test": "export NODE_ENV=test && mocha --timeout 10000"
74+
},
75+
```
76+
77+
修改后:
78+
79+
```
80+
"scripts": {
81+
"build": "waffle",
82+
"test": "set NODE_ENV=test && mocha --timeout 10000"
83+
},
84+
```
85+
86+
87+
## 参考文档
88+
89+
- waffle 官方文档: <https://ethereum-waffle.readthedocs.io/en/latest/getting-started.html>
90+
91+
- ehterjs 官方文档: <https://docs.ethers.io/v4/api-providers.html>
92+
<https://docs.ethers.io/v5/getting-started/#getting-started--contracts>
93+
94+
- 中文文档: <https://learnblockchain.cn/docs/ethers.js/api-providers.html>

basic/06-ethersjs-waffle/README.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,72 @@
1-
## 前言
1+
[中文](https://github.com/Dapp-Learning-DAO/Dapp-Learning/main/basic/06-ethersjs-waffle/README-CN.md)
22

3-
Waffle 是一款适配 ethers.js 的智能合约测试库。本样例演示了使用 Waffle 进行测试的基本流程及使用方法.
4-
Waffle 详细使用方法可以参考 [Waffle 官网](https://ethereum-waffle.readthedocs.io/en/latest/getting-started.html) , 对于不熟悉 Waffle 测试框架的开发者, 可以根据本样例进行基础的操作, 阅读样例代码, 形成初步的流程概念, 之后再参考官网进行更加深入的了解.
3+
## Preface
54

6-
## 合约介绍
5+
Waffle is a smart contract test library that adapts to ehter.js. This example demonstrates the basic process and usage of Waffle test.
6+
You can refer to the offical website of Waffle width the detailed usage(https://ethereum-waffle.readthedocs.io/en/latest/getting-started.html).If you are a developler not familiar with Waffle, you could read the sample code and do exercises, then refer to the official website for a more in-depth understanding.
77

8-
- contract/SimpleToken.sol
9-
一个标准的 ERC20 合约, 实现了 ERC20 的所有接口, 用户可以使用这个合约进行 ERC20 代币的发放.
8+
## Contracts Introduction
9+
10+
- contract/SimpleToken.sol
11+
A standard ERC20 contract that implements all interface of ERC20. Users could issue ERC20 tokens using this contract.
1012

1113

12-
## 脚本介绍
14+
## Scripts Introduction
1315

14-
- test/simpleTokenTest.js
15-
SimpleToken.sol 合约的单元测试代码. 这里只写了一个测试脚本, 实际开发中, 可以在 test 目录下, 针对不同的合约, 编写多个单元测试脚本, 之后使用 yarn test 命令即可执行 test 目录下所有的单元测试脚本.
16-
simpleTokenTest.js 脚本中, 对 SimpleToken.sol 合约的各个接口进行简单的测试, 可以参考此样例编写其他合约的单元测试代码.
16+
- test/simpleTokenTest.js
17+
The unit test code of SimpleToken.sol contract. There is only one test script here, you could write multiple scripts of unit test codes for different contracts under the "test" directory during the development.
18+
Each interface of SimpleToken.sol contract will be simplely tested in the simpleTokenTest.js script.You can refer to the sample to write unit test codes of other contracts.
1719

18-
- index.js
19-
外部合约, 需要单独进行调用. 对应实际生产环境中, 当单元测试通过后, 就可以调用此脚本进行实际的生成操作.
20-
此脚本名字自行进行定义, 这里是使用 index.js 进行指定
20+
- index.js
21+
External contracts needs to be invoked separately. When unit test is passed, the script could be called to generate some actions in the production environment.
2122

22-
## 操作步骤
23+
## steps
2324

24-
- 1 安装依赖
25+
- 1 install dependencies
2526

2627
```bash
2728
yarn install
2829
```
2930

30-
- 2 编译合约
31+
- 2 compile contracts
3132

3233
```bash
3334
yarn build
3435
```
3536

36-
- 3 配置环境变量
37+
- 3 config environment variables
3738

3839
```bash
3940
cp .env.example .env
4041

41-
## 然后修改 .env ,在其中配置 PRIVATE_KEY INFURA_ID
42+
## modify PRIVATE_KEY and INFURA_ID in .env
4243
```
4344

44-
- 4 执行测试
45+
- 4 Test Execution
4546

4647
```bash
4748
yarn test
4849
```
4950

50-
- 5 测试 index.js
51+
- 5 test index.js
5152

5253
```bash
5354
node index.js
5455
```
55-
## 说明
56-
在使用命yarn install命令,提示无法找到yarn命令时(比如在VMware上跑),可以尝试执行:
56+
57+
## Note
58+
59+
when it hint that "cannot find yarn commands"(when running on VMWare), you can try:
60+
5761
1. $ sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.rep
5862
2. $ sudo yum install yarn
5963

60-
之后查看yarn 版本:
64+
check yarn version
6165
$ yarn --versionyarn --version
6266

67+
- If run `yarn test` on windows, you should change the "export" keyword to the "set" keyword in the "test" command of the "scripts" key of the file named package.json
6368

64-
- 如果在windows上跑yarn test命令时,要把package.json文件中script脚本中test命令中的export命令修改为set命令,否则会报找不到命令。
65-
66-
修改前:
69+
Before changed:
6770

6871
```
6972
"scripts": {
@@ -72,21 +75,21 @@ $ yarn --versionyarn --version
7275
},
7376
```
7477

75-
修改后:
78+
afer changed:
7679

7780
```
7881
"scripts": {
7982
"build": "waffle",
8083
"test": "set NODE_ENV=test && mocha --timeout 10000"
8184
},
8285
```
83-
84-
85-
## 参考文档
8686

87-
- waffle 官方文档: <https://ethereum-waffle.readthedocs.io/en/latest/getting-started.html>
87+
## Reference document
88+
89+
90+
- waffle offical document: <https://ethereum-waffle.readthedocs.io/en/latest/getting-started.html>
8891

89-
- ethers.js 官方文档: <https://docs.ethers.io/v4/api-providers.html>
90-
<https://docs.ethers.io/v5/getting-started/#getting-started--contracts>
92+
- etherjs offical document: <https://docs.ethers.io/v4/api-providers.html>
93+
<https://docs.ethers.io/v5/getting-started/#getting-started--contracts>
9194

92-
- 中文文档: <https://learnblockchain.cn/docs/ethers.js/api-providers.html>
95+
- Chinese document: <https://learnblockchain.cn/docs/ethers.js/api-providers.html>

0 commit comments

Comments
 (0)