Created
October 26, 2018 13:46
-
-
Save TiuTalk/dd77dd830cee9316e61754d50b597053 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=true&gist=
This file contains hidden or 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
pragma solidity ^0.4.17; | |
contract Lottery { | |
address public manager; | |
address[] public players; | |
uint minEntry = .01 ether; | |
uint managerFee = .01 ether; | |
constructor() public { | |
manager = msg.sender; | |
} | |
modifier restricted() { | |
require(msg.sender == manager, "You're not the manager!"); | |
_; | |
} | |
function enter() public payable { | |
require(msg.value > minEntry, "The minimum entry is .01 ETH"); | |
players.push(msg.sender); | |
} | |
function pickWinner() public restricted { | |
require(players.length > 1, "Not enough players!"); | |
require(address(this).balance > 0, "There is no prize to distribute"); | |
uint winnerIndex = _random(players.length); | |
address winner = players[winnerIndex]; | |
// Reset the players list | |
players = new address[](0); | |
// Calculate & transfer the prize | |
manager.transfer(managerFee); | |
winner.transfer(address(this).balance); | |
} | |
function _random(uint limit) private view returns (uint) { | |
assert(limit > 0); | |
bytes memory input = abi.encodePacked(block.difficulty, now, players); | |
return uint(keccak256(input)) % limit; | |
} | |
} |
This file contains hidden or 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
pragma solidity ^0.4.7; | |
import "remix_tests.sol"; // this import is automatically injected by Remix. | |
import "./ballot.sol"; | |
contract test3 { | |
Ballot ballotToTest; | |
function beforeAll () { | |
ballotToTest = new Ballot(2); | |
} | |
function checkWinningProposal () public { | |
ballotToTest.vote(1); | |
Assert.equal(ballotToTest.winningProposal(), uint(1), "1 should be the winning proposal"); | |
} | |
function checkWinninProposalWithReturnValue () public constant returns (bool) { | |
return ballotToTest.winningProposal() == 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment