簡體   English   中英

使用 nodejs 進行智能合約測試失敗並顯示錯誤消息

[英]Smart Contract test with nodejs fails with an error message

我正在嘗試測試智能合約並想做以下測試。

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

我轉移的價值實際上大於所有者的余額。 但不是通過測試失敗並出現以下錯誤。

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

我在這里做錯了什么?

您必須更改等待的 position,將其放在預期之外。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM