Sei中文文档(Sei Docs CHN)-by Chainguys
  • 导览(INTRODUCTION)
    • 版权声明(Copyright Notice)
    • 概览 (Overview)
    • Sei 设计空间 (Sei Design Space)
    • DEX 优化 (DEX Optimizations)
    • Sei 生态系统 (Sei Ecosystem)
  • 智能合约和本地开发 (Smart contracts & local development)
    • Sei工具指南 (Sei Tool Guide)
    • 设置一个本地节点 (Set up a local network)
    • 本地 Sei 脚本部署 (Local Sei script deployment)
    • Sei.go
    • CosmWasm合约测试 (CosmWasm Contract Testing)
    • 部署通用合约 (Deploy a generic contract)
    • 部署交易合约 (Deploy an exchange contract)
    • 非完整节点下部署和开发 (Deploy & develop without Full Node)
    • Dex 模块教程 (Dex Module Tutorial)
    • 代币工厂模块教程 (Tokenfactory Module Tutorial)
    • IBC转账 (IBC Transfers)
  • 订单匹配(order match)
    • 并行性 (Parallelism)
    • 资格 (Eligibility)
    • DEX 合约间依赖 (DEX Inter—Contract Dependencies)
    • 白名单商店 (Whitelisted Store)
  • 节点&验证者 (NODES&VALIDATORS)
    • 加入测试网 (Joining Testnets)
    • 更新 (Upgrades)
    • Seinami激励测试网 (Seinami Incentivized Testnet)
      • 加入激励测试网 (Joining Incentivized Testnet)
      • 所有测试任务 (All Testnet Missions)
      • 行为准则 (Code of Conduct)
      • 奖励发放详情 (Rewards Distribution Details)
  • 基础API端点 (Basic API Endpoints)
  • 模块化端点 (Module Endpoints)
  • 状态同步 (Statesync)
  • 恢复操作(Recovery Operations)
  • 治理(GOVERNANCE)
    • 创建提案 (Creating Proposals)
    • 管理质押 (Managing Staking)
    • 对提案投票表决 (Voting on Proposals)
  • 预言机(ORACLE)
    • 预言机参与 (Oracle Participation)
  • 钱包(WALLETS)
    • 钱包集成(Wallet Integration)
    • 转账 (Transfers)
  • 更多(More)
    • 推特(Twitter)
由 GitBook 提供支持
在本页
  • 单元测试 (Unit Testing)
  • 集成测试 (Integration Testing)
  • 使用 Sei 链进行端到端测试 (End-to-end testing with Sei chain)
  1. 智能合约和本地开发 (Smart contracts & local development)

CosmWasm合约测试 (CosmWasm Contract Testing)

上一页Sei.go下一页部署通用合约 (Deploy a generic contract)

最后更新于2年前

单元测试 (Unit Testing)

To make tests, specify:

要测试,要明确:

#[cfg(test)]

mod tests { ...

}

To run tests: cargo test

运行测试:cargo test

Cosmwasm Reference:

Cosmwasm 参考:

Example of a basic contract and tests:

基本合约和测试示例:[https://github.com/InterWasm/cw-contracts/blob/main/contracts/simple-option/src/contract.rs](https://github.com/InterWasm/ cw-contracts/blob/main/contracts/simple-option/src/contract.rs)

集成测试 (Integration Testing)

The cw-multi-test () package allows for integration tests.

cw-multi-test ()包允许集成测试。

We can do the following steps: 我们可以执行以下步骤:

  1. Initiate the testing setup, which may look like the following, where we use instantiate_contract()and then can use execute_contract() accordingly: 启动测试设置,可能如下所示,我们使用 instantiate_contract(),然后可以相应地使用 execute_contract():

fn setup_test(
    app: &mut App<
        BankKeeper,
        MockApi,
        MockStorage,
        SeiModule,
        WasmKeeper<SeiMsg, SeiQueryWrapper>,
        FailingStaking,
        FailingDistribution,
    >,
) -> (Addr, Addr) {
    let example_contract_code = app.store_code(Box::new(
        ContractWrapper::new(
            example_crate::contract::execute,
            example_crate::contract::instantiate,
            example_crate::contract::query,
        )
        .with_reply(example_crate::contract::reply),
    ));

    let example_contract_addr = app
        .instantiate_contract(
            example_contract_code,
            Addr::unchecked(ADMIN),
            &example_crate::msg::InstantiateMsg {
                example_param: Uint64::new(100),
            },
            &[],
            "example",
            Some(ADMIN.to_string()),
        )
        .unwrap();

    app.execute_contract(
        Addr::unchecked(ADMIN),
        example_contract_addr.clone(),
        &ExampleExecuteMsg::ExampleCall {
            asset_denom: "usei".to_string(),
        },
        &[],
    )
    .unwrap();

    example_contract_addr
}

使用 Sei 链进行端到端测试 (End-to-end testing with Sei chain)

For debugging, such as if an order is unsuccessful, one can use a combination of tools on the contract side. Firstly, the Rust compiler can catch issues at compile time. Secondly, for any struct that implements the Debug trait then println! can be used. Lastly, logs can be added via deps.api.debug(err) on the contract side.

对于调试,如果订单不成功,可以使用合约端的工具组合。首先,Rust 编译器可以在编译时发现问题。其次,对于任何实现了 Debug 特性的 struct,都可以使用 println!。最后,可以通过合约端的 deps.api.debug(err) 添加日志。

Cosmwasm reference:

Cosmwasm 参考:

In order to do end-to-end testing, follow the previous steps to 1) launch the chain either locally or on devnet: , and 2) deploy your contract: . For an example contract that can be used for local testing see the following:

为了进行端到端测试,请按照前面的步骤 1) 在本地或 devnet 上启动链:,以及 2) 部署你的合约:[https: //docs.seinetwork.io/smart-contracts-and-local-development/deploy-a-generic-contract](https://docs.seinetwork.io/smart-contracts-and-local-development/deploy-a -通用合同)。有关可用于本地测试的示例合约,请参见以下内容:

https://docs.cosmwasm.com/tutorials/simple-option/testing/
https://docs.cosmwasm.com/tutorials/simple-option/testing/
https://github.com/InterWasm/cw-contracts/blob/main/contracts/simple-option/src/contract.rs
https://docs.rs/cw-multi-test/latest/cw_multi_test/
https://docs.rs/cw-multi-test/latest/cw_multi_test/
https://docs.cosmwasm.com/docs/1.0/smart-contracts/testing/
https://docs.cosmwasm.com/docs/1.0/smart-contracts/testing/
https://docs.seinetwork.io/smart-contracts-and-local-development/set-up-a-local-network
https://docs.seinetwork.io/smart-contracts-and-local-development/deploy-a-generic-contract
https://github.com/sei-protocol/sei-cosmwasm
https://docs.seinetwork.io/smart-contracts-and-local-development/set- up-a-local-network
https://github.com/sei-protocol/sei-cosmwasm