Closed vird closed 3 years ago
pragma solidity ^0.4.16;
contract Ballot {
struct Voter {
uint256 weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted
address delegate; // person delegated to
uint256 vote; // index of the voted proposal
}
struct Proposal {
bytes32 name; // short name (up to 32 bytes)
uint256 voteCount; // number of accumulated votes
}
address public chairperson;
mapping(address => Voter) public voters;
Proposal[] public proposals;
function Ballot(bytes32[] proposalNames) public {
chairperson = msg.sender;
voters[chairperson].weight = 1;
for (uint256 i = 0; i < proposalNames.length; i++) {
proposals.push(Proposal({name: proposalNames[i], voteCount: 0}));
}
}
function giveRightToVote(address v) public {
require(
(msg.sender == chairperson) &&
!voters[v].voted &&
(voters[v].weight == 0)
);
voters[v].weight = 1;
}
function delegate(address to) public {
Voter storage sender = voters[msg.sender];
require(!sender.voted);
require(to != msg.sender);
while (voters[to].delegate != address(0)) {
to = voters[to].delegate;
require(to != msg.sender);
}
sender.voted = true;
sender.delegate = to;
Voter storage delegate_ = voters[to];
if (delegate_.voted) {
proposals[delegate_.vote].voteCount += sender.weight;
} else {
delegate_.weight += sender.weight;
}
}
function vote(uint256 proposal) public {
Voter storage sender = voters[msg.sender];
require(!sender.voted);
sender.voted = true;
sender.vote = proposal;
proposals[proposal].voteCount += sender.weight;
}
function winningProposal() public view returns (uint256 winningProposal_) {
uint256 winningVoteCount = 0;
for (uint256 p = 0; p < proposals.length; p++) {
if (proposals[p].voteCount > winningVoteCount) {
winningVoteCount = proposals[p].voteCount;
winningProposal_ = p;
}
}
}
function winnerName() public view returns (bytes32 winnerName_) {
winnerName_ = proposals[winningProposal()].name;
}
}
bad test samples
pragma solidity ^0.4.21;
contract Test {
struct Swap {
uint256 value;
}
function test() public {
Swap memory b = Swap(0);
}
}
Translates, but const b : test_Swap = record [ value = 0 ];
, expected 0n
instead of 0
pragma solidity ^0.4.21;
contract Test {
struct Swap {
uint256 value;
}
function test() public {
var b = Swap(0);
}
}
Error: unpack_id_type unknown typeString 'struct Test.Swap memory'
pragma solidity ^0.4.21;
contract Swap {
uint256 value;
}
contract Test {
function test() public {
var b = new Swap();
}
}
Error: unpack_id_type unknown typeString 'contract Swap'
ternary bad example
pragma solidity ^0.4.21;
contract Test {
function test() public {
var a = true?1:0; // first example
uint b = a + 0;
uint c = true?1:0; // second example
}
}
const a : nat = (case True of | True -> 1 | False -> 0 end);
expected
const a : nat = (case True of | True -> 1n | False -> 0n end);
See #133
uint b = a?1:0;
Should be ok for ternaryShould be ok for new