Created
September 10, 2018 21:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @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