@ayanworks/polygon-did-registry-contract 1.1.2 → 2.0.1-alpha.0

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.
package/compile.js DELETED
@@ -1,112 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs-extra');
3
- const solc = require('solc');
4
- const ethers = require('ethers');
5
-
6
- const sourceFolderPath = path.resolve(__dirname, 'contracts');
7
- const buildFolderPath = path.resolve(__dirname, 'build');
8
- const lastSourceHashFilePath = path.resolve(__dirname, 'sst-config.json');
9
-
10
- const getContractSource = contractFileName => {
11
- const contractPath = path.resolve(__dirname, 'contracts', contractFileName);
12
- const source = fs.readFileSync(contractPath, 'utf8');
13
- return source;
14
- };
15
-
16
- let sources = {};
17
-
18
- fs.readdirSync(sourceFolderPath).forEach(contractFileName => {
19
- sources = {
20
- ...sources,
21
- [contractFileName]: {
22
- content: getContractSource(contractFileName)
23
- }
24
- }
25
- });
26
- // console.log(sources);
27
-
28
- function convertToHex(inputString) {
29
- var hex = '';
30
- for(var i=0;i<inputString.length;i++) {
31
- hex += ''+inputString.charCodeAt(i).toString(16);
32
- }
33
- return hex;
34
- }
35
-
36
- const sourceHash = ethers.utils.sha256('0x'+convertToHex(JSON.stringify(sources)));
37
-
38
- console.log('\n'.repeat(process.stdout.rows));
39
-
40
- if(fs.existsSync(buildFolderPath)
41
- && fs.existsSync(lastSourceHashFilePath)
42
- && (JSON.parse(fs.readFileSync(lastSourceHashFilePath, 'utf8'))).sourceHash === sourceHash) {
43
- console.log('No changes in .sol files detected... \nSkiping compile script...\n');
44
- } else {
45
- // write the source hash there at the end of
46
- // console.log(lastSourceHash,sourceHash);
47
-
48
- const input = {
49
- language: 'Solidity',
50
- sources,
51
- settings: {
52
- outputSelection: {
53
- '*': {
54
- '*': [ '*' ]
55
- }
56
- }
57
- }
58
- }
59
-
60
- console.log('Compiling contracts...');
61
- const output = JSON.parse(solc.compile(JSON.stringify(input)));
62
- console.log('Done');
63
-
64
- let shouldBuild = true;
65
-
66
- if (output.errors) {
67
- // console.error(output.errors);
68
- for(error of output.errors) {
69
- console.log('-'.repeat(process.stdout.columns));
70
- console.group(error.severity.toUpperCase());
71
- console.log(error.formattedMessage);
72
- console.groupEnd();
73
- }
74
- if(Object.values(output.errors).length) console.log('-'.repeat(process.stdout.columns));
75
- // throw '\nError in compilation please check the contract\n';
76
- for(error of output.errors) {
77
- if(error.severity === 'error') {
78
- shouldBuild = false;
79
- throw 'Error found\n';
80
- break;
81
- }
82
- }
83
- }
84
-
85
- if(shouldBuild) {
86
- console.log('\nBuilding please wait...');
87
-
88
- fs.removeSync(buildFolderPath);
89
- fs.ensureDirSync(buildFolderPath);
90
-
91
- let i = 0;
92
- for (let contractFile in output.contracts) {
93
- for(let key in output.contracts[contractFile]) {
94
- //console.log(key, Object.keys(output.contracts[contractFile][key]));
95
- fs.outputJsonSync(
96
- path.resolve(buildFolderPath, `${contractFile.split('.')[0]}_${key}.json`),
97
- output.contracts[contractFile][key]
98
- );
99
-
100
- }
101
- i++;
102
- }
103
- console.log('Build finished successfully!\n');
104
- } else {
105
- console.log('\nBuild failed\n');
106
- }
107
-
108
- fs.outputJsonSync(
109
- path.resolve(lastSourceHashFilePath),
110
- { sourceHash }
111
- );
112
- }
package/test/.gitkeep DELETED
File without changes
@@ -1,460 +0,0 @@
1
- const ethers = require('ethers');
2
- const ganache = require('ganache-cli');
3
- const assert = require('assert');
4
- const { deployProxy } = require('@openzeppelin/truffle-upgrades');
5
- const PolygonDidRegistry = artifacts.require("PolygonDidRegistry");
6
-
7
- // Library initialization that will talk with Blockchain
8
- const provider = new ethers.providers.Web3Provider(ganache.provider({ gasLimit: 8000000 }));
9
- // Initializing the build files
10
- const PolygonDIDRegistryJSON = require('../build/contracts/PolygonDidRegistry.json');
11
-
12
- let accounts, PolygonDIDRegistryInstance, PolygonDIDRegistryInstance_test, PolygonUpgradableInstance, PolygonUpgradableInstance_test;
13
-
14
- // Describing the 1st Test
15
- // This will setup Ganache with some test address
16
- describe('Ganache Setup', async () => {
17
-
18
- it('Ganache setup with Test Accounts', async () => {
19
-
20
- // List of accounts are fetched here
21
- accounts = await provider.listAccounts();
22
-
23
- // We will check that atleast 2 accounts are loaded
24
- assert.ok(accounts.length >= 1, '2 Accounts are present minimum');
25
- });
26
- });
27
-
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 getTotalNumberOfDIDs Function', async () => {
71
- it('This should get correct number of DIDs registered', async () => {
72
-
73
- const currentValue = await PolygonUpgradableInstance.getTotalNumberOfDIDs();
74
- assert.equal(
75
- currentValue,
76
- 1,
77
- 'value should be matching'
78
- );
79
- });
80
- });
81
-
82
-
83
- // Describing the 1.3 Test case
84
- describe('Checking the Update function in Upgradable Contract', async () => {
85
-
86
- it('This should update the DID doc on Upgradable Contract and will read and check if the value stored is correct', async () => {
87
-
88
- // This will send the value to local ganache blockchain
89
- const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
90
- //changed the controller
91
- 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"}]}';
92
- const tx = await PolygonUpgradableInstance.updateDID(did, doc);
93
-
94
- // Getting the set value in ganache blockchain
95
- const currentValue = await PolygonUpgradableInstance.getDID(did);
96
-
97
- // Comparing the set value to confirm
98
- assert.equal(
99
- currentValue,
100
- doc,
101
- 'value set must be able to get'
102
- );
103
- });
104
- });
105
-
106
- //Describing test 1.4 to check if test fails if we update with different controller
107
- describe('Checking update with wrong controller', async () => {
108
-
109
- it('This should not update DID doc ', async () => {
110
-
111
- const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
112
- 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
- try {
114
- assert.ifError(
115
-
116
- //sending transaction using different controller
117
- await PolygonUpgradableInstance_test.functions.updateDID(did, doc));
118
- } catch (error) {
119
- }
120
- });
121
- });
122
-
123
- // Describing the 1.5 Test case
124
- describe('Checking the Delete function in Upgradable Contract', async () => {
125
-
126
- it('This should delete the DID doc on Upgradable Contract and will read and check if the value is now an empty string', async () => {
127
-
128
- // This will send the value to local ganache blockchain
129
- const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
130
- const tx = await PolygonUpgradableInstance.deleteDID(did);
131
-
132
- // Getting the set value in ganache blockchain
133
- const currentValue = await PolygonUpgradableInstance.getDID(did);
134
-
135
- // Comparing the set value to confirm
136
- assert.equal(
137
- currentValue,
138
- "",
139
- 'value should be matching'
140
- );
141
- });
142
- });
143
-
144
- // Describing the 1.6 Test case
145
- describe('Checking the Create function in Upgradable Contract', async () => {
146
-
147
- it('This should store the DID doc on Upgradable Contract and will read and check if the value stored is not null', async () => {
148
-
149
- // This will send the value to local ganache blockchain
150
- const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
151
- 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"}]}';
152
- 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"}]}';
153
- const tx = await PolygonUpgradableInstance.createDID(did, doc);
154
-
155
- // Getting the set value in ganache blockchain
156
- const currentValue = await PolygonUpgradableInstance.getDID(did);
157
-
158
- // Checking value is not null
159
-
160
- assert.notEqual(
161
- currentValue,
162
- "",
163
- 'value should not match'
164
- );
165
- });
166
- });
167
-
168
- // Describing the 1.7 Test case
169
- describe('Checking the Update function in Upgradable Contract', async () => {
170
-
171
- it('This should update the DID doc on Upgradable Contract and will read and check if the value stored has changed', async () => {
172
-
173
- // This will send the value to local ganache blockchain
174
- const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
175
- //changed the controller
176
- 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"}]}';
177
- 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"}]}';
178
- const tx = await PolygonUpgradableInstance.updateDID(did, doc);
179
-
180
- // Getting the set value in ganache blockchain
181
- const currentValue = await PolygonUpgradableInstance.getDID(did);
182
-
183
- // Comparing the set value to confirm
184
- assert.notEqual(
185
- currentValue,
186
- docoriginal,
187
- 'value should not match'
188
- );
189
- });
190
- });
191
-
192
-
193
- // Describing the 1.8 Test Case
194
- describe('Checking the Delete function in Upgradable Contract', async () => {
195
-
196
- 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 () => {
197
-
198
- // This will send the value to local ganache blockchain
199
- const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
200
- 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"}]}';
201
- const tx = await PolygonUpgradableInstance.deleteDID(did);
202
-
203
- // Getting the set value in ganache blockchain
204
- const currentValue = await PolygonUpgradableInstance.getDID(did);
205
-
206
- // Comparing the set value to confirm
207
- assert.notEqual(
208
- currentValue,
209
- doc,
210
- 'value should not be matching'
211
- );
212
- });
213
- });
214
-
215
- //Describing the 1.9 Test Case
216
- describe('Checking the getTotalNumberOfDIDs Function', async () => {
217
- it('This should get correct number of DIDs registered', async () => {
218
-
219
- const totalValue = await PolygonUpgradableInstance.getTotalNumberOfDIDs();
220
- const deltedValue = await PolygonUpgradableInstance.getTotalNumberOfDeletedDIDs();
221
- const currentValue = totalValue - deltedValue;
222
- assert.equal(
223
- currentValue,
224
- 0,
225
- 'value should be matching'
226
- );
227
- });
228
- });
229
-
230
- //Describing the 1.10 Test Case
231
- describe('Checking the Transafer Ownership Function', async () => {
232
- it('This should transfer ownership of contract to another user', async () => {
233
-
234
- const newOwner = accounts[5];
235
- const owner = await PolygonUpgradableInstance.getOwner();
236
- const tx = await PolygonUpgradableInstance.transferOwnership(newOwner);
237
- const currentOwner = await PolygonUpgradableInstance.getOwner();
238
-
239
- assert.notEqual(
240
- owner,
241
- currentOwner,
242
- 'value should not be equal'
243
- );
244
- });
245
- });
246
-
247
- //Describing the 1.11 Test Case
248
- describe('Checking the Transafer Ownership Function', async () => {
249
- it('This should not transfer ownership of contract to another user since the transaction is being initiated by different owner', async () => {
250
-
251
- const newOwner = accounts[6];
252
- try {
253
- assert.ifError(
254
- //sending transaction using different controller
255
- await PolygonUpgradableInstance_test.functions.transferOwnership(newOwner));
256
- } catch (error) {
257
- }
258
- });
259
- });
260
- })
261
-
262
-
263
- // basic Contract Testing
264
- // Deployment Testing 2.0
265
- describe('Basic Contract Testing', async () => {
266
-
267
- // Describing a SubTest case
268
- describe('Setting up the contract', async () => {
269
-
270
- it('This Deploys Polygon Smart contract from 1st account with no Parameters/Constructor', async () => {
271
-
272
- // Creating a contract factory for deploying contract.
273
- const PolygonDIDRegistry = new ethers.ContractFactory(
274
- PolygonDIDRegistryJSON.abi,
275
- PolygonDIDRegistryJSON.bytecode,
276
- provider.getSigner(accounts[2])
277
- );
278
- PolygonDIDRegistryInstance = await PolygonDIDRegistry.deploy();
279
- PolygonDIDRegistryInstance_test = new ethers.Contract(PolygonDIDRegistryInstance.address, PolygonDIDRegistryJSON.abi, provider.getSigner(accounts[3]));
280
- assert.ok(PolygonDIDRegistryInstance.address, 'conract address should be present');
281
- });
282
-
283
- });
284
-
285
- // Describing the 2.1 Test case
286
- describe('Checking the Create function in Contract', async () => {
287
-
288
- it('This should store the DID doc on Contract and will read and check if the value stored is correct', async () => {
289
-
290
- // This will send the value to local ganache blockchain
291
- const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
292
- 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"}]}';
293
- const tx = await PolygonDIDRegistryInstance.functions.createDID(did, doc);
294
-
295
- // Transfer confirmation
296
- await tx.wait();
297
-
298
- // Getting the set value in ganache blockchain
299
- const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
300
-
301
- // Comparing the set value to confirm
302
- assert.equal(
303
- currentValue,
304
- doc,
305
- 'value set must be able to get'
306
- );
307
-
308
- assert.notEqual(
309
- currentValue,
310
- null,
311
- 'value should not be empty'
312
- );
313
- });
314
- });
315
-
316
- // Describing the 2.2 Test case
317
- describe('Checking the Update function in Contract', async () => {
318
-
319
- it('This should update the DID doc on Contract and will read and check if the value stored is correct', async () => {
320
-
321
- // This will send the value to local ganache blockchain
322
- const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
323
- //changed the controller
324
- 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"}]}';
325
- const tx = await PolygonDIDRegistryInstance.functions.updateDID(did, doc);
326
-
327
- // Transfer confirmation
328
- await tx.wait();
329
-
330
- // Getting the set value in ganache blockchain
331
- const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
332
-
333
- // Comparing the set value to confirm
334
- assert.equal(
335
- currentValue,
336
- doc,
337
- 'value set must be able to get'
338
- );
339
- });
340
- });
341
- //Describing test 2.3 to check if test fails if we update with different controller
342
- describe('Checking update with wrong controller', async () => {
343
-
344
- it('This should not update DID doc ', async () => {
345
-
346
- const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
347
- 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"}]}';
348
- try {
349
- assert.ifError(
350
- //sending transaction using different controller
351
- await PolygonDIDRegistryInstance_test.functions.updateDID(did, doc));
352
- } catch (error) {
353
- }
354
- });
355
- });
356
-
357
- // Describing the 2.4 Test case
358
- describe('Checking the Delete function in Contract', async () => {
359
-
360
- it('This should delete the DID doc on Contract and will read and check if the value is now an empty string', async () => {
361
-
362
- // This will send the value to local ganache blockchain
363
- const did = '0x2f65b747440deaf596892dfc7965040be8b99100';
364
- const tx = await PolygonDIDRegistryInstance.functions.deleteDID(did);
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
- // Comparing the set value to confirm
373
- assert.equal(
374
- currentValue,
375
- "",
376
- 'value should be matching'
377
- );
378
- });
379
- });
380
-
381
- // Describing the 2.5 Test case
382
- describe('Checking the Create function in Contract', async () => {
383
-
384
- it('This should store the DID doc on Contract and will read and check if the value stored is not null', async () => {
385
-
386
- // This will send the value to local ganache blockchain
387
- const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
388
- 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"}]}';
389
- 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"}]}';
390
- const tx = await PolygonDIDRegistryInstance.functions.createDID(did, doc);
391
-
392
- // Transfer confirmation
393
- await tx.wait();
394
-
395
- // Getting the set value in ganache blockchain
396
- const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
397
-
398
- // Checking value is not null
399
-
400
- assert.notEqual(
401
- currentValue,
402
- doctest,
403
- 'value should not match'
404
- );
405
- });
406
- });
407
-
408
- // Describing the 2.6 Test case
409
- describe('Checking the Update function in Contract', async () => {
410
-
411
- it('This should update the DID doc on Contract and will read and check if the value stored has changed', async () => {
412
-
413
- // This will send the value to local ganache blockchain
414
- const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
415
- //changed the controller
416
- 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"}]}';
417
- 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"}]}';
418
- const tx = await PolygonDIDRegistryInstance.functions.updateDID(did, doc);
419
-
420
- // Transfer confirmation
421
- await tx.wait();
422
-
423
- // Getting the set value in ganache blockchain
424
- const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
425
-
426
- // Comparing the set value to confirm
427
- assert.notEqual(
428
- currentValue,
429
- docoriginal,
430
- 'value should not match'
431
- );
432
- });
433
- });
434
-
435
-
436
- // Describing the 2.7 Test case
437
- describe('Checking the Delete function in Contract', async () => {
438
-
439
- 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 () => {
440
-
441
- // This will send the value to local ganache blockchain
442
- const did = '0x54ec7be8b24f7139f870f277cf99c527ff43892b';
443
- 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"}]}';
444
- const tx = await PolygonDIDRegistryInstance.functions.deleteDID(did);
445
-
446
- // Transfer confirmation
447
- await tx.wait();
448
-
449
- // Getting the set value in ganache blockchain
450
- const currentValue = await PolygonDIDRegistryInstance.functions.getDID(did);
451
-
452
- // Comparing the set value to confirm
453
- assert.notEqual(
454
- currentValue,
455
- doc,
456
- 'value should not be matching'
457
- );
458
- });
459
- });
460
- });