硬帽子时间 -n -地雷
此插件将帮助您在测试和使用时操纵时间和地雷块 hardhat node 开发任何类型的DApp.
哈达特 插件实例 .
什麽
此插件会添加一些任务来操纵未来块的时间戳, 如果您正在使用的话 hardhat node,它会帮助你开发DApps,这些DApps需要时间而不需要等待时间来真正消散.
除了增加上述任务之外,它还以函数格式扩展了HardhatRuntime Environment的相同任务,以便您能够在JS/TS环境中使用(这是自动测试,或您自己的脚本和任务).
安装
要安装它,你只需要
npm install @atixlabs/hardhat-time-n-mine hardhat
导入您的插件 hardhat.config.js数字 :
require("@atixlabs/hardhat-time-n-mine");
或者,如果你正在使用类型脚本,在您的 hardhat.config.ts数字 :
import "@atixlabs/hardhat-time-n-mine";
所需的插件
此插件不需要其他插件, 它只需要您安装 Hardhat ^ 2. 0.0( 已经用 2.4. 0 测试过) .
任务
此插件添加了以下小节中解释的任务 .
请注意,你必须使用 --network localhost 如果您正在本地运行节点(或者使用指定url指向您节点的任何其他网络) .
属于我的
Usage: hardhat [GLOBAL OPTIONS] mine [--amount <INT>]
OPTIONS:
--amount amount of blocks to be mined (default: 1)
mine: mines a single block
For global options help run: hardhat help
时间
Usage: hardhat [GLOBAL OPTIONS] increaseTime delta
POSITIONAL ARGUMENTS:
delta difference to add to the current time tracker. Can be a number representing the seconds or a string representing the delta
increaseTime: adds the given delta. NOTICE: this counts 'real' ellapsing time and is not idempotent, we recommend you user setTimeIncrease
For global options help run: hardhat help
我们正在使用 分钟 来解析三角洲,如果它不是一个数字,那么你可以使用其中的任何一种格式.
实例:
hardhat increaseTime 10: 增加十秒钟hardhat increaseTime 1d: 增加一天时间hardhat increaseTime "1 week": 增加一周时间hardhat increaseTime 1y: 增加一年
时间增加
Usage: hardhat [GLOBAL OPTIONS] setTimeIncrease delta
POSITIONAL ARGUMENTS:
delta difference between the current timestamp and the next. Can be a number representing the seconds or a string representing the delta
setTimeIncrease: makes the next block timestamp increase the given delta with respect to the current block timestamp
For global options help run: hardhat help
我们正在使用 分钟 来解析三角洲,如果它不是一个数字,那么你可以使用其中的任何一种格式.
实例:
hardhat setTimeIncrease 10: 增加十秒钟hardhat setTimeIncrease 1d: 增加一天时间hardhat setTimeIncrease "1 week": 增加一周时间hardhat setTimeIncrease 1y: 增加一年
设置时间NextBlock
Usage: hardhat [GLOBAL OPTIONS] setTimeNextBlock time
POSITIONAL ARGUMENTS:
time timestamp of the next block
setTimeNextBlock: set the timestamp of the next block(does not actually mine)
For global options help run: hardhat help
时间
Usage: hardhat [GLOBAL OPTIONS] setTime time
POSITIONAL ARGUMENTS:
time timestamp of the next block
setTime: mines a single block with a given time, effectively setting the time of the blockchain
For global options help run: hardhat help
环境扩展
此插件通过添加一个 timeAndMine 字段
它是一个具有五个功能的物体,即:
-
属于我的
-
时间
-
设置时间NextBlock
-
时间
-
时间增加
前面提到的每个函数都与前面提到的任务一样(但需要全部参数),可以在测试/标语中被使用.
配置
此插件不需要任何类型的额外配置 .
使用量
一旦您在 hardhat.config.js/hardhat.config.ts 中安装并导入了插件,您就不必做其他任何工作,只需使用其中的功能 timeAndMine 对象或使用定义的任务.
捐款
一旦安装了回波,您就可以使用
npm run test:tasks
(你必须有一个节点运行)
要测试hre方法, 你必须运行:
npm run test:hreMethods
你可以用它测试所有
npm test
你可以用:
npm run lint
或者说
npm run lint:fix
今后的工作
- 添加
ms以解析时间三角洲 - 添加一些日期解析