Created
October 25, 2019 14:56
-
-
Save dg1an3/ddb5cece81b0fe09d97c1fe143b6dbe1 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.5.12+commit.7709ece9.js&optimize=false&gist=
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
pragma solidity ^0.5.12; | |
contract PhotoContestContract { | |
bytes32 _name; | |
address _owner; | |
bytes32[] _ipfsPhotoHashes; | |
address payable[] _submissionAddresses; | |
constructor(bytes32 name) public { | |
_owner = msg.sender; | |
_name = name; | |
} | |
function submit(bytes32 photoHash) public { | |
_submissionAddresses.push(msg.sender); | |
_ipfsPhotoHashes.push(photoHash); | |
} | |
function getSubmissions() public view returns (bytes32[] memory) { | |
return _ipfsPhotoHashes; | |
} | |
function selectWinner(bytes32 photoHash) public { | |
require(msg.sender == _owner, "You are not the owner."); | |
for (uint n = 0; n < _ipfsPhotoHashes.length; n++) { | |
if (_ipfsPhotoHashes[n] == photoHash) { | |
address payable winner = _submissionAddresses[n]; | |
// send eth to winner address | |
winner.transfer(address(this).balance); | |
} | |
} | |
} | |
} |
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
pragma solidity >=0.4.22 <0.6.0; | |
import "remix_tests.sol"; // this import is automatically injected by Remix. | |
import "./ballot.sol"; | |
contract test3 { | |
Ballot ballotToTest; | |
function beforeAll () public { | |
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 view returns (bool) { | |
return ballotToTest.winningProposal() == 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment