@ayanworks/polygon-did-registry-contract 2.0.0 → 2.0.1-alpha.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.
@@ -0,0 +1,2 @@
1
+ import DidRegistryContract from './artifacts/PolygonDidRegistry.json';
2
+ export default DidRegistryContract;
package/build/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const PolygonDidRegistry_json_1 = __importDefault(require("./artifacts/PolygonDidRegistry.json"));
7
+ exports.default = PolygonDidRegistry_json_1.default;
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;AAAA,kGAAqE;AAErE,kBAAe,iCAAmB,CAAA"}
package/compile.ts ADDED
@@ -0,0 +1,117 @@
1
+ import path from 'path'
2
+ import fs from 'fs-extra'
3
+ // @ts-ignore
4
+ import solc from 'solc'
5
+ import * as ethers from 'ethers'
6
+
7
+ const sourceFolderPath = path.resolve(__dirname, 'contracts')
8
+ const buildFolderPath = path.resolve(__dirname, 'artifacts')
9
+ const lastSourceHashFilePath = path.resolve(__dirname, 'sst-config.json')
10
+
11
+ const getContractSource = (contractFileName: string) => {
12
+ const contractPath = path.resolve(__dirname, 'contracts', contractFileName)
13
+ const source = fs.readFileSync(contractPath, 'utf8')
14
+ return source
15
+ }
16
+
17
+ let sources = {}
18
+
19
+ fs.readdirSync(sourceFolderPath).forEach((contractFileName: string) => {
20
+ sources = {
21
+ ...sources,
22
+ [contractFileName]: {
23
+ content: getContractSource(contractFileName),
24
+ },
25
+ }
26
+ })
27
+ // console.log(sources);
28
+
29
+ function convertToHex(inputString: string) {
30
+ let hex = ''
31
+ for (let i = 0; i < inputString.length; i++) {
32
+ hex += '' + inputString.charCodeAt(i).toString(16)
33
+ }
34
+ return hex
35
+ }
36
+
37
+ const sourceHash = ethers.utils.sha256(
38
+ '0x' + convertToHex(JSON.stringify(sources)),
39
+ )
40
+
41
+ console.log('\n'.repeat(process.stdout.rows))
42
+
43
+ if (
44
+ fs.existsSync(buildFolderPath) &&
45
+ fs.existsSync(lastSourceHashFilePath) &&
46
+ JSON.parse(fs.readFileSync(lastSourceHashFilePath, 'utf8')).sourceHash ===
47
+ sourceHash
48
+ ) {
49
+ console.log(
50
+ 'No changes in .sol files detected... \nSkiping compile script...\n',
51
+ )
52
+ } else {
53
+ // write the source hash there at the end of
54
+ // console.log(lastSourceHash,sourceHash);
55
+
56
+ const input = {
57
+ language: 'Solidity',
58
+ sources,
59
+ settings: {
60
+ outputSelection: {
61
+ '*': {
62
+ '*': ['*'],
63
+ },
64
+ },
65
+ },
66
+ }
67
+
68
+ console.log('Compiling contracts...')
69
+ const output = JSON.parse(solc.compile(JSON.stringify(input))) as any
70
+ console.log('Done')
71
+
72
+ let shouldBuild = true
73
+
74
+ if (output.errors) {
75
+ // console.error(output.errors);
76
+ for (const error of output.errors) {
77
+ console.log('-'.repeat(process.stdout.columns))
78
+ console.group(error.severity.toUpperCase())
79
+ console.log(error.formattedMessage)
80
+ console.groupEnd()
81
+ }
82
+ if (Object.values(output.errors).length)
83
+ console.log('-'.repeat(process.stdout.columns))
84
+ // throw '\nError in compilation please check the contract\n';
85
+ for (const error of output.errors) {
86
+ if (error.severity === 'error') {
87
+ shouldBuild = false
88
+ throw 'Error found\n'
89
+ break
90
+ }
91
+ }
92
+ }
93
+
94
+ if (shouldBuild) {
95
+ console.log('\nBuilding please wait...')
96
+
97
+ fs.removeSync(buildFolderPath)
98
+ fs.ensureDirSync(buildFolderPath)
99
+
100
+ let i = 0
101
+ for (const contractFile in output.contracts) {
102
+ for (const key in output.contracts[contractFile]) {
103
+ console.log(key, path.resolve(buildFolderPath, `${key}.json`))
104
+ fs.outputJsonSync(
105
+ path.resolve(buildFolderPath, `${key}.json`),
106
+ output.contracts[contractFile][key],
107
+ )
108
+ }
109
+ i++
110
+ }
111
+ console.log('Build finished successfully!\n')
112
+ } else {
113
+ console.log('\nBuild failed\n')
114
+ }
115
+
116
+ fs.outputJsonSync(path.resolve(lastSourceHashFilePath), { sourceHash })
117
+ }
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import DidRegistryContract from './artifacts/PolygonDidRegistry.json'
2
+
3
+ export default DidRegistryContract
package/package.json CHANGED
@@ -1,33 +1,42 @@
1
1
  {
2
2
  "name": "@ayanworks/polygon-did-registry-contract",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-alpha.1",
4
4
  "description": "Smart Contract to register DID on Polygon",
5
- "main": "build/contracts/PolygonDidRegistry.json",
5
+ "main": "build/index.js",
6
6
  "directories": {
7
7
  "test": "test"
8
8
  },
9
9
  "scripts": {
10
- "compile": "node compile.js",
11
10
  "deploy": "node deploy.js",
12
- "test": "node compile.js && mocha --timeout 30000"
11
+ "test": "node compile.js && mocha --timeout 30000",
12
+ "clean": "rm -rf build",
13
+ "clean:deps": "pnpm clean && rm -rf node_modules",
14
+ "build": "pnpm build:sol && tsc",
15
+ "build:sol": "node --require ts-node/register ./compile.ts",
16
+ "prettier": "prettier --ignore-path .gitignore .",
17
+ "check-format": "pnpm prettier --list-different",
18
+ "check-types": "pnpm build --noEmit",
19
+ "format": "pnpm prettier --write",
20
+ "release": "release-it"
13
21
  },
14
22
  "license": "MIT",
15
- "dependencies": {
16
- "@openzeppelin/contracts": "^4.7.0",
23
+ "devDependencies": {
24
+ "@openzeppelin/truffle-upgrades": "^1.15.0",
17
25
  "@truffle/hdwallet-provider": "^2.0.10",
26
+ "@types/fs-extra": "^11.0.1",
27
+ "@types/node": "^18.17.0",
18
28
  "dotenv": "^16.0.2",
19
29
  "eslint": "^8.23.1",
20
- "fs-extra": "8.1.0",
30
+ "ethers": "^5.6.9",
31
+ "fs-extra": "^11.1.1",
21
32
  "ganache-cli": "6.12.2",
22
33
  "mocha": "^7.0.0",
23
- "solc": "0.8.0",
24
- "truffle": "^5.5.20"
25
- },
26
- "devDependencies": {
27
- "@openzeppelin/truffle-upgrades": "^1.15.0",
28
- "chai": "^4.3.6",
29
- "ethers": "^5.6.9",
30
- "truffle": "^5.5.20"
34
+ "prettier": "^3.0.2",
35
+ "release-it": "^16.1.5",
36
+ "solc": "^0.8.21",
37
+ "truffle": "^5.5.20",
38
+ "ts-node": "^10.9.1",
39
+ "typescript": "^5.1.6"
31
40
  },
32
41
  "repository": {
33
42
  "type": "git",
package/sst-config.json CHANGED
@@ -1 +1 @@
1
- {"sourceHash":"0xc8790162aa577d0b4d7d5c07565d0921f14a5fd07e896fb2cafd79ec8317eb54"}
1
+ {"sourceHash":"0xd34bb18b8a1a061e975b0850a1887bacdf0b8891d51e51399492bb038c05ff96"}
@@ -0,0 +1,399 @@
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(
9
+ ganache.provider({ gasLimit: 8000000 })
10
+ )
11
+ // Initializing the build files
12
+ const PolygonDIDRegistryJSON = require("../build/contracts/PolygonDidRegistry.json")
13
+
14
+ let accounts,
15
+ PolygonDIDRegistryInstance,
16
+ PolygonDIDRegistryInstance_test,
17
+ PolygonUpgradableInstance,
18
+ PolygonUpgradableInstance_test
19
+
20
+ // Describing the 1st Test
21
+ // This will setup Ganache with some test address
22
+ describe("Ganache Setup", async () => {
23
+ it("Ganache setup with Test Accounts", async () => {
24
+ // List of accounts are fetched here
25
+ accounts = await provider.listAccounts()
26
+
27
+ // We will check that atleast 2 accounts are loaded
28
+ assert.ok(accounts.length >= 1, "2 Accounts are present minimum")
29
+ })
30
+ })
31
+
32
+ // Upgradable with Proxy
33
+ // Deployment Testing 1.0
34
+ describe("Setting up the Upgradable Smart Contract", async () => {
35
+ describe("Setting up the contract", async () => {
36
+ it("Should deploy contract with Proxy, with no parameters/Constructor", async () => {
37
+ PolygonUpgradableInstance = await deployProxy(PolygonDidRegistry)
38
+ PolygonUpgradableInstance_test = new ethers.Contract(
39
+ PolygonUpgradableInstance.address,
40
+ PolygonDIDRegistryJSON.abi,
41
+ provider.getSigner(accounts[3])
42
+ )
43
+ assert.ok(
44
+ PolygonUpgradableInstance.address,
45
+ "Upgradeable contract is deployed"
46
+ )
47
+ })
48
+ })
49
+
50
+ //Check Create Function test 1.1
51
+ describe("Checking the Create function using Upgradeable Contract", async () => {
52
+ it("This should store the DID doc on Upgradable Contract and will read and check if the value stored is correct", async () => {
53
+ // This will send the value to local ganache blockchain
54
+ const did = "0x2f65b747440deaf596892dfc7965040be8b99100"
55
+ const doc =
56
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
57
+ const tx = await PolygonUpgradableInstance.createDID(did, doc)
58
+
59
+ // Getting the set value in ganache blockchain
60
+ const currentValue = await PolygonUpgradableInstance.getDID(did)
61
+
62
+ // Comparing the set value to confirm
63
+ assert.equal(currentValue, doc, "value set must be able to get")
64
+
65
+ assert.notEqual(currentValue, null, "value should not be empty")
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
+ const currentValue =
73
+ await PolygonUpgradableInstance.getTotalNumberOfDIDs()
74
+ assert.equal(currentValue, 1, "value should be matching")
75
+ })
76
+ })
77
+
78
+ // Describing the 1.3 Test case
79
+ describe("Checking the Update function in Upgradable Contract", async () => {
80
+ it("This should update the DID doc on Upgradable Contract and will read and check if the value stored is correct", async () => {
81
+ // This will send the value to local ganache blockchain
82
+ const did = "0x2f65b747440deaf596892dfc7965040be8b99100"
83
+ //changed the controller
84
+ const doc =
85
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
86
+ const tx = await PolygonUpgradableInstance.updateDID(did, doc)
87
+
88
+ // Getting the set value in ganache blockchain
89
+ const currentValue = await PolygonUpgradableInstance.getDID(did)
90
+
91
+ // Comparing the set value to confirm
92
+ assert.equal(currentValue, doc, "value set must be able to get")
93
+ })
94
+ })
95
+
96
+ //Describing test 1.4 to check if test fails if we update with different controller
97
+ describe("Checking update with wrong controller", async () => {
98
+ it("This should not update DID doc ", async () => {
99
+ const did = "0x2f65b747440deaf596892dfc7965040be8b99100"
100
+ const doc =
101
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
102
+ try {
103
+ assert.ifError(
104
+ //sending transaction using different controller
105
+ await PolygonUpgradableInstance_test.functions.updateDID(did, doc)
106
+ )
107
+ } catch (error) {}
108
+ })
109
+ })
110
+
111
+ // Describing the 1.5 Test case
112
+ describe("Checking the Delete function in Upgradable Contract", async () => {
113
+ it("This should delete the DID doc on Upgradable Contract and will read and check if the value is now an empty string", async () => {
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(currentValue, "", "value should be matching")
123
+ })
124
+ })
125
+
126
+ // Describing the 1.6 Test case
127
+ describe("Checking the Create function in Upgradable Contract", async () => {
128
+ it("This should store the DID doc on Upgradable Contract and will read and check if the value stored is not null", async () => {
129
+ // This will send the value to local ganache blockchain
130
+ const did = "0x54ec7be8b24f7139f870f277cf99c527ff43892b"
131
+ const doc =
132
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","verificationMethod":[{"id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","publicKeyBase58":"RwHysxjkzFdJDqi2irHRVRFHX9uUj5aVAXVoufnk5PDA4qcn1ejJMgGhqCsFdQqXRCTdi4TbEQFJjDUAdi2JvYmH"}]}'
133
+ const doctest =
134
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
135
+ const tx = await PolygonUpgradableInstance.createDID(did, doc)
136
+
137
+ // Getting the set value in ganache blockchain
138
+ const currentValue = await PolygonUpgradableInstance.getDID(did)
139
+
140
+ // Checking value is not null
141
+
142
+ assert.notEqual(currentValue, "", "value should not match")
143
+ })
144
+ })
145
+
146
+ // Describing the 1.7 Test case
147
+ describe("Checking the Update function in Upgradable Contract", async () => {
148
+ it("This should update the DID doc on Upgradable Contract and will read and check if the value stored has changed", async () => {
149
+ // This will send the value to local ganache blockchain
150
+ const did = "0x54ec7be8b24f7139f870f277cf99c527ff43892b"
151
+ //changed the controller
152
+ const doc =
153
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
154
+ const docoriginal =
155
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","verificationMethod":[{"id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","publicKeyBase58":"RwHysxjkzFdJDqi2irHRVRFHX9uUj5aVAXVoufnk5PDA4qcn1ejJMgGhqCsFdQqXRCTdi4TbEQFJjDUAdi2JvYmH"}]}'
156
+ const tx = await PolygonUpgradableInstance.updateDID(did, doc)
157
+
158
+ // Getting the set value in ganache blockchain
159
+ const currentValue = await PolygonUpgradableInstance.getDID(did)
160
+
161
+ // Comparing the set value to confirm
162
+ assert.notEqual(currentValue, docoriginal, "value should not match")
163
+ })
164
+ })
165
+
166
+ // Describing the 1.8 Test Case
167
+ describe("Checking the Delete function in Upgradable Contract", async () => {
168
+ 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 () => {
169
+ // This will send the value to local ganache blockchain
170
+ const did = "0x54ec7be8b24f7139f870f277cf99c527ff43892b"
171
+ const doc =
172
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
173
+ const tx = await PolygonUpgradableInstance.deleteDID(did)
174
+
175
+ // Getting the set value in ganache blockchain
176
+ const currentValue = await PolygonUpgradableInstance.getDID(did)
177
+
178
+ // Comparing the set value to confirm
179
+ assert.notEqual(currentValue, doc, "value should not be matching")
180
+ })
181
+ })
182
+
183
+ //Describing the 1.9 Test Case
184
+ describe("Checking the getTotalNumberOfDIDs Function", async () => {
185
+ it("This should get correct number of DIDs registered", async () => {
186
+ const totalValue = await PolygonUpgradableInstance.getTotalNumberOfDIDs()
187
+ const deltedValue =
188
+ await PolygonUpgradableInstance.getTotalNumberOfDeletedDIDs()
189
+ const currentValue = totalValue - deltedValue
190
+ assert.equal(currentValue, 0, "value should be matching")
191
+ })
192
+ })
193
+
194
+ //Describing the 1.10 Test Case
195
+ describe("Checking the Transafer Ownership Function", async () => {
196
+ it("This should transfer ownership of contract to another user", async () => {
197
+ const newOwner = accounts[5]
198
+ const owner = await PolygonUpgradableInstance.getOwner()
199
+ const tx = await PolygonUpgradableInstance.transferOwnership(newOwner)
200
+ const currentOwner = await PolygonUpgradableInstance.getOwner()
201
+
202
+ assert.notEqual(owner, currentOwner, "value should not be equal")
203
+ })
204
+ })
205
+
206
+ //Describing the 1.11 Test Case
207
+ describe("Checking the Transafer Ownership Function", async () => {
208
+ it("This should not transfer ownership of contract to another user since the transaction is being initiated by different owner", async () => {
209
+ const newOwner = accounts[6]
210
+ try {
211
+ assert.ifError(
212
+ //sending transaction using different controller
213
+ await PolygonUpgradableInstance_test.functions.transferOwnership(
214
+ newOwner
215
+ )
216
+ )
217
+ } catch (error) {}
218
+ })
219
+ })
220
+ })
221
+
222
+ // basic Contract Testing
223
+ // Deployment Testing 2.0
224
+ describe("Basic Contract Testing", async () => {
225
+ // Describing a SubTest case
226
+ describe("Setting up the contract", async () => {
227
+ it("This Deploys Polygon Smart contract from 1st account with no Parameters/Constructor", async () => {
228
+ // Creating a contract factory for deploying contract.
229
+ const PolygonDIDRegistry = new ethers.ContractFactory(
230
+ PolygonDIDRegistryJSON.abi,
231
+ PolygonDIDRegistryJSON.bytecode,
232
+ provider.getSigner(accounts[2])
233
+ )
234
+ PolygonDIDRegistryInstance = await PolygonDIDRegistry.deploy()
235
+ PolygonDIDRegistryInstance_test = new ethers.Contract(
236
+ PolygonDIDRegistryInstance.address,
237
+ PolygonDIDRegistryJSON.abi,
238
+ provider.getSigner(accounts[3])
239
+ )
240
+ assert.ok(
241
+ PolygonDIDRegistryInstance.address,
242
+ "conract address should be present"
243
+ )
244
+ })
245
+ })
246
+
247
+ // Describing the 2.1 Test case
248
+ describe("Checking the Create function in Contract", async () => {
249
+ it("This should store the DID doc on Contract and will read and check if the value stored is correct", async () => {
250
+ // This will send the value to local ganache blockchain
251
+ const did = "0x2f65b747440deaf596892dfc7965040be8b99100"
252
+ const doc =
253
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
254
+ const tx = await PolygonDIDRegistryInstance.functions.createDID(did, doc)
255
+
256
+ // Transfer confirmation
257
+ await tx.wait()
258
+
259
+ // Getting the set value in ganache blockchain
260
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(
261
+ did
262
+ )
263
+
264
+ // Comparing the set value to confirm
265
+ assert.equal(currentValue, doc, "value set must be able to get")
266
+
267
+ assert.notEqual(currentValue, null, "value should not be empty")
268
+ })
269
+ })
270
+
271
+ // Describing the 2.2 Test case
272
+ describe("Checking the Update function in Contract", async () => {
273
+ it("This should update the DID doc on Contract and will read and check if the value stored is correct", async () => {
274
+ // This will send the value to local ganache blockchain
275
+ const did = "0x2f65b747440deaf596892dfc7965040be8b99100"
276
+ //changed the controller
277
+ const doc =
278
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
279
+ const tx = await PolygonDIDRegistryInstance.functions.updateDID(did, doc)
280
+
281
+ // Transfer confirmation
282
+ await tx.wait()
283
+
284
+ // Getting the set value in ganache blockchain
285
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(
286
+ did
287
+ )
288
+
289
+ // Comparing the set value to confirm
290
+ assert.equal(currentValue, doc, "value set must be able to get")
291
+ })
292
+ })
293
+ //Describing test 2.3 to check if test fails if we update with different controller
294
+ describe("Checking update with wrong controller", async () => {
295
+ it("This should not update DID doc ", async () => {
296
+ const did = "0x2f65b747440deaf596892dfc7965040be8b99100"
297
+ const doc =
298
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
299
+ try {
300
+ assert.ifError(
301
+ //sending transaction using different controller
302
+ await PolygonDIDRegistryInstance_test.functions.updateDID(did, doc)
303
+ )
304
+ } catch (error) {}
305
+ })
306
+ })
307
+
308
+ // Describing the 2.4 Test case
309
+ describe("Checking the Delete function in Contract", async () => {
310
+ it("This should delete the DID doc on Contract and will read and check if the value is now an empty string", async () => {
311
+ // This will send the value to local ganache blockchain
312
+ const did = "0x2f65b747440deaf596892dfc7965040be8b99100"
313
+ const tx = await PolygonDIDRegistryInstance.functions.deleteDID(did)
314
+
315
+ // Transfer confirmation
316
+ await tx.wait()
317
+
318
+ // Getting the set value in ganache blockchain
319
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(
320
+ did
321
+ )
322
+
323
+ // Comparing the set value to confirm
324
+ assert.equal(currentValue, "", "value should be matching")
325
+ })
326
+ })
327
+
328
+ // Describing the 2.5 Test case
329
+ describe("Checking the Create function in Contract", async () => {
330
+ it("This should store the DID doc on Contract and will read and check if the value stored is not null", async () => {
331
+ // This will send the value to local ganache blockchain
332
+ const did = "0x54ec7be8b24f7139f870f277cf99c527ff43892b"
333
+ const doc =
334
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","verificationMethod":[{"id":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x54ec7be8b24f7139f870f277cf99c527ff43892b","publicKeyBase58":"RwHysxjkzFdJDqi2irHRVRFHX9uUj5aVAXVoufnk5PDA4qcn1ejJMgGhqCsFdQqXRCTdi4TbEQFJjDUAdi2JvYmH"}]}'
335
+ const doctest =
336
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
337
+ const tx = await PolygonDIDRegistryInstance.functions.createDID(did, doc)
338
+
339
+ // Transfer confirmation
340
+ await tx.wait()
341
+
342
+ // Getting the set value in ganache blockchain
343
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(
344
+ did
345
+ )
346
+
347
+ // Checking value is not null
348
+
349
+ assert.notEqual(currentValue, doctest, "value should not match")
350
+ })
351
+ })
352
+
353
+ // Describing the 2.6 Test case
354
+ describe("Checking the Update function in Contract", async () => {
355
+ it("This should update the DID doc on Contract and will read and check if the value stored has changed", async () => {
356
+ // This will send the value to local ganache blockchain
357
+ const did = "0x54ec7be8b24f7139f870f277cf99c527ff43892b"
358
+ //changed the controller
359
+ const doc =
360
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
361
+ const docoriginal =
362
+ '{"@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 tx = await PolygonDIDRegistryInstance.functions.updateDID(did, doc)
364
+
365
+ // Transfer confirmation
366
+ await tx.wait()
367
+
368
+ // Getting the set value in ganache blockchain
369
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(
370
+ did
371
+ )
372
+
373
+ // Comparing the set value to confirm
374
+ assert.notEqual(currentValue, docoriginal, "value should not match")
375
+ })
376
+ })
377
+
378
+ // Describing the 2.7 Test case
379
+ describe("Checking the Delete function in Contract", async () => {
380
+ 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 () => {
381
+ // This will send the value to local ganache blockchain
382
+ const did = "0x54ec7be8b24f7139f870f277cf99c527ff43892b"
383
+ const doc =
384
+ '{"@context":"https://w3id.org/did/v1","id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","verificationMethod":[{"id":"did:polygon:0x2f65b747440deaf596892dfc7965040be8b99100","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:polygon:0x2f65b747440deaf596892dfc7965040be8c66666","publicKeyBase58":"NDaEdTguJV39Ns8BZkxQ3XR6GUinZAJfVoyEMkK9fP7XQmpSkT3UsLHB52cFpDqoM6m4Hevtba8pkmjvEG3Ur7ji"}]}'
385
+ const tx = await PolygonDIDRegistryInstance.functions.deleteDID(did)
386
+
387
+ // Transfer confirmation
388
+ await tx.wait()
389
+
390
+ // Getting the set value in ganache blockchain
391
+ const currentValue = await PolygonDIDRegistryInstance.functions.getDID(
392
+ did
393
+ )
394
+
395
+ // Comparing the set value to confirm
396
+ assert.notEqual(currentValue, doc, "value should not be matching")
397
+ })
398
+ })
399
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "build",
4
+ "target": "es2016",
5
+ "module": "commonjs",
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "strict": true,
9
+ "declaration": true,
10
+ "sourceMap": true,
11
+ "resolveJsonModule": true
12
+ },
13
+ "exclude": ["tests", "compile.ts"]
14
+ }