and am trying to write some test for a payable function in Solidity but i don't know how to go about it any help will be appreciated . I want to test for the case where the buyer send an amount less of the item price . should i just check if the state of the item hasn't changed or is there a way to check if the modifier didn't "Pass"
modifier checkValue(uint _sku) {
_;
uint _price = items[_sku].price;
uint amountToRefund = msg.value - _price;
items[_sku].buyer.transfer(amountToRefund);
}
modifier paidEnough(uint _price) {require(msg.value >= _price);_;}
function buyItem(uint _sku) forSale (_sku) checkValue(_sku) paidEnough(items[_sku].price) public payable
{
items[_sku].buyer = msg.sender;
items[_sku].seller.transfer(items[_sku].price);
items[_sku].state = State.Sold;
emit Sold(_sku);
}
call()methods (solidity) will returnfalsein the case that the called contract throws an exception. You might assert that this is the case. Warning: https://ethereum.stackexchange.com/questions/8270/what-does-soliditys-call-function-mean – Rob Hitchens Dec 04 '18 at 23:47