Commit 0288fd21356a15c8f3f95a9f431bc370405ac46c
Beginnings of voting
Joran committed on 1/12/2017, 12:44:32 AMParent: 8c8b7da9dc43699fc6a0d49a9c8ba2ccf4075672
Files changed
contracts/Entropy.sol | changed |
migrations/2_deploy_contracts.js | changed |
test/Entropy_actions.js | changed |
contracts/Entropy.sol | ||
---|---|---|
@@ -108,9 +108,8 @@ | ||
108 | 108 … | safety_limit = _new_limit; |
109 | 109 … | SafetyLimitChange(msg.sender, _new_limit); |
110 | 110 … | } |
111 | 111 … | |
112 | - | |
113 | 112 … | /** |
114 | 113 … | * Actions |
115 | 114 … | * |
116 | 115 … | * Trusted citizens can create an action, which then can be voted on for 5 days |
@@ -135,8 +134,30 @@ | ||
135 | 134 … | actions_count = actionID + 1; |
136 | 135 … | } |
137 | 136 … | |
138 | 137 … | |
138 … | + | |
139 … | + | |
140 … | + /** | |
141 … | + * Voting | |
142 … | + */ | |
143 … | + function vote(uint actionId, bool in_favour) | |
144 … | + onlyTrusted | |
145 … | + returns (uint voteID) | |
146 … | + { | |
147 … | + Action action = actions[actionId]; | |
148 … | + | |
149 … | + // Check to make sure this person has not already voted | |
150 … | + if (action.voted[msg.sender] == true) throw; | |
151 … | + | |
152 … | + voteID = action.votes.length++; | |
153 … | + action.votes[voteID] = Vote({inSupport: in_favour, citizen: msg.sender}); | |
154 … | + action.voted[msg.sender] = true; | |
155 … | + action.numberOfVotes = voteID + 1; | |
156 … | + Voted(actionId, in_favour, msg.sender); | |
157 … | + } | |
158 … | + | |
159 … | + | |
139 | 160 … | /** |
140 | 161 … | * Guardians 💂 |
141 | 162 … | */ |
142 | 163 … | |
@@ -211,8 +232,11 @@ | ||
211 | 232 … | */ |
212 | 233 … | |
213 | 234 … | event ActionAdded(uint actionID, uint amount, string description); |
214 | 235 … | |
236 … | + // Vote | |
237 … | + event Voted(uint actionId, bool in_favour, address citizen); | |
238 … | + | |
215 | 239 … | // A new guardian has been elected |
216 | 240 … | event NewGuardian(address indexed _guardian, address indexed _creator); |
217 | 241 … | |
218 | 242 … | // A new person has been trusted |
migrations/2_deploy_contracts.js | ||
---|---|---|
@@ -3,7 +3,7 @@ | ||
3 | 3 … | deployer.deploy(Owned); |
4 | 4 … | deployer.autolink(); |
5 | 5 … | |
6 | 6 … | // Deploy main contracts |
7 | - deployer.deploy(StandardToken); | |
7 … | + // deployer.deploy(StandardToken); | |
8 | 8 … | deployer.deploy(Entropy); |
9 | 9 … | }; |
test/Entropy_actions.js | ||
---|---|---|
@@ -38,16 +38,20 @@ | ||
38 | 38 … | describe("Voting", () =>{ |
39 | 39 … | it("lets trusted citizens vote", (done) => { |
40 | 40 … | helpers.deployEntropyContract() |
41 | 41 … | .then((entropy) => { |
42 | - entropy.newAction(1e18, "Rigging refit").then((tx) => { | |
43 | - entropy.actions_count().then((actions_count) => { | |
44 | - assert.equal(actions_count, 1); | |
45 | - }) | |
46 | - .then(()=>{ done() }) | |
42 … | + entropy.newAction(1e18, "Rigging refit") | |
43 … | + .then((tx) => { | |
44 … | + // Vote in favour! | |
45 … | + entropy.vote(0, true).then((tx) => { | |
46 … | + done(); | |
47 … | + // TODO: Check it has a vote! | |
48 … | + // entropy.actions[0].numberOfVotes().then((count) => { | |
49 … | + // assert.equal(count, 1); | |
50 … | + // done(); | |
51 … | + // }) | |
52 … | + }) | |
47 | 53 … | }) |
48 | 54 … | }) |
49 | 55 … | }); |
50 | - | |
51 | 56 … | }) |
52 | - | |
53 | 57 … | }) |
Built with git-ssb-web