Skip to content

Instantly share code, notes, and snippets.

@dougiebuckets
Created September 10, 2018 21:33
Show Gist options
  • Save dougiebuckets/b526244bba26e2ba2b3a122a584942fc to your computer and use it in GitHub Desktop.
Save dougiebuckets/b526244bba26e2ba2b3a122a584942fc to your computer and use it in GitHub Desktop.
A simple guide for how to write unit tests for smart contracts - Example Function
/// @dev The first one to provide a bid at the currentAskingPrice is awarded the beneficiary's NFT
/// @dev If a bidder overbids on the NFT they will win the auction and their overage will be returned
function processBid()
public
payable
atStage(Stages.AuctionStarted)
validBid()
returns (uint)
{
bid = msg.value;
bidder = msg.sender;
getCurrentAskingPrice();
if (bid > currentAskingPrice) {
overage = bid.sub(currentAskingPrice);
bidder.transfer(overage);
bid = currentAskingPrice;
stage = Stages.AuctionEnded;
payBeneficiary();
sendToBidder();
} else if (bid == currentAskingPrice) {
stage = Stages.AuctionEnded;
payBeneficiary();
sendToBidder();
} else {
revert("Bid is lower than currentAskingPrice");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment