0

I have a simple test to mint tokens on a newly deployed contract.

While developing, I was testing locally and the test never failed. Now that the contract is deployed to the testnet, I get a 50% failure rate in my test.

I can check the contract on Snowtrace and see that the mint function was executed properly.

My question is why are the await's not being obeyed?

See the test in question:

it("should allow owner to mint tokens", async function () {
    await contract.deployed();
    await expect(() => contract.mint(bobAddress, fiveHundred))
    .to.changeTokenBalance(contract, bob, (500 * (10 ** (decimals))).toString());
  });

2 Answers 2

1

I truly think you should run the mint function first then use the wait method to wait for the transaction to succeed then use "expect" to check "bobAddress" has the fiveHundred amount in its balance :>

    await (await contract.mint(bobAddress, fiveHundred)).wait();

1
  • 1
    Very much appreciated. It's irrational to think you need to use wait() at the end of 2(!) await's
    – Adam
    Commented Mar 14, 2022 at 20:32
1

I ran into this as well. the solution is to wait for the value to update.

Since I work in Python, you'll need to translate this to JavaScript...

while contract.owner() != bob: # assuming bob is the owner.
    time.sleep(1)

contract.mint(etc, etc)

I'm pretty sure our development environments are interacting with the contracts before they are actually ready even if we do use async.

3
  • With a delay or a .then() or .done()? What was your approach?
    – Adam
    Commented Mar 13, 2022 at 20:45
  • updating my answer
    – ctnava
    Commented Mar 14, 2022 at 4:06
  • Thank you for the feedback. You saved me hours of frustration!
    – Adam
    Commented Mar 14, 2022 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.