@ayanworks/polygon-did-registry-contract 0.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,27 @@
1
- pragma solidity ^0.5.1;
1
+ /**
2
+ *Submitted for verification at polygonscan.com on 2021-12-29
3
+ */
4
+
5
+ //SPDX-License-Identifier: MIT
6
+ pragma solidity ^0.8.15;
7
+ // import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
2
8
 
3
9
  /**
4
10
  *@title PolygonDidRegistry
5
11
  *@dev Smart Contract for Polygon DID Method
6
12
  */
7
13
  contract PolygonDidRegistry {
14
+ address owner;
8
15
  struct PolyDID {
9
16
  address controller;
10
17
  uint256 created;
11
18
  uint256 updated;
12
19
  string did_doc;
13
20
  }
21
+
14
22
  modifier onlyController(address _id) {
15
23
  require(
16
- did[_id].controller == msg.sender, "message sender is not the controller"
24
+ did[_id].controller == msg.sender, "message sender is not the controller of the DID Doc"
17
25
  );
18
26
  _;
19
27
  }
@@ -22,20 +30,54 @@ contract PolygonDidRegistry {
22
30
  event DidCreated(address id, string doc);
23
31
  event DidUpdated(address id, string doc);
24
32
  event DidDeleted(address id);
33
+ event TransferOwnership(address newOwner);
34
+ bool private initialized;
35
+
36
+ function initialize() public {
37
+ require(!initialized, "Contract instance has already been initialized");
38
+ initialized = true;
39
+ owner = msg.sender;
40
+ }
41
+
42
+ modifier onlyOwner(){
43
+ require( msg.sender == owner, "message sender is not the owner");
44
+ _;
45
+ }
46
+
47
+ /**
48
+ *@dev transfer the ownership of contract
49
+ *@param _newOwner - Address of the new owner to whom the ownership needs to be passed
50
+ **/
51
+ function transferOwnership(address _newOwner)public onlyOwner() returns (string memory){
52
+ if(owner != _newOwner){
53
+ owner = _newOwner;
54
+ emit TransferOwnership(owner);
55
+ return ("Ownership transferred successfully");
56
+ }
57
+ else {
58
+ return ("New Owner address is equal to original owner address");
59
+ }
60
+ }
61
+
62
+ /**
63
+ *@dev Reads contract owner from chain
64
+ */
65
+ function getOwner() public view returns (address _owner){
66
+ return owner;
67
+ }
25
68
 
26
69
  /**
27
70
  *@dev Register a new DID
28
71
  *@param _id - Address that will refer the DID doc
29
72
  *@param _doc - A string object that holds the DID Doc
30
- *@return returns the controller, created and updated time stamp and DID Document
31
73
  */
32
74
  function createDID(address _id, string memory _doc)
33
75
  public
34
76
  returns (address controller, uint256 created, uint256 updated, string memory did_doc)
35
77
  {
36
78
  did[_id].controller = msg.sender;
37
- did[_id].created = now;
38
- did[_id].updated = now;
79
+ did[_id].created = block.timestamp;
80
+ did[_id].updated = block.timestamp;
39
81
  did[_id].did_doc = _doc;
40
82
  emit DidCreated(_id, _doc);
41
83
  return (did[_id].controller, did[_id].created, did[_id].updated, did[_id].did_doc);
@@ -53,14 +95,13 @@ contract PolygonDidRegistry {
53
95
  *@dev To Update the DID doc
54
96
  *@param _id - Address that refers to the DID doc
55
97
  *@param _doc - A String that holds the DID doc
56
- *@return returns the controller, created and updated time stamp and DID Document
57
98
  */
58
99
  function updateDID(address _id, string memory _doc)
59
100
  public
60
101
  onlyController(_id) returns(address controller, uint256 created, uint256 updated, string memory did_doc)
61
102
  {
62
103
  did[_id].did_doc = _doc;
63
- did[_id].updated = now;
104
+ did[_id].updated = block.timestamp;
64
105
  emit DidUpdated(_id, _doc);
65
106
  return (did[_id].controller, did[_id].created, did[_id].updated, did[_id].did_doc);
66
107
  }
@@ -1,5 +1,8 @@
1
+ const { deployProxy } = require('@openzeppelin/truffle-upgrades');
2
+
1
3
  const PolygonDidRegistry = artifacts.require("PolygonDidRegistry");
2
4
 
3
- module.exports = function(deployer){
4
- deployer.deploy(PolygonDidRegistry);
5
+ module.exports = async function (deployer) {
6
+ const instance = await deployProxy(PolygonDidRegistry, { deployer });
7
+ console.log('Deployed', instance.address);
5
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ayanworks/polygon-did-registry-contract",
3
- "version": "0.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Smart Contract to register DID on Polygon",
5
5
  "main": "build/contracts/PolygonDidRegistry.json",
6
6
  "directories": {
@@ -13,23 +13,33 @@
13
13
  },
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "ganache-cli": "6.8.1",
16
+ "@openzeppelin/contracts": "^4.7.0",
17
+ "@truffle/hdwallet-provider": "^2.0.10",
18
+ "fs-extra": "8.1.0",
19
+ "ganache-cli": "6.12.2",
17
20
  "mocha": "^7.0.0",
18
- "solc": "0.5.1",
19
- "ethers": "^4.0.41",
20
- "fs-extra": "8.1.0"
21
+ "solc": "0.8.0",
22
+ "truffle": "^5.5.20"
23
+ },
24
+ "devDependencies": {
25
+ "@openzeppelin/truffle-upgrades": "^1.15.0",
26
+ "chai": "^4.3.6",
27
+ "ethers": "^5.6.9",
28
+ "truffle": "^5.5.20"
21
29
  },
22
- "devDependencies": {},
23
30
  "repository": {
24
31
  "type": "git",
25
- "url": "git+https://gitlab.com/polygon-did/polygon-did-registry-contract.git"
32
+ "url": "git+https://github.com/ayanworks/polygon-did-registry-contract"
26
33
  },
27
34
  "keywords": [
28
35
  "did-method"
29
36
  ],
30
- "author": "Shashank Kulkarni <shashank.kulkarni@ayanworks.com>",
37
+ "author": "Ajay Jadhav <ajay@ayanworks.com>",
38
+ "contributors": [
39
+ "Anusha Garg <anusha.garg@ayanworks.com>, Shashank Kulkarni <shashank.kulkarni@ayanworks.com>"
40
+ ],
31
41
  "bugs": {
32
- "url": "https://gitlab.com/polygon-did/polygon-did-registry-contract/issues"
42
+ "url": "https://github.com/ayanworks/polygon-did-registry-contract/issues"
33
43
  },
34
- "homepage": "https://gitlab.com/polygon-did/polygon-did-registry-contract#readme"
44
+ "homepage": "https://github.com/ayanworks/polygon-did-registry-contract#readme"
35
45
  }
package/sst-config.json CHANGED
@@ -1 +1 @@
1
- {"sourceHash":"0x14a03c371f47729ebf07341b2e088ba55fbf26b5cb30651e577e7b75727b89fc"}
1
+ {"sourceHash":"0xc8790162aa577d0b4d7d5c07565d0921f14a5fd07e896fb2cafd79ec8317eb54"}
@@ -1,15 +1,15 @@
1
1
  const ethers = require('ethers');
2
2
  const ganache = require('ganache-cli');
3
3
  const assert = require('assert');
4
-
4
+ const { deployProxy } = require('@openzeppelin/truffle-upgrades');
5
+ const PolygonDidRegistry = artifacts.require("PolygonDidRegistry");
5
6
 
6
7
  // Library initialization that will talk with Blockchain
7
8
  const provider = new ethers.providers.Web3Provider(ganache.provider({ gasLimit: 8000000 }));
8
-
9
9
  // Initializing the build files
10
- const PolygonDIDRegistryJSON = require('../build/PolygonDIDRegistry_PolygonDIDRegistry.json');
10
+ const PolygonDIDRegistryJSON = require('../build/contracts/PolygonDidRegistry.json');
11
11
 
12
- let accounts, PolygonDIDRegistryInstance;
12
+ let accounts, PolygonDIDRegistryInstance, PolygonDIDRegistryInstance_test, PolygonUpgradableInstance, PolygonUpgradableInstance_test;
13
13
 
14
14
  // Describing the 1st Test
15
15
  // This will setup Ganache with some test address
@@ -25,32 +25,240 @@ describe('Ganache Setup', async () => {
25
25
  });
26
26
  });
27
27
 
28
- // 2nd Test starts here
29
- describe('Basic Contract Testing', () => {
28
+ // Upgradable with Proxy
29
+ // Deployment Testing 1.0
30
+ describe('Setting up the Upgradable Smart Contract', async () => {
31
+
32
+ describe('Setting up the contract', async () => {
33
+
34
+ it("Should deploy contract with Proxy, with no parameters/Constructor", async () => {
35
+ PolygonUpgradableInstance = await deployProxy( PolygonDidRegistry );
36
+ PolygonUpgradableInstance_test = new ethers.Contract(PolygonUpgradableInstance.address, PolygonDIDRegistryJSON.abi, provider.getSigner(accounts[3]));
37
+ assert.ok(PolygonUpgradableInstance.address, 'Upgradeable contract is deployed');
38
+ });
39
+ });
40
+
41
+ //Check Create Function test 1.1
42
+ describe('Checking the Create function using Upgradeable Contract', async () => {
43
+
44
+ it('This should store the DID doc on Upgradable Contract and will read and check if the value stored is correct', async () => {
45
+
46
+ // This will send the value to local ganache blockchain
47
+ const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
48
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
49
+ const tx = await PolygonUpgradableInstance.createDID(did, doc);
50
+
51
+ // Getting the set value in ganache blockchain
52
+ const currentValue = await PolygonUpgradableInstance.getDID(did);
53
+
54
+ // Comparing the set value to confirm
55
+ assert.equal(
56
+ currentValue,
57
+ doc,
58
+ 'value set must be able to get'
59
+ );
60
+
61
+ assert.notEqual(
62
+ currentValue,
63
+ null,
64
+ 'value should not be empty'
65
+ );
66
+ });
67
+ });
68
+
69
+ // Describing the 1.2 Test case
70
+ describe('Checking the Update function in Upgradable Contract', async () => {
71
+
72
+ it('This should update the DID doc on Upgradable Contract and will read and check if the value stored is correct', async () => {
73
+
74
+ // This will send the value to local ganache blockchain
75
+ const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
76
+ //changed the controller
77
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
78
+ const tx = await PolygonUpgradableInstance.updateDID(did, doc);
79
+
80
+ // Getting the set value in ganache blockchain
81
+ const currentValue = await PolygonUpgradableInstance.getDID(did);
82
+
83
+ // Comparing the set value to confirm
84
+ assert.equal(
85
+ currentValue,
86
+ doc,
87
+ 'value set must be able to get'
88
+ );
89
+ });
90
+ });
91
+
92
+ //Describing test 1.3 to check if test fails if we update with different controller
93
+ describe('Checking update with wrong controller', async () => {
94
+
95
+ it('This should not update DID doc ', async () => {
96
+
97
+ const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
98
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
99
+ try {
100
+ assert.ifError(
101
+
102
+ //sending transaction using different controller
103
+ await PolygonUpgradableInstance_test.functions.updateDID(did, doc));
104
+ } catch (error) {
105
+ }
106
+ });
107
+ });
108
+
109
+ // Describing the 1.4 Test case
110
+ describe('Checking the Delete function in Upgradable Contract', async () => {
111
+
112
+ it('This should delete the DID doc on Upgradable Contract and will read and check if the value is now an empty string', async () => {
113
+
114
+ // This will send the value to local ganache blockchain
115
+ const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
116
+ const tx = await PolygonUpgradableInstance.deleteDID(did);
117
+
118
+ // Getting the set value in ganache blockchain
119
+ const currentValue = await PolygonUpgradableInstance.getDID(did);
120
+
121
+ // Comparing the set value to confirm
122
+ assert.equal(
123
+ currentValue,
124
+ "",
125
+ 'value should be matching'
126
+ );
127
+ });
128
+ });
129
+
130
+ // Describing the 1.5 Test case
131
+ describe('Checking the Create function in Upgradable Contract', async () => {
132
+
133
+ it('This should store the DID doc on Upgradable Contract and will read and check if the value stored is not null', async () => {
134
+
135
+ // This will send the value to local ganache blockchain
136
+ const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
137
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","verificationMethod":[{"id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","publicKeyBase58":"RwHysxjkzFdJDqi2irHRVRFHX9uUj5aVAXVoufnk5PDA4qcn1ejJMgGhqCsFdQqXRCTdi4TbEQFJjDUAdi2JvYmH"}]}';
138
+ const doctest = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
139
+ const tx = await PolygonUpgradableInstance.createDID(did, doc);
140
+
141
+ // Getting the set value in ganache blockchain
142
+ const currentValue = await PolygonUpgradableInstance.getDID(did);
143
+
144
+ // Checking value is not null
145
+
146
+ assert.notEqual(
147
+ currentValue,
148
+ "",
149
+ 'value should not match'
150
+ );
151
+ });
152
+ });
153
+
154
+ // Describing the 1.6 Test case
155
+ describe('Checking the Update function in Upgradable Contract', async () => {
156
+
157
+ it('This should update the DID doc on Upgradable Contract and will read and check if the value stored has changed', async () => {
158
+
159
+ // This will send the value to local ganache blockchain
160
+ const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
161
+ //changed the controller
162
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
163
+ const docoriginal = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","verificationMethod":[{"id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","publicKeyBase58":"RwHysxjkzFdJDqi2irHRVRFHX9uUj5aVAXVoufnk5PDA4qcn1ejJMgGhqCsFdQqXRCTdi4TbEQFJjDUAdi2JvYmH"}]}';
164
+ const tx = await PolygonUpgradableInstance.updateDID(did, doc);
165
+
166
+ // Getting the set value in ganache blockchain
167
+ const currentValue = await PolygonUpgradableInstance.getDID(did);
168
+
169
+ // Comparing the set value to confirm
170
+ assert.notEqual(
171
+ currentValue,
172
+ docoriginal,
173
+ 'value should not match'
174
+ );
175
+ });
176
+ });
177
+
178
+
179
+ // Describing the 1.7 Test Case
180
+ describe('Checking the Delete function in Upgradable Contract', async () => {
181
+
182
+ it('This should delete the DID doc on Upgradable Contract and will read and check if the value is now not equal to the updated doc', async () => {
183
+
184
+ // This will send the value to local ganache blockchain
185
+ const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
186
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
187
+ const tx = await PolygonUpgradableInstance.deleteDID(did);
188
+
189
+ // Getting the set value in ganache blockchain
190
+ const currentValue = await PolygonUpgradableInstance.getDID(did);
191
+
192
+ // Comparing the set value to confirm
193
+ assert.notEqual(
194
+ currentValue,
195
+ doc,
196
+ 'value should not be matching'
197
+ );
198
+ });
199
+ });
200
+
201
+
202
+ //Describing the 1.8 Test Case
203
+ describe('Checking the Transafer Ownership Function', async () => {
204
+ it('This should transfer ownership of contract to another user', async () => {
205
+
206
+ const newOwner = accounts[5];
207
+ const owner = await PolygonUpgradableInstance.getOwner();
208
+ const tx = await PolygonUpgradableInstance.transferOwnership(newOwner);
209
+ const currentOwner = await PolygonUpgradableInstance.getOwner();
210
+
211
+ assert.notEqual(
212
+ owner,
213
+ currentOwner,
214
+ 'value should not be equal'
215
+ );
216
+ });
217
+ });
218
+
219
+ //Describing the 1.9 Test Case
220
+ describe('Checking the Transafer Ownership Function', async () => {
221
+ it('This should not transfer ownership of contract to another user since the transaction is being initiated by different owner', async () => {
222
+
223
+ const newOwner = accounts[6];
224
+ try {
225
+ assert.ifError(
226
+ //sending transaction using different controller
227
+ await PolygonUpgradableInstance_test.functions.transferOwnership(newOwner));
228
+ } catch (error) {
229
+ }
230
+ });
231
+ });
232
+
233
+ })
234
+
235
+
236
+
237
+ // basic Contract Testing
238
+ // Deployment Testing 2.0
239
+ describe('Basic Contract Testing', async () => {
30
240
 
31
241
  // Describing a SubTest case
32
242
  describe('Setting up the contract', async () => {
33
243
 
34
- // 1st Test case for the SubTest case
35
244
  it('This Deploys Polygon Smart contract from 1st account with no Parameters/Constructor', async () => {
36
245
 
37
246
  // Creating a contract factory for deploying contract.
38
247
  const PolygonDIDRegistry = new ethers.ContractFactory(
39
248
  PolygonDIDRegistryJSON.abi,
40
- PolygonDIDRegistryJSON.evm.bytecode.object,
41
- provider.getSigner(accounts[0])
249
+ PolygonDIDRegistryJSON.bytecode,
250
+ provider.getSigner(accounts[2])
42
251
  );
43
252
  PolygonDIDRegistryInstance = await PolygonDIDRegistry.deploy();
44
-
253
+ PolygonDIDRegistryInstance_test = new ethers.Contract(PolygonDIDRegistryInstance.address, PolygonDIDRegistryJSON.abi, provider.getSigner(accounts[3]));
45
254
  assert.ok(PolygonDIDRegistryInstance.address, 'conract address should be present');
46
255
  });
47
256
 
48
257
  });
49
258
 
50
- // Describing the 3rd Test case
259
+ // Describing the 2.1 Test case
51
260
  describe('Checking the Create function in Contract', async () => {
52
261
 
53
- // Initializing the 1st sub test
54
262
  it('This should store the DID doc on Contract and will read and check if the value stored is correct', async () => {
55
263
 
56
264
  // This will send the value to local ganache blockchain
@@ -70,13 +278,18 @@ describe('Basic Contract Testing', () => {
70
278
  doc,
71
279
  'value set must be able to get'
72
280
  );
281
+
282
+ assert.notEqual(
283
+ currentValue,
284
+ null,
285
+ 'value should not be empty'
286
+ );
73
287
  });
74
288
  });
75
289
 
76
- // Describing the 4th Test case
290
+ // Describing the 2.2 Test case
77
291
  describe('Checking the Update function in Contract', async () => {
78
292
 
79
- // Initializing the 1st sub test
80
293
  it('This should update the DID doc on Contract and will read and check if the value stored is correct', async () => {
81
294
 
82
295
  // This will send the value to local ganache blockchain
@@ -99,17 +312,109 @@ describe('Basic Contract Testing', () => {
99
312
  );
100
313
  });
101
314
  });
315
+ //Describing test 2.3 to check if test fails if we update with different controller
316
+ describe('Checking update with wrong controller', async () => {
317
+
318
+ it('This should not update DID doc ', async () => {
319
+
320
+ const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
321
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
322
+ try {
323
+ assert.ifError(
324
+ //sending transaction using different controller
325
+ await PolygonDIDRegistryInstance_test.functions.updateDID(did, doc));
326
+ } catch (error) {
327
+ }
328
+ });
329
+ });
102
330
 
103
- // Describing the 5th Test case
331
+ // Describing the 2.4 Test case
104
332
  describe('Checking the Delete function in Contract', async () => {
105
333
 
106
- // Initializing the 1st sub test
107
- it('This should delete the DID doc on Contract and will read and check if the value is now null', async () => {
334
+ it('This should delete the DID doc on Contract and will read and check if the value is now an empty string', async () => {
108
335
 
109
336
  // This will send the value to local ganache blockchain
110
337
  const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
338
+ const tx = await PolygonDIDRegistryInstance.functions.deleteDID(did);
339
+
340
+ // Transfer confirmation
341
+ await tx.wait();
342
+
343
+ // Getting the set value in ganache blockchain
344
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
345
+
346
+ // Comparing the set value to confirm
347
+ assert.equal(
348
+ currentValue,
349
+ "",
350
+ 'value should be matching'
351
+ );
352
+ });
353
+ });
354
+
355
+ // Describing the 2.5 Test case
356
+ describe('Checking the Create function in Contract', async () => {
357
+
358
+ it('This should store the DID doc on Contract and will read and check if the value stored is not null', async () => {
359
+
360
+ // This will send the value to local ganache blockchain
361
+ const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
362
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","verificationMethod":[{"id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","publicKeyBase58":"RwHysxjkzFdJDqi2irHRVRFHX9uUj5aVAXVoufnk5PDA4qcn1ejJMgGhqCsFdQqXRCTdi4TbEQFJjDUAdi2JvYmH"}]}';
363
+ const doctest = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
364
+ const tx = await PolygonDIDRegistryInstance.functions.createDID(did, doc);
365
+
366
+ // Transfer confirmation
367
+ await tx.wait();
368
+
369
+ // Getting the set value in ganache blockchain
370
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
371
+
372
+ // Checking value is not null
373
+
374
+ assert.notEqual(
375
+ currentValue,
376
+ doctest,
377
+ 'value should not match'
378
+ );
379
+ });
380
+ });
381
+
382
+ // Describing the 2.6 Test case
383
+ describe('Checking the Update function in Contract', async () => {
384
+
385
+ it('This should update the DID doc on Contract and will read and check if the value stored has changed', async () => {
386
+
387
+ // This will send the value to local ganache blockchain
388
+ const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
389
+ //changed the controller
111
390
  const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
391
+ const docoriginal = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","verificationMethod":[{"id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","publicKeyBase58":"RwHysxjkzFdJDqi2irHRVRFHX9uUj5aVAXVoufnk5PDA4qcn1ejJMgGhqCsFdQqXRCTdi4TbEQFJjDUAdi2JvYmH"}]}';
392
+ const tx = await PolygonDIDRegistryInstance.functions.updateDID(did, doc);
393
+
394
+ // Transfer confirmation
395
+ await tx.wait();
396
+
397
+ // Getting the set value in ganache blockchain
398
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
399
+
400
+ // Comparing the set value to confirm
401
+ assert.notEqual(
402
+ currentValue,
403
+ docoriginal,
404
+ 'value should not match'
405
+ );
406
+ });
407
+ });
112
408
 
409
+
410
+ // Describing the 2.7 Test case
411
+ describe('Checking the Delete function in Contract', async () => {
412
+
413
+ it('This should delete the DID doc on Contract and will read and check if the value is now not equal to the updated doc', async () => {
414
+
415
+ // This will send the value to local ganache blockchain
416
+ const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
417
+ const doc = '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}';
113
418
  const tx = await PolygonDIDRegistryInstance.functions.deleteDID(did);
114
419
 
115
420
  // Transfer confirmation