Question:

Comparing msg.value using javascript test always fails

Lucas: 2 weeks ago

So I have this solidity function:

function claimGoodTest(uint256 typeId) public payable {
    if (msg.value < 4000) revert();
}

I test it with the following:

var result = await contract.claimGoodTest(typeId, {
    from: accounts[0], value: web3.utils.toWei('40', 'ether')
}, function(result) { })

I get this :

Error: VM Exception while processing transaction: revert

Why is this happening ? This seems like a bug or I have the wrong syntax.

Answer:
Mia: 2 weeks ago

Oh! I just had to switch the order of the test parameters. The object with value should be the very last param. The callback needed to be the second to last. This is not documented well.

var result = await contract.claimGoodTest( typeId , function(){} ,{ value:web3utils.toWei('0.00001','ether') })