Truffle 测试 msg.value 向合约发送以太币时为零

Truffle test msg.value is zero when sending ether to contract

我真的觉得缺少一些非常基本的东西,但我无法弄清楚为什么在将以太币发送到合约功能时我的松露测试失败了。我的测试代码如下:

it('Test execute funds deposit', async function () {
    await fundsDepositServiceInstance.depositEther(
        accountAddr, accountNo, {from:accounts[0], value: 100, gas: 4712388});
});

我的solidity代码如下:

function depositEther(address _accountAddr, bytes32 _accountNo) external payable {
    require(msg.value < 1, "Insufficient funds to complete transaction");
}

运行 Ubuntu 18.04.1 LTS 上的 Truffle v4.1.14、Ganache v1.2.2 还原代码始终处于激活状态,我的测试失败了。如果这是我这边的一些基本错误,我深表歉意。提前谢谢你。

您的 require 语句需要 msg.value < 1 而您调用 depositEthervalue 为 100。因此您的代码正在执行预期的操作,您的测试应该失败。