摩卡合约测试错误:Done在挂钩中多次调用

问题描述

嗨,我是智能合约领域的新手,并且我遇到了与摩卡有关的问题。这是我正在从事的测试:

-EDIT-

const UsersContract = artifacts.require("../contracts/UsersContract.sol");

contract("TestUsersContract",async accounts => {
    let instance;

    beforeEach('setup contract for each test',async () => {
        instance = await UsersContract.deployed();
    });

    it('should retrieve User',async () => {
        instance.join(1,"John Doe");
        instance.send({ from: accounts[0],gas: 50000 });

        let user = await instance.getUser(accounts[0]);
        assert.equal(user[0].toNumber(),1);
        assert.equal(user[1],'John Doe');
    });
});

这引发了以下错误

    1) Uncaught Error: the string "abort(Error: Given input \"[object Object]\" is not a number.). Build with -s ASSERTIONS=1 for more info." was thrown,throw an Error :)
    2) Error: done() called multiple times in hook

我不知道为什么,但是当我将测试重构为非异步版本时:

it('should retrieve User',() => {
    instance.join(1,"John Doe");
    instance.send({ from: accounts[0],gas: 50000 });

    instance.getUser(accounts[0]).then( user => {
        assert.equal(user[0].toNumber(),'John Doe');
    });
});

一切顺利,测试按预期进行。为什么会这样呢?可以在这里完成async/await版本吗?还是我必须始终坚持使用.then()版本?

有点启发是很好的,谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)