Solidity

Truffle 測試:如何測試 Ether 轉移?具體賬戶餘額?

  • April 24, 2020

如何測試我的合約是否真的將資金轉移到特定賬戶?

function _transfer(address receiver_, uint256 payout) internal{
   receiver_.transfer(payout);
}

用 JavaScript 語法測試。期待類似的東西:

assert.equal(accounts[1].balance, 100 Ether);

要斷言帳戶餘額,請嘗試以下操作:

let expectedBalance = web3.toBigNumber(web3.toWei(3, 'ether'));
let actualBalance = await web3.eth.getBalance(accounts[1]);

assert.deepEqual(actualBalance, expectedBalance, "Balance incorrect!");

引用自:https://ethereum.stackexchange.com/questions/52073