首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elrond mandos测试elrond_wasm_debug::mandos_rs通过但是erdpy合同测试失败

Elrond mandos测试elrond_wasm_debug::mandos_rs通过但是erdpy合同测试失败
EN

Stack Overflow用户
提问于 2022-03-06 06:47:15
回答 1查看 122关注 0票数 3

我正在为我的NFT智能合同(SC)编写测试用例。当我在创建NFT之后检查SC的状态时,我希望看到一个变量(next_index_to_mint:u64,也就是我每增加一个新的NFT)来更新。

因此,我使用以下命令运行测试:

代码语言:javascript
复制
$ erdpy contract test
INFO:projects.core:run_tests.project: /Users/<user>/sc_nft
INFO:myprocess:run_process: ['/Users/<user>/elrondsdk/vmtools/mandos-test', '/Users/<user>/sc_nft/mandos'], in folder: None
CRITICAL:cli:External process error:
Command line: ['/Users/<user>/elrondsdk/vmtools/mandos-test', '/Users/<user>/sc_nft/mandos']
Output: Scenario: buy_nft.scen.json ...   FAIL: wrong account storage for account "sc:nft-minter":
  for key 0x6e657874496e646578546f4d696e74 (str:nextIndexToMint): Want: "0x02". Have: ""
Scenario: create_nft.scen.json ...   FAIL: wrong account storage for account "sc:nft-minter":
  for key 0x6e657874496e646578546f4d696e74 (str:nextIndexToMint): Want: "0x02". Have: ""
Scenario: init.scen.json ...   ok
Done. Passed: 1. Failed: 2. Skipped: 0.
ERROR: some tests failed

但是,当我使用elrond_wasm_debug::mandos_rs函数和create_nft.scen.json文件运行测试时,它通过了。

代码语言:javascript
复制
use elrond_wasm_debug::*;

fn world() -> BlockchainMock {
    let mut blockchain = BlockchainMock::new();
    blockchain.set_current_dir_from_workspace("");

    blockchain.register_contract_builder("file:output/test.wasm", nft_auth_card::ContractBuilder);
    blockchain
}

#[test]
fn create_nft() {
    elrond_wasm_debug::mandos_rs("mandos/create_nft.scen.json", world());
}

顺便说一句,如果您想将它添加到NFT示例中,这在tests/文件夹中将是很棒的。

我试着放一个不正确的值,结果如预期的那样失败了。因此,我的问题是,如何使用mandos elrond_wasm调试而不使用erdpy工作呢?

代码语言:javascript
复制
running 1 test
thread 'create_nft' panicked at 'bad storage value. Address: sc:nft-minter. Key: str:nextIndexToMint. Want: "0x04". Have: 0x02', /Users/<user>/elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-wasm-debug-0.28.0/src/mandos_step/check_state.rs:56:21

下面是代码(我使用默认的NFT 示例):

代码语言:javascript
复制
const NFT_INDEX: u64 = 0;
fn create_nft_with_attributes<T: TopEncode>(...) -> u64 {
    ...
    self.next_index_to_mint().set_if_empty(&NFT_INDEX);
    let next_index_to_mint = self.next_index_to_mint().get();
    self.next_index_to_mint().set(next_index_to_mint+1);
    ...
}

#[storage_mapper("nextIndexToMint")]
fn next_index_to_mint(&self) -> SingleValueMapper<u64>;
EN

回答 1

Stack Overflow用户

发布于 2022-05-16 10:53:08

简短回答:很可能在用erdpy测试之前,您还没有重新构建您的合同。

Long答案:目前执行mandos测试的方法有两种,在您的案例中已经说明了这一点:

  • 通过mandos_rs直接从锈病中运行测试
  • 通过erdpy运行测试(这反过来使用mandos_go)

这两个框架(mandos_rs和mandos_go)以不同的方式运行:

  • mandos_rs:这个框架直接运行在您的rust code上,并在后台对模拟的VM和模拟的块链进行测试。因此,在使用mandos_rs时没有必要构建您的契约。
  • mandos_go:这个框架是在一个实际的VM上测试你的compiled contract,在后台有一个模拟的块链,所以在通过mandos_go运行测试之前,有必要将您的最新更改构建到.wasm字节码(例如erdpy contract build)中,因为这个编译的文件将由VM在实际使用场景中加载。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71368221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档