我正在为我的NFT智能合同(SC)编写测试用例。当我在创建NFT之后检查SC的状态时,我希望看到一个变量(next_index_to_mint:u64,也就是我每增加一个新的NFT)来更新。
因此,我使用以下命令运行测试:
$ 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文件运行测试时,它通过了。
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工作呢?
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 示例):
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>;发布于 2022-05-16 10:53:08
简短回答:很可能在用erdpy测试之前,您还没有重新构建您的合同。
Long答案:目前执行mandos测试的方法有两种,在您的案例中已经说明了这一点:
这两个框架(mandos_rs和mandos_go)以不同的方式运行:
rust code上,并在后台对模拟的VM和模拟的块链进行测试。因此,在使用mandos_rs时没有必要构建您的契约。compiled contract,在后台有一个模拟的块链,所以在通过mandos_go运行测试之前,有必要将您的最新更改构建到.wasm字节码(例如erdpy contract build)中,因为这个编译的文件将由VM在实际使用场景中加载。https://stackoverflow.com/questions/71368221
复制相似问题