Skip to content

Commit

Permalink
Added tests to contract
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelaazevedo committed Jun 18, 2021
1 parent 1c79f78 commit d3887bd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions test/TestVoting.sol
@@ -0,0 +1,43 @@
pragma solidity >=0.4.22 <0.8.0;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Voting.sol";

contract TestVoting {
Voting voting = Voting(DeployedAddresses.Voting());

uint256 expectedLocationId = 8;

address expectedVotedLocation = address(this);

function testUserCanVoteLocation() public {
uint256 returnedId = voting.vote(expectedLocationId);

Assert.equal(
returnedId,
expectedLocationId,
"User was able to vote for the expected location and expectedVotedLocation should match what is returned."
);
}

function testGetVotedLocationAddressByLocationId() public {
address location = voting.locations(expectedLocationId);

Assert.equal(
location,
expectedVotedLocation,
"Voted Location of the expected location should be this contract"
);
}

function testGetVotedLocationAddressByLocationIdInArray() public {
address[16] memory locations = voting.getLocations();

Assert.equal(
locations[expectedLocationId],
expectedVotedLocation,
"Voted location of the expected location should be this contract"
);
}
}

0 comments on commit d3887bd

Please sign in to comment.