Smart Contract test with nodejs fails with an error message

Viewed 23

I am trying to test a smart contract and want to do the following test.

it('Transfer tokens from owner should fail if owner has a low balance.', async () => {
                expect(await ptrTokenContract.transfer(receiverAddress1.address, 10000000)).to.be.revertedWith('Insufficient balance.Transfer failed !')
                console.log(await ptrTokenContract.balanceOf(receiverAddress1.address))                
            })

the value I am transferring is actrually greater than the owner's balance. But instead of passing the test fails with following error.

 Error: VM Exception while processing transaction: reverted with reason string 'Insufficient balance.Transfer failed !'
at Token.transfer (contracts/Token.sol:59)

what am I doing wrong here?

1 Answers

You have to change the position of the await, put it outside of the expect.

it('Transfer tokens from owner should fail if owner has a low balance.', async () => {
                await expect(ptrTokenContract.transfer(receiverAddress1.address, 10000000)).to.be.revertedWith('Insufficient balance.Transfer failed !')
                console.log(await ptrTokenContract.balanceOf(receiverAddress1.address))                
            })
Related