简介
simd testnet 子命令可以帮助你轻松初始化并启动一个用于测试的模拟测试网络。simd 二进制文件还包含一个 testnet 命令,使你能够在进程内启动一个模拟测试网络,或者为在独立进程中运行的模拟测试网络初始化所需文件。
初始化文件
首先,我们来看一下init-files 子命令。
这与初始化单节点时使用的 init 命令类似,但这里初始化的是多个节点,会为每个节点生成创世交易,并将这些交易收集起来。
init-files 子命令会初始化在独立进程中运行测试网络所需的文件(例如使用 Docker 容器)。运行此命令并不是执行 start 子命令的前置条件(见下文)。
要为测试网络初始化文件,请运行以下命令:
.testnets 目录。下面来看一下 .testnets 目录中创建的文件。
gentxs
gentxs 目录包含每个验证者节点的一笔创世交易。每个文件中都包含一个 JSON 编码的创世交易,用于在创世时注册对应的验证者节点。在初始化过程中,这些创世交易会被添加到每个节点目录中的 genesis.json 文件里。
nodes
系统会为每个验证者节点创建一个节点目录。每个节点目录中都包含一个simd 目录。simd 目录是每个节点的主目录,其中包含该节点的配置文件和数据文件(也就是运行单节点时默认 ~/.simapp 目录中包含的同类文件)。
启动测试网络
现在,我们来看一下start 子命令。
start 子命令会同时初始化并启动一个进程内测试网络。这是为了测试目的快速启动本地测试网络的最快方式。
你可以运行以下命令来启动本地测试网络:
--node 标志)。
检查第一个验证者节点的状态:
测试网络选项
你可以通过标志自定义测试网络的配置。如需查看所有标志选项,请在每个命令后附加--help 标志。
Synopsis
The
simd testnet subcommand makes it easy to initialize and start a simulated test network for testing purposes.simd binary also includes a testnet command that allows you to start a simulated test network in-process or to initialize files for a simulated test network that runs in a separate process.
Initialize Files
First, let’s take a look at theinit-files subcommand.
This is similar to the init command when initializing a single node, but in this case we are initializing multiple nodes, generating the genesis transactions for each node, and then collecting those transactions.
The init-files subcommand initializes the necessary files to run a test network in a separate process (i.e. using a Docker container). Running this command is not a prerequisite for the start subcommand (see below).
In order to initialize the files for a test network, run the following command:
.testnets directory. Let’s take a look at the files created within the .testnets directory.
gentxs
Thegentxs directory includes a genesis transaction for each validator node. Each file includes a JSON encoded genesis transaction used to register a validator node at the time of genesis. The genesis transactions are added to the genesis.json file within each node directory during the initialization process.
nodes
A node directory is created for each validator node. Within each node directory is asimd directory. The simd directory is the home directory for each node, which includes the configuration and data files for that node (i.e. the same files included in the default ~/.simapp directory when running a single node).
Start Testnet
Now, let’s take a look at thestart subcommand.
The start subcommand both initializes and starts an in-process test network. This is the fastest way to spin up a local test network for testing purposes.
You can start the local test network by running the following command:
--node flag).
Check the status of the first validator node:
Testnet Options
You can customize the configuration of the test network with flags. In order to see all flag options, append the--help flag to each command.