Home > Blockchain >  How can I pass through the it(...).then() function in unit test of solidity
How can I pass through the it(...).then() function in unit test of solidity

Time:01-10

I have been learning solidity about a few days ago. It is very easy and interesting, but it has a lot of problems which can't solve myself. This is one of such problems. In a source code of a unit test of some contract, I found the it(...).then() function.

var DAppToken = artifacts.require("./DAppToken.sol");

contract("DAppToken",  (accounts) => {
    it("transfers taken ownership", async () => {
        const dappTokenInstance = await DAppToken.deployed();
        return await dappTokenInstance.transfer.call(accounts[1], 99999999999999999999999999999);
    }).then(assert.fail).catch((error) => {
        assert( error.message.indexOf("revert") >= 0, "error message must contain revert");
    });
});

It was not executed as I expected. I got the following errors.

TypeError: it(...).then is not a function

I am not sure about this error.

How could I help me?

CodePudding user response:

.then should not come after it. it must be appended to the returned promise.

it("transfers taken ownership", async () => {
        const dappTokenInstance = await DAppToken.deployed();
        return await dappTokenInstance.transfer.call(accounts[1], 99999999999999999999999999999)
       .then(assert.fail).catch((error) => {
          assert( error.message.indexOf("revert") >= 0, "error message must contain revert");
    });
});

In this case, .then is used after await to catch the error. It is kinda try/catch

  •  Tags:  
  • Related