简体   繁体   中英

Smart Contract test with nodejs fails with an error message

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?

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))                
            })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM