/ test / identity.js
identity.js
  1  const TestUtils = require("./TestUtils.js")
  2  const Identity = artifacts.require("./identity/Identity.sol");
  3  
  4  contract('Identity', function(accounts) {
  5  
  6      let identity;
  7      beforeEach(async () => {
  8          identity = await Identity.new({from: accounts[0]})
  9      })
 10  
 11  
 12      describe("Identity()", () => {
 13  
 14          it("initialize with msg.sender as management key", async () => {
 15              assert.equal(
 16                  await identity.getKeyType(accounts[0]),
 17                  1,
 18                  identity.address+".getKeyType("+accounts[0]+") is not MANAGEMENT_KEY")
 19          });
 20          
 21      });
 22  
 23  
 24      describe("addKey(address _key, uint256 _type)", () => {
 25  
 26          it("MANAGEMENT_KEY add a new address as ACTION_KEY", async () => {
 27              await identity.addKey(accounts[1], 2, {from: accounts[0]})
 28              assert.equal(
 29                  await identity.getKeyType(accounts[1]),
 30                  2,
 31                  identity.address+".getKeyType("+accounts[1]+") is not ACTION_KEY")
 32          });
 33  
 34  
 35          it("should not add key by non manager", async () => {            
 36              try {
 37                  await identity.addKey(accounts[1], 1, {from: accounts[2]})
 38              }catch(e){
 39              }
 40              assert.equal(
 41                  await identity.getKeyType(accounts[1]),
 42                  0,
 43                  identity.address+".getKeyType("+accounts[1]+") is not correct")
 44          });
 45  
 46          it("should not add key type 1 by actor", async () => {            
 47              await identity.addKey(accounts[2], 2, {from: accounts[0]})
 48              try {
 49                  await identity.addKey(accounts[1], 1, {from: accounts[2]})
 50              } catch(e){
 51              }
 52              assert.equal(
 53                  await identity.getKeyType(accounts[1]),
 54                  0,
 55                  identity.address+".getKeyType("+accounts[1]+") is not correct")
 56          });
 57  
 58  
 59  
 60          it("fire KeyAdded(address indexed key, uint256 indexed type)", async () => {
 61              identity.addKey(accounts[1], 2, {from: accounts[0]})
 62              const keyAdded = await TestUtils.listenForEvent(identity.KeyAdded())
 63              assert(keyAdded.key, accounts[1], "Key is not correct")
 64              assert(keyAdded.keyType, 2, "Type is not correct")
 65          });
 66  
 67      });
 68  
 69  
 70      describe("removeKey(address _key, uint256 _type)", () => {
 71  
 72          it("MANAGEMENT_KEY should removes a key", async () => {
 73              await identity.addKey(accounts[1], 1, {from: accounts[0]})
 74              await identity.removeKey(accounts[0], {from: accounts[1]})    
 75              assert.equal(
 76                  await identity.getKeyType(accounts[0]),
 77                  0,
 78                  identity.address+".getKeyType("+accounts[0]+") is not 0")
 79          });
 80          
 81  
 82          it("other key should not removes a key", async () => {
 83              await identity.addKey(accounts[1], 1, {from: accounts[0]})
 84              try {
 85                  await identity.removeKey(accounts[1], {from: accounts[2]})    
 86              }catch (e) {
 87  
 88              }
 89              assert.equal(
 90                  await identity.getKeyType(accounts[1]),
 91                  1,
 92                  identity.address+".getKeyType("+accounts[1]+") is not 0")
 93          });
 94  
 95          it("actor key should not remove key", async () => {
 96              await identity.addKey(accounts[1], 2, {from: accounts[0]})
 97              await identity.addKey(accounts[2], 2, {from: accounts[0]})
 98              try {
 99                  await identity.removeKey(accounts[1], {from: accounts[2]})    
100              }catch (e) {
101  
102              }
103              assert.equal(
104                  await identity.getKeyType(accounts[1]),
105                  2,
106                  identity.address+".getKeyType("+accounts[1]+") is not 0")
107          });
108          
109  
110          it("MANAGEMENT_KEY should not remove itself MANAGEMENT_KEY when there is no other MANAGEMENT_KEY", async () => {
111              try {
112                  await identity.removeKey(accounts[0], {from: accounts[0]})
113              } catch(e) {
114                  //nothing
115              }
116              assert.equal(
117                  await identity.getKeyType(accounts[0]),
118                  1,
119                  identity.address+".getKeyType("+accounts[0]+") is not MANAGEMENT_KEY")
120            
121          });
122  
123          it("fire KeyRemoved(address indexed key, uint256 indexed type)", async () => {
124              await identity.addKey(accounts[1], 2, {from: accounts[0]})
125              identity.removeKey(accounts[1], {from: accounts[0]})  
126              const keyRemoved = await TestUtils.listenForEvent(identity.KeyRemoved())
127              assert(keyRemoved.key, accounts[1], "Key is not correct")
128              assert(keyRemoved.keyType, 2, "Type is not correct")
129          });
130  
131      });
132  
133  
134      describe("getKeyType(address _key)", () => {
135  
136          it("should start only with initializer as only key", async () => {
137              assert.equal(
138                  await identity.getKeyType(accounts[0]),
139                  1,
140                  identity.address+".getKeyType("+accounts[0]+") is not correct")
141  
142              assert.equal(
143                  await identity.getKeyType(accounts[1]),
144                  0,
145                  identity.address+".getKeyType("+accounts[1]+") is not correct")
146          });
147  
148          it("should get type 2 after addKey type 2", async () => {
149              await identity.addKey(accounts[1], 2, {from: accounts[0]})
150              assert.equal(
151                  await identity.getKeyType(accounts[1]),
152                  2,
153                  identity.address+".getKeyType("+accounts[1]+") is not correct")
154              });
155              
156          it("should get type 999 after addKey type 999", async () => {            
157              await identity.addKey(accounts[1], 999, {from: accounts[0]})
158              assert.equal(
159                  await identity.getKeyType(accounts[1]),
160                  999,
161                  identity.address+".getKeyType("+accounts[1]+") is not correct")
162          });
163  
164      });
165  
166  
167      describe("getKeysByType(uint256 _type)", () => {
168  
169          it("at initialization", async () => {
170              
171          });
172  
173          it("after addKey", async () => {
174              
175          });
176  
177          it("after removeKey", async () => {
178              
179          });
180  
181          it("after replaceKey", async () => {
182              
183          });
184  
185      });
186  
187  
188      describe("replaceKey(address _oldKey, address _newKey)", () => {
189  
190          it("MANAGEMENT_KEY replace itself (alone)", async () => {
191          
192          });
193  
194          it("MANAGEMENT_KEY replace a key between others", async () => {
195              
196          });
197  
198          it("MANAGEMENT_KEY replace the first key", async () => {
199              
200          });
201  
202          it("MANAGEMENT_KEY replace the last key", async () => {
203              
204          });
205  
206          it("fire KeyReplaced(address indexed oldKey, address indexed newKey, uint256 indexed type)", async () => {
207  
208          });
209  
210      });
211  
212  
213      describe("execute(address _to, uint256 _value, bytes _data)", () => {
214  
215          it("ACTOR_KEY execute arbitrary transaction", async () => {
216              
217          });
218          
219          it("MANAGEMENT_KEY execute arbitrary transaction", async () => {
220              
221          });
222  
223          it("Other keys NOT execute arbitrary transaction", async () => {
224              
225          });
226  
227          it("fire Executed(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data)", async () => {
228              
229          });
230  
231      });
232  
233  
234      describe("approve(bytes32 _id, bool _approve)", () => {
235  
236          it("MANAGEMENT_KEY should approve a claim", async () => {
237              
238          });
239  
240          it("MANAGEMENT_KEY should approve a transaction", async () => {
241              
242          });
243  
244          it("fire Approved(uint256 indexed executionId, bool approved)", async () => {
245              
246          });
247  
248      });
249  
250      
251      describe("getClaim(bytes32 _claimId)", () => {
252  
253          it("Returns a claim by ID.", async () => {
254              
255          });
256  
257      });
258              
259      describe("getClaimIdsByType(uint256 _claimType)", () => {
260          it("Returns an array of claim IDs by type.", async () => {
261              
262          });
263      });
264                          
265      describe("addClaim(uint256 _claimType, address issuer, uint256 signatureType, bytes _signature, bytes _data, string _uri)", () => {
266          it("Requests the ADDITION of a claim from an issuer", async () => {
267              
268          });
269  
270          it("Requests the CHANGE of a claim from an issuer", async () => {
271              
272          });
273  
274      });
275  
276      describe("removeClaim(bytes32 _claimId)", () => {
277          it("Requests the DELETION of a claim from an issuer", async () => {
278              
279          });
280  
281          it("Requests the DELETION of a claim from identity", async () => {
282              
283          });
284      });
285                  
286  });