sui-build

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Building Packages

构建包

MCP tool: When available in your environment, also query the Sui documentation MCP server (
https://sui.mcp.kapa.ai
) for up-to-date answers. Use it for verification and for details not covered by these reference files.
Source constraint: All information sourced exclusively from docs.sui.io and move-book.com.
MCP工具: 如果你的环境中可用,也可以查询Sui文档MCP服务器(
https://sui.mcp.kapa.ai
)获取最新答案。用它来验证信息,以及获取这些参考文件未涵盖的细节。
来源限制: 所有信息均来自docs.sui.iomove-book.com

Building

构建

bash
sui move build
This compiles all modules, validates types, enforces resource safety, and produces bytecode. Fix any errors before proceeding.
For the canonical hello-world repository, run build commands from
sui-stack-hello-world/move/hello-world
.
bash
sui move build
该命令会编译所有模块、验证类型、强制执行资源安全性并生成字节码。继续操作前请修复所有错误。
对于标准的hello-world仓库,请在
sui-stack-hello-world/move/hello-world
目录下运行构建命令。

--build-env
flag

--build-env
参数

When a package has an
[environments]
section in
Move.toml
with multiple networks, use
--build-env
to target a specific environment:
bash
sui move build --build-env testnet
sui move build --build-env mainnet
This resolves dependencies and package addresses for the specified environment. Without
--build-env
, the build uses the default environment or may fail with "Could not determine the correct dependencies" if multiple environments are defined and no default is set.
The
--build-env
flag also applies to
sui move test
:
bash
sui move test --build-env testnet
如果包的
Move.toml
文件中有
[environments]
部分定义了多个网络,请使用
--build-env
指定目标环境:
bash
sui move build --build-env testnet
sui move build --build-env mainnet
这会解析指定环境的依赖项和包地址。如果没有
--build-env
,构建会使用默认环境;如果定义了多个环境且未设置默认值,可能会失败并提示“无法确定正确的依赖项”。
--build-env
参数同样适用于
sui move test
bash
sui move test --build-env testnet

Testing

测试

bash
sui move test
bash
sui move test

Key testing modules

核心测试模块

  • sui::test_scenario
    — Multi-transaction, multi-sender test scenarios. Simulates realistic transaction flows with
    begin
    ,
    next_tx
    , and
    end
    .
  • std::unit_test
    — Assertion macros for unit tests (
    assert_eq!
    ,
    assert_ne!
    ).
  • sui::test_scenario
    — 支持多交易、多发送者的测试场景。通过
    begin
    next_tx
    end
    模拟真实的交易流程。
  • std::unit_test
    — 用于单元测试的断言宏(
    assert_eq!
    assert_ne!
    )。

Code coverage

代码覆盖率

Track which lines your tests exercise:
bash
sui move test --coverage
View coverage results for a specific module:
bash
sui move coverage source --module <name>
跟踪测试用例覆盖的代码行:
bash
sui move test --coverage
查看特定模块的覆盖率结果:
bash
sui move coverage source --module <name>

Move Analyzer

Move Analyzer

Install via suiup:
bash
suiup install move-analyzer
Then install the Move Analyzer extension in VS Code. It provides code completion, go-to-definition, inline diagnostics, and hover documentation. It activates automatically for
.move
files — no additional configuration needed.
通过suiup安装:
bash
suiup install move-analyzer
然后在VS Code中安装Move Analyzer扩展。它提供代码补全、跳转到定义、内联诊断和悬停文档功能。对于
.move
文件会自动激活,无需额外配置。

Debugging

调试

  • Move Trace Debugger: Step-through debugger for Move execution traces with variable inspection.
  • sui replay
    :
    Locally re-execute any past onchain transaction and compare effects. Useful for diagnosing production issues.
  • std::debug::print
    :
    Print values during test execution.
  • Move Trace Debugger: 用于Move执行轨迹的单步调试器,支持变量检查。
  • sui replay
    本地重新执行任何已上链的过往交易并对比效果。适用于诊断生产环境问题。
  • std::debug::print
    在测试执行过程中打印值。