-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding tests for the Simple Auction smart contract. #532
Merged
stefan-stefanooov
merged 2 commits into
main
from
489-solidity-support-simple-auction-example
Nov 21, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
artifacts/contracts/solidity/simple-auction/SimpleAuction.sol/SimpleAuction.dbg.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"_format": "hh-sol-dbg-1", | ||
"buildInfo": "../../../../build-info/18a2f5e432afb04d112aa7797a8e064f.json" | ||
} |
183 changes: 183 additions & 0 deletions
183
artifacts/contracts/solidity/simple-auction/SimpleAuction.sol/SimpleAuction.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
{ | ||
"_format": "hh-sol-artifact-1", | ||
"contractName": "SimpleAuction", | ||
"sourceName": "contracts/solidity/simple-auction/SimpleAuction.sol", | ||
"abi": [ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "biddingTime", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "address payable", | ||
"name": "beneficiaryAddress", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "AuctionAlreadyEnded", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "AuctionEndAlreadyCalled", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "AuctionNotYetEnded", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "BidNotHighEnough", | ||
"type": "error" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "winner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "AuctionEnded", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "recepient", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "FundReturned", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "bidder", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "HighestBidIncreased", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "auctionEnd", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "auctionEndTime", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "beneficiary", | ||
"outputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "bid", | ||
"outputs": [], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "highestBid", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "highestBidder", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "withdraw", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
], | ||
"bytecode": "0x608060405234801561001057600080fd5b5060405161054438038061054483398101604081905261002f91610062565b610039824261009f565b600155600080546001600160a01b0319166001600160a01b0392909216919091179055506100c6565b6000806040838503121561007557600080fd5b825160208401519092506001600160a01b038116811461009457600080fd5b809150509250929050565b808201808211156100c057634e487b7160e01b600052601160045260246000fd5b92915050565b61046f806100d56000396000f3fe6080604052600436106100705760003560e01c80633ccfd60b1161004e5780633ccfd60b146100d15780634b449cba146100f657806391f901571461011a578063d57bde791461013a57600080fd5b80631998aeef146100755780632a24f46c1461007f57806338af3eed14610094575b600080fd5b61007d610150565b005b34801561008b57600080fd5b5061007d610297565b3480156100a057600080fd5b506000546100b4906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156100dd57600080fd5b506100e6610373565b60405190151581526020016100c8565b34801561010257600080fd5b5061010c60015481565b6040519081526020016100c8565b34801561012657600080fd5b506002546100b4906001600160a01b031681565b34801561014657600080fd5b5061010c60035481565b6001544211156101a75760405162461bcd60e51b815260206004820152601360248201527f41756374696f6e416c7265616479456e6465640000000000000000000000000060448201526064015b60405180910390fd5b34600354106101f85760405162461bcd60e51b815260206004820152601060248201527f4269644e6f7448696768456e6f75676800000000000000000000000000000000604482015260640161019e565b60035415610233576003546002546001600160a01b03166000908152600460205260408120805490919061022d908490610412565b90915550505b6002805473ffffffffffffffffffffffffffffffffffffffff1916339081179091553460038190556040805192835260208301919091527ff4757a49b326036464bec6fe419a4ae38c8a02ce3e68bf0809674f6aab8ad300910160405180910390a1565b6001544210156102ba5760405163044cee2960e41b815260040160405180910390fd5b60055460ff16156102de57604051630c39fb9f60e31b815260040160405180910390fd5b6005805460ff19166001179055600254600354604080516001600160a01b03909316835260208301919091527fdaec4582d5d9595688c8c98545fdd1c696d41c6aeaeb636737e84ed2f5c00eda910160405180910390a1600080546003546040516001600160a01b039092169281156108fc029290818181858888f19350505050158015610370573d6000803e3d6000fd5b50565b33600090815260046020526040812054801561040a57336000818152600460205260408082208290555183156108fc0291849190818181858888f1935050505061040a5733600081815260046020908152604091829020849055815192835282018390527ff0f0519cd10c4b06281b3bcd73769ee2071e9f11d6a5cfa92b565d51c5643083910160405180910390a1600091505090565b600191505090565b8082018082111561043357634e487b7160e01b600052601160045260246000fd5b9291505056fea2646970667358221220439d4d437409a51fb88c7adfffc36d1dc0b4c573bddb18345ee7d53f4a16eab164736f6c63430008140033", | ||
"deployedBytecode": "0x6080604052600436106100705760003560e01c80633ccfd60b1161004e5780633ccfd60b146100d15780634b449cba146100f657806391f901571461011a578063d57bde791461013a57600080fd5b80631998aeef146100755780632a24f46c1461007f57806338af3eed14610094575b600080fd5b61007d610150565b005b34801561008b57600080fd5b5061007d610297565b3480156100a057600080fd5b506000546100b4906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156100dd57600080fd5b506100e6610373565b60405190151581526020016100c8565b34801561010257600080fd5b5061010c60015481565b6040519081526020016100c8565b34801561012657600080fd5b506002546100b4906001600160a01b031681565b34801561014657600080fd5b5061010c60035481565b6001544211156101a75760405162461bcd60e51b815260206004820152601360248201527f41756374696f6e416c7265616479456e6465640000000000000000000000000060448201526064015b60405180910390fd5b34600354106101f85760405162461bcd60e51b815260206004820152601060248201527f4269644e6f7448696768456e6f75676800000000000000000000000000000000604482015260640161019e565b60035415610233576003546002546001600160a01b03166000908152600460205260408120805490919061022d908490610412565b90915550505b6002805473ffffffffffffffffffffffffffffffffffffffff1916339081179091553460038190556040805192835260208301919091527ff4757a49b326036464bec6fe419a4ae38c8a02ce3e68bf0809674f6aab8ad300910160405180910390a1565b6001544210156102ba5760405163044cee2960e41b815260040160405180910390fd5b60055460ff16156102de57604051630c39fb9f60e31b815260040160405180910390fd5b6005805460ff19166001179055600254600354604080516001600160a01b03909316835260208301919091527fdaec4582d5d9595688c8c98545fdd1c696d41c6aeaeb636737e84ed2f5c00eda910160405180910390a1600080546003546040516001600160a01b039092169281156108fc029290818181858888f19350505050158015610370573d6000803e3d6000fd5b50565b33600090815260046020526040812054801561040a57336000818152600460205260408082208290555183156108fc0291849190818181858888f1935050505061040a5733600081815260046020908152604091829020849055815192835282018390527ff0f0519cd10c4b06281b3bcd73769ee2071e9f11d6a5cfa92b565d51c5643083910160405180910390a1600091505090565b600191505090565b8082018082111561043357634e487b7160e01b600052601160045260246000fd5b9291505056fea2646970667358221220439d4d437409a51fb88c7adfffc36d1dc0b4c573bddb18345ee7d53f4a16eab164736f6c63430008140033", | ||
"linkReferences": {}, | ||
"deployedLinkReferences": {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract SimpleAuction { | ||
address payable public beneficiary; | ||
uint public auctionEndTime; | ||
address public highestBidder; | ||
uint public highestBid; | ||
|
||
mapping(address => uint) pendingReturns; | ||
bool ended; | ||
|
||
event HighestBidIncreased(address bidder, uint amount); | ||
event AuctionEnded(address winner, uint amount); | ||
event FundReturned(address recepient, uint amount); | ||
|
||
/// The auction has already ended. | ||
error AuctionAlreadyEnded(); | ||
/// There is already a higher or equal bid. | ||
error BidNotHighEnough(); | ||
/// The auction has not ended yet. | ||
error AuctionNotYetEnded(); | ||
/// The function auctionEnd has already been called. | ||
error AuctionEndAlreadyCalled(); | ||
|
||
constructor( | ||
uint biddingTime, | ||
address payable beneficiaryAddress | ||
) { | ||
auctionEndTime = block.timestamp + biddingTime; | ||
beneficiary = beneficiaryAddress; | ||
} | ||
|
||
function bid() external payable { | ||
if (block.timestamp > auctionEndTime) | ||
revert('AuctionAlreadyEnded'); | ||
|
||
if (highestBid >= msg.value) | ||
revert('BidNotHighEnough'); | ||
|
||
if (highestBid != 0) { | ||
pendingReturns[highestBidder] += highestBid; | ||
} | ||
|
||
highestBidder = msg.sender; | ||
highestBid = msg.value; | ||
emit HighestBidIncreased(msg.sender, msg.value); | ||
} | ||
|
||
/// Withdraw a bid that was overbid. | ||
function withdraw() external returns (bool) { | ||
uint amount = pendingReturns[msg.sender]; | ||
if (amount > 0) { | ||
pendingReturns[msg.sender] = 0; | ||
if (!payable(msg.sender).send(amount)) { | ||
pendingReturns[msg.sender] = amount; | ||
emit FundReturned(msg.sender, amount); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/// End the auction and send the highest bid | ||
/// to the beneficiary. | ||
function auctionEnd() external { | ||
if (block.timestamp < auctionEndTime) | ||
revert AuctionNotYetEnded(); | ||
if (ended) | ||
revert AuctionEndAlreadyCalled(); | ||
|
||
ended = true; | ||
emit AuctionEnded(highestBidder, highestBid); | ||
|
||
beneficiary.transfer(highestBid); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,4 +76,3 @@ module.exports = { | |
}, | ||
}, | ||
} | ||
|
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check this file in