git ssb

0+

dangerousbeans / Entropy_contracts



Commit e2d16c3510e7763b548d4c0110a89fa0924236d6

Can create Actions

Joran committed on 12/8/2016, 7:15:25 AM
Parent: 45b3bd9b03a6a9a6ff08c2d724c3a2e1b2015582

Files changed

contracts/Entropy.solchanged
test/Entropy_actions.jschanged
test/Entropy_token.jschanged
test/helpers.jschanged
contracts/Entropy.solView
@@ -40,16 +40,18 @@
4040 * Any funds associated with Actions :bulb: in the Action Stream :clipboard:
4141 * become available in the Slush Pool :moneybag: for the Guardians :guardsman:
4242 * to use towards making those Actions :bulb: happen.
4343 */
44 + Action[] public actions;
45 + uint public actions_count;
4446 struct Action {
4547 uint amount;
4648 string description;
4749 uint votingDeadline;
4850 bool done;
4951 bool actionPassed;
5052 uint numberOfVotes;
51- bytes32 proposalHash;
53 + bytes32 actionHash;
5254 Vote[] votes;
5355 mapping (address => bool) voted;
5456 }
5557
@@ -65,11 +67,11 @@
6567 */
6668 function Entropy() {
6769 // Setup token attributes
6870 name = "Entropy";
69- decimals = 0;
70- symbol = "ENT"; //identifier
71- safety_limit = 300 ether;
71 + decimals = 0; // 1 token cannot be devided
72 + symbol = "ENT"; // identifier
73 + safety_limit = 300 ether; // Inital safety cap
7274
7375 // Set the creator as Trusted, a Citizen and a Guardian
7476 totalSupply = 1;
7577 balances[msg.sender] = 1;
@@ -85,13 +87,15 @@
8587 * Fallback function
8688 * This runs whenever ether is sent to Entropy without any other information
8789 */
8890 function() {
91 + // Buy tokens 🍪
8992 buyTokens();
9093 }
9194
92- // Token Selling related
9395
96 + // Token Selling related 🍪
97 +
9498 /**
9599 * Alters the safety limit for the maximum value of tokens bought
96100 */
97101 function changeSafeyLimit(uint _new_limit) onlyGuardians returns (bool success) {
@@ -102,9 +106,36 @@
102106 safety_limit = _new_limit;
103107 SafetyLimitChange(msg.sender, _new_limit);
104108 }
105109
110 +
106111 /**
112 + * Actions
113 + *
114 + * Trusted citizens can create an action, which then can be voted on for 5 days
115 + */
116 + function newAction(
117 + uint _etherAmount, // Amount to unlock (optional)
118 + string _description // The idea, task or destination
119 + )
120 + onlyTrusted // Only trusted Citizens
121 + returns (uint actionID)
122 + {
123 + actionID = actions.length++;
124 + Action a = actions[actionID];
125 + a.amount = _etherAmount;
126 + a.description = _description;
127 + a.actionHash = sha3(_etherAmount, _description);
128 + a.votingDeadline = now + 5 days;
129 + a.done = false;
130 + a.actionPassed = false;
131 + a.numberOfVotes = 0;
132 + ActionAdded(actionID, _etherAmount, _description);
133 + actions_count = actionID + 1;
134 + }
135 +
136 +
137 + /**
107138 * Guardians 💂
108139 */
109140
110141 // Set someone as a Guardian
@@ -176,13 +207,16 @@
176207 *
177208 * Important changes to the state of Entropy
178209 */
179210
211 + event ActionAdded(uint actionID, uint amount, string description);
212 +
180213 // A new guardian has been elected
181214 event NewGuardian(address indexed _guardian, address indexed _creator);
182215
183216 // A new person has been trusted
184217 event NewTrust(address indexed _citizen, address indexed _guardian);
218 +
185219 // A person is no longer trusted
186220 event TrustLost(address indexed _citizen, address indexed _guardian);
187221
188222 // Safety Limit has been increased
test/Entropy_actions.jsView
@@ -1,5 +1,34 @@
1-require('./helpers.js')
1 +const helpers = require('./helpers');
22
33 contract('Entropy - Actions', (accounts) => {
4 + /**
5 + * Actions
6 + *
7 + */
8 + it("stops untrusted Citizens from creating actions", (done) => {
9 + helpers.deployEntropyContract()
10 + .then((entropy) => {
11 + return helpers.expectedExceptionPromise(() => {
12 + return entropy.newAction(1e18, "Rigging refit", { from: accounts[1]});
13 + }, 3000000)
14 + .then(()=>{
15 + entropy.actions_count().then((actions_count) => {
16 + assert.equal(actions_count, 0);
17 + done();
18 + })
19 + })
20 + })
21 + });
422
23 + it("lets trusted Citizens create actions", (done) => {
24 + helpers.deployEntropyContract()
25 + .then((entropy) => {
26 + entropy.newAction(1e18, "Rigging refit").then((tx) => {
27 + entropy.actions_count().then((actions_count) => {
28 + assert.equal(actions_count, 1);
29 + })
30 + .then(()=>{ done() })
31 + })
32 + })
33 + });
534 })
test/Entropy_token.jsView
@@ -1,7 +1,7 @@
11 const helpers = require('./helpers');
22
3-contract('EntropyToken', (accounts) => {
3 +contract('Entropy - Token', (accounts) => {
44 describe("Basic", () => {
55 it("Sets valid attributes", function(done) {
66 helpers.deployEntropyContract()
77 .then((entropy) => {
test/helpers.jsView
@@ -1,6 +1,6 @@
11 exports.deployEntropyContract = () => {
2- return Entropy.new({gas: 1000000})
2 + return Entropy.new({gas: 2000000})
33 }
44
55
66 exports.getBalance = (address) => {

Built with git-ssb-web