@dashevo/dpns-contract 0.4.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/.eslintrc +15 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +26 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +32 -0
- package/.github/workflows/test_and_release.yml +83 -0
- package/.mocharc.yml +3 -0
- package/LICENSE +20 -0
- package/README.md +33 -0
- package/package.json +44 -0
- package/schema/dpns-contract-documents.json +141 -0
- package/test/.eslintrc +12 -0
- package/test/bootstrap.js +22 -0
- package/test/unit/dpnsContract.spec.js +709 -0
package/.eslintrc
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: ''
|
|
5
|
+
labels: 'bug'
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<!--- Provide a general summary of the issue in the Title above -->
|
|
11
|
+
|
|
12
|
+
## Expected Behavior
|
|
13
|
+
<!--- Tell us what should happen -->
|
|
14
|
+
|
|
15
|
+
## Current Behavior
|
|
16
|
+
<!--- Tell us what happens instead of the expected behavior -->
|
|
17
|
+
|
|
18
|
+
## Possible Solution
|
|
19
|
+
<!--- Not obligatory, but suggest a fix/reason for the bug -->
|
|
20
|
+
|
|
21
|
+
## Steps to Reproduce (for bugs)
|
|
22
|
+
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
|
23
|
+
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
|
24
|
+
1.
|
|
25
|
+
2.
|
|
26
|
+
3.
|
|
27
|
+
4.
|
|
28
|
+
|
|
29
|
+
## Context
|
|
30
|
+
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
|
31
|
+
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
|
32
|
+
|
|
33
|
+
## Your Environment
|
|
34
|
+
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
|
35
|
+
* Version used:
|
|
36
|
+
* Environment name and version (e.g. Chrome 39, node.js 5.4):
|
|
37
|
+
* Operating System and version (desktop, server, or mobile):
|
|
38
|
+
* Link to your project:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an idea for this project
|
|
4
|
+
title: ''
|
|
5
|
+
labels: 'enhancement'
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<!--- Provide a general summary of the feature request in the Title above -->
|
|
11
|
+
|
|
12
|
+
## Expected Behavior
|
|
13
|
+
<!--- A clear and concise description of what you want to happen -->
|
|
14
|
+
|
|
15
|
+
## Current Behavior
|
|
16
|
+
<!--- Explain the difference from current behavior -->
|
|
17
|
+
|
|
18
|
+
## Possible Solution
|
|
19
|
+
<!--- Suggest ideas of how to implement the addition or change -->
|
|
20
|
+
|
|
21
|
+
## Alternatives Considered
|
|
22
|
+
<!--- A clear and concise description of any alternative solutions or features you've considered -->
|
|
23
|
+
|
|
24
|
+
## Additional Context
|
|
25
|
+
<!--- Add any other context or screenshots about the feature request here. -->
|
|
26
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!--- Provide a general summary of your changes in the Title above -->
|
|
2
|
+
<!--- Pull request titles must use the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) format -->
|
|
3
|
+
|
|
4
|
+
## Issue being fixed or feature implemented
|
|
5
|
+
<!--- Why is this change required? What problem does it solve? -->
|
|
6
|
+
<!--- If it fixes an open issue, please link to the issue here. -->
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## What was done?
|
|
10
|
+
<!--- Describe your changes in detail -->
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## How Has This Been Tested?
|
|
14
|
+
<!--- Please describe in detail how you tested your changes. -->
|
|
15
|
+
<!--- Include details of your testing environment, and the tests you ran to -->
|
|
16
|
+
<!--- see how your change affects other areas of the code, etc. -->
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Breaking Changes
|
|
20
|
+
<!--- Please describe any breaking changes your code introduces and verify that -->
|
|
21
|
+
<!--- the title includes "!" following the conventional commit type (e.g. "feat!: ..."-->
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Checklist:
|
|
25
|
+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
|
26
|
+
- [ ] I have performed a self-review of my own code
|
|
27
|
+
- [ ] I have commented my code, particularly in hard-to-understand areas
|
|
28
|
+
- [ ] I have added or updated relevant unit/integration/functional/e2e tests
|
|
29
|
+
- [ ] I have made corresponding changes to the documentation
|
|
30
|
+
|
|
31
|
+
**For repository code-owners and collaborators only**
|
|
32
|
+
- [ ] I have assigned this pull request to a milestone
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
name: Test and Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
release:
|
|
6
|
+
types:
|
|
7
|
+
- published
|
|
8
|
+
pull_request:
|
|
9
|
+
branches:
|
|
10
|
+
- master
|
|
11
|
+
- v[0-9]+.[0-9]+-dev
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
name: Run DPNS Contract tests
|
|
16
|
+
runs-on: ubuntu-20.04
|
|
17
|
+
timeout-minutes: 10
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v2
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-node@v2
|
|
22
|
+
with:
|
|
23
|
+
node-version: '16'
|
|
24
|
+
|
|
25
|
+
- name: Enable NPM cache
|
|
26
|
+
uses: actions/cache@v2
|
|
27
|
+
with:
|
|
28
|
+
path: '~/.npm'
|
|
29
|
+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
30
|
+
restore-keys: |
|
|
31
|
+
${{ runner.os }}-node-
|
|
32
|
+
|
|
33
|
+
- name: Check NPM package lock version is updated
|
|
34
|
+
uses: dashevo/gh-action-check-package-lock@v1
|
|
35
|
+
|
|
36
|
+
- name: Install NPM dependencies
|
|
37
|
+
run: npm ci
|
|
38
|
+
|
|
39
|
+
- name: Run ESLinter
|
|
40
|
+
run: npm run lint
|
|
41
|
+
|
|
42
|
+
- name: Run tests
|
|
43
|
+
run: npm run test
|
|
44
|
+
|
|
45
|
+
release:
|
|
46
|
+
name: Release NPM package
|
|
47
|
+
runs-on: ubuntu-20.04
|
|
48
|
+
needs: test
|
|
49
|
+
if: ${{ github.event_name == 'release' }}
|
|
50
|
+
steps:
|
|
51
|
+
- uses: actions/checkout@v2
|
|
52
|
+
|
|
53
|
+
- name: Check package version matches tag
|
|
54
|
+
uses: geritol/match-tag-to-package-version@0.1.0
|
|
55
|
+
env:
|
|
56
|
+
TAG_PREFIX: refs/tags/v
|
|
57
|
+
|
|
58
|
+
- name: Enable NPM cache
|
|
59
|
+
uses: actions/cache@v2
|
|
60
|
+
with:
|
|
61
|
+
path: '~/.npm'
|
|
62
|
+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
63
|
+
restore-keys: |
|
|
64
|
+
${{ runner.os }}-node-
|
|
65
|
+
|
|
66
|
+
- name: Install NPM dependencies
|
|
67
|
+
run: npm ci
|
|
68
|
+
|
|
69
|
+
- name: Set release tag
|
|
70
|
+
uses: actions/github-script@v3
|
|
71
|
+
id: tag
|
|
72
|
+
with:
|
|
73
|
+
result-encoding: string
|
|
74
|
+
script: |
|
|
75
|
+
const tag = context.payload.release.tag_name;
|
|
76
|
+
const [, major, minor] = tag.match(/^v([0-9]+)\.([0-9]+)/);
|
|
77
|
+
return (tag.includes('dev') ? `${major}.${minor}-dev` : 'latest');
|
|
78
|
+
|
|
79
|
+
- name: Publish NPM package
|
|
80
|
+
uses: JS-DevTools/npm-publish@v1
|
|
81
|
+
with:
|
|
82
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
83
|
+
tag: ${{ steps.tag.outputs.result }}
|
package/.mocharc.yml
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Dash Core Group, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# DPNS Contract
|
|
2
|
+
|
|
3
|
+
[](https://github.com/dashevo/dpns-contract/actions/workflows/test_and_release.yml)
|
|
4
|
+
[](https://npmjs.org/package/@dashevo/dpns-contract)
|
|
5
|
+
|
|
6
|
+
JSON Contracts for Dash Platform Name Service
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
- [Install](#install)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Contributing](#contributing)
|
|
13
|
+
- [License](#license)
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @dashevo/dpns-contract
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
# TODO ...
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Contributing
|
|
28
|
+
|
|
29
|
+
Feel free to dive in! [Open an issue](https://github.com/dashevo/dpns-contract/issues/new) or submit PRs.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
[MIT](LICENSE) © Dash Core Group, Inc.
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dashevo/dpns-contract",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "A contract and helper scripts for DPNS DApp",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"lint": "eslint .",
|
|
7
|
+
"test": "npm run test:unit",
|
|
8
|
+
"test:unit": "mocha 'test/unit/**/*.spec.js'"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "Ivan Shumkov",
|
|
13
|
+
"email": "ivan@shumkov.ru",
|
|
14
|
+
"url": "https://github.com/shumkov"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "Djavid Gabibiyan",
|
|
18
|
+
"email": "djavid@dash.org",
|
|
19
|
+
"url": "https://github.com/jawid-h"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "Anton Suprunchuk",
|
|
23
|
+
"email": "anton.suprunchuk@dash.org",
|
|
24
|
+
"url": "https://github.com/antouhou"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "Konstantin Shuplenkov",
|
|
28
|
+
"email": "konstantin.shuplenkov@dash.org",
|
|
29
|
+
"url": "https://github.com/shuplenkov"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@dashevo/dpp": "~0.21.0-dev.5",
|
|
35
|
+
"chai": "^4.2.0",
|
|
36
|
+
"dirty-chai": "^2.0.1",
|
|
37
|
+
"eslint": "^6.7.2",
|
|
38
|
+
"eslint-config-airbnb-base": "^14.0.0",
|
|
39
|
+
"eslint-plugin-import": "^2.19.1",
|
|
40
|
+
"mocha": "^8.1.1",
|
|
41
|
+
"sinon": "^8.0.1",
|
|
42
|
+
"sinon-chai": "^3.4.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
{
|
|
2
|
+
"domain": {
|
|
3
|
+
"type": "object",
|
|
4
|
+
"indices": [
|
|
5
|
+
{
|
|
6
|
+
"properties": [
|
|
7
|
+
{
|
|
8
|
+
"normalizedParentDomainName": "asc"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"normalizedLabel": "asc"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"unique": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"properties": [
|
|
18
|
+
{
|
|
19
|
+
"records.dashUniqueIdentityId": "asc"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"unique": true
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"properties": [
|
|
26
|
+
{
|
|
27
|
+
"records.dashAliasIdentityId": "asc"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"properties": {
|
|
33
|
+
"label": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]$",
|
|
36
|
+
"minLength": 3,
|
|
37
|
+
"maxLength": 63,
|
|
38
|
+
"description": "Domain label. e.g. 'Bob'."
|
|
39
|
+
},
|
|
40
|
+
"normalizedLabel": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"pattern": "^[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$",
|
|
43
|
+
"maxLength": 63,
|
|
44
|
+
"description": "Domain label in lowercase for case-insensitive uniqueness validation. e.g. 'bob'",
|
|
45
|
+
"$comment": "Must be equal to the label in lowercase. This property will be deprecated due to case insensitive indices"
|
|
46
|
+
},
|
|
47
|
+
"normalizedParentDomainName": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"pattern": "^$|^[[a-z0-9][a-z0-9-\\.]{0,188}[a-z0-9]$",
|
|
50
|
+
"minLength": 0,
|
|
51
|
+
"maxLength": 190,
|
|
52
|
+
"description": "A full parent domain name in lowercase for case-insensitive uniqueness validation. e.g. 'dash'",
|
|
53
|
+
"$comment": "Must either be equal to an existing domain or empty to create a top level domain. Only the data contract owner can create top level domains."
|
|
54
|
+
},
|
|
55
|
+
"preorderSalt": {
|
|
56
|
+
"type": "array",
|
|
57
|
+
"byteArray": true,
|
|
58
|
+
"minItems": 32,
|
|
59
|
+
"maxItems": 32,
|
|
60
|
+
"description": "Salt used in the preorder document"
|
|
61
|
+
},
|
|
62
|
+
"records": {
|
|
63
|
+
"type": "object",
|
|
64
|
+
"properties": {
|
|
65
|
+
"dashUniqueIdentityId": {
|
|
66
|
+
"type": "array",
|
|
67
|
+
"byteArray": true,
|
|
68
|
+
"minItems": 32,
|
|
69
|
+
"maxItems": 32,
|
|
70
|
+
"contentMediaType": "application/x.dash.dpp.identifier",
|
|
71
|
+
"description": "Identity ID to be used to create the primary name the Identity",
|
|
72
|
+
"$comment": "Must be equal to the document owner"
|
|
73
|
+
},
|
|
74
|
+
"dashAliasIdentityId": {
|
|
75
|
+
"type": "array",
|
|
76
|
+
"byteArray": true,
|
|
77
|
+
"minItems": 32,
|
|
78
|
+
"maxItems": 32,
|
|
79
|
+
"contentMediaType": "application/x.dash.dpp.identifier",
|
|
80
|
+
"description": "Identity ID to be used to create alias names for the Identity",
|
|
81
|
+
"$comment": "Must be equal to the document owner"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"$comment": "Constraint with max and min properties ensure that only one identity record is used - either a `dashUniqueIdentityId` or a `dashAliasIdentityId`",
|
|
85
|
+
"minProperties": 1,
|
|
86
|
+
"maxProperties": 1,
|
|
87
|
+
"additionalProperties": false
|
|
88
|
+
},
|
|
89
|
+
"subdomainRules": {
|
|
90
|
+
"type": "object",
|
|
91
|
+
"properties": {
|
|
92
|
+
"allowSubdomains": {
|
|
93
|
+
"type": "boolean",
|
|
94
|
+
"description": "This option defines who can create subdomains: true - anyone; false - only the domain owner",
|
|
95
|
+
"$comment": "Only the domain owner is allowed to create subdomains for non top-level domains"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"description": "Subdomain rules allow domain owners to define rules for subdomains",
|
|
99
|
+
"additionalProperties": false,
|
|
100
|
+
"required": ["allowSubdomains"]
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"required": [
|
|
104
|
+
"label",
|
|
105
|
+
"normalizedLabel",
|
|
106
|
+
"normalizedParentDomainName",
|
|
107
|
+
"preorderSalt",
|
|
108
|
+
"records",
|
|
109
|
+
"subdomainRules"
|
|
110
|
+
],
|
|
111
|
+
"additionalProperties": false,
|
|
112
|
+
"$comment": "In order to register a domain you need to create a preorder. The preorder step is needed to prevent man-in-the-middle attacks. normalizedLabel + '.' + normalizedParentDomain must not be longer than 253 chars length as defined by RFC 1035. Domain documents are immutable: modification and deletion are restricted"
|
|
113
|
+
},
|
|
114
|
+
"preorder": {
|
|
115
|
+
"type": "object",
|
|
116
|
+
"indices": [
|
|
117
|
+
{
|
|
118
|
+
"properties": [
|
|
119
|
+
{
|
|
120
|
+
"saltedDomainHash": "asc"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"unique": true
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"properties": {
|
|
127
|
+
"saltedDomainHash": {
|
|
128
|
+
"type": "array",
|
|
129
|
+
"byteArray": true,
|
|
130
|
+
"minItems": 32,
|
|
131
|
+
"maxItems": 32,
|
|
132
|
+
"description": "Double sha-256 of the concatenation of a 32 byte random salt and a normalized domain name"
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
"required": [
|
|
136
|
+
"saltedDomainHash"
|
|
137
|
+
],
|
|
138
|
+
"additionalProperties": false,
|
|
139
|
+
"$comment": "Preorder documents are immutable: modification and deletion are restricted"
|
|
140
|
+
}
|
|
141
|
+
}
|
package/test/.eslintrc
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const sinon = require('sinon');
|
|
2
|
+
const sinonChai = require('sinon-chai');
|
|
3
|
+
|
|
4
|
+
const { expect, use } = require('chai');
|
|
5
|
+
const dirtyChai = require('dirty-chai');
|
|
6
|
+
|
|
7
|
+
use(dirtyChai);
|
|
8
|
+
use(sinonChai);
|
|
9
|
+
|
|
10
|
+
beforeEach(function beforeEach() {
|
|
11
|
+
if (!this.sinon) {
|
|
12
|
+
this.sinon = sinon.createSandbox();
|
|
13
|
+
} else {
|
|
14
|
+
this.sinon.restore();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(function afterEach() {
|
|
19
|
+
this.sinon.restore();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
global.expect = expect;
|
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
|
|
3
|
+
const DashPlatformProtocol = require('@dashevo/dpp');
|
|
4
|
+
|
|
5
|
+
const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
6
|
+
|
|
7
|
+
const dpnsContractDocumentsSchema = require('../../schema/dpns-contract-documents.json');
|
|
8
|
+
|
|
9
|
+
describe('DPNS Contract', () => {
|
|
10
|
+
let dpp;
|
|
11
|
+
let dataContract;
|
|
12
|
+
let identityId;
|
|
13
|
+
|
|
14
|
+
beforeEach(async function beforeEach() {
|
|
15
|
+
const fetchContractStub = this.sinon.stub();
|
|
16
|
+
|
|
17
|
+
dpp = new DashPlatformProtocol({
|
|
18
|
+
stateRepository: {
|
|
19
|
+
fetchDataContract: fetchContractStub,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await dpp.initialize();
|
|
24
|
+
|
|
25
|
+
identityId = generateRandomIdentifier();
|
|
26
|
+
|
|
27
|
+
dataContract = dpp.dataContract.create(identityId, dpnsContractDocumentsSchema);
|
|
28
|
+
|
|
29
|
+
fetchContractStub.resolves(dataContract);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should have a valid contract definition', async () => {
|
|
33
|
+
const validationResult = await dpp.dataContract.validate(dataContract);
|
|
34
|
+
|
|
35
|
+
expect(validationResult.isValid()).to.be.true();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('documents', () => {
|
|
39
|
+
describe('preorder', () => {
|
|
40
|
+
let rawPreorderDocument;
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
rawPreorderDocument = {
|
|
44
|
+
saltedDomainHash: crypto.randomBytes(32),
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('saltedDomainHash', () => {
|
|
49
|
+
it('should be defined', async () => {
|
|
50
|
+
delete rawPreorderDocument.saltedDomainHash;
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
54
|
+
|
|
55
|
+
expect.fail('should throw error');
|
|
56
|
+
} catch (e) {
|
|
57
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
58
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
59
|
+
|
|
60
|
+
const [error] = e.getErrors();
|
|
61
|
+
|
|
62
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
63
|
+
expect(error.keyword).to.equal('required');
|
|
64
|
+
expect(error.params.missingProperty).to.equal('saltedDomainHash');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should not be empty', async () => {
|
|
69
|
+
rawPreorderDocument.saltedDomainHash = Buffer.alloc(0);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
73
|
+
|
|
74
|
+
expect.fail('should throw error');
|
|
75
|
+
} catch (e) {
|
|
76
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
77
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
78
|
+
|
|
79
|
+
const [error] = e.getErrors();
|
|
80
|
+
|
|
81
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
82
|
+
expect(error.keyword).to.equal('minItems');
|
|
83
|
+
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should be not less than 32 bytes', async () => {
|
|
88
|
+
rawPreorderDocument.saltedDomainHash = crypto.randomBytes(10);
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
92
|
+
|
|
93
|
+
expect.fail('should throw error');
|
|
94
|
+
} catch (e) {
|
|
95
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
96
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
97
|
+
|
|
98
|
+
const [error] = e.getErrors();
|
|
99
|
+
|
|
100
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
101
|
+
expect(error.keyword).to.equal('minItems');
|
|
102
|
+
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should be not longer than 32 bytes', async () => {
|
|
107
|
+
rawPreorderDocument.saltedDomainHash = crypto.randomBytes(40);
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
111
|
+
|
|
112
|
+
expect.fail('should throw error');
|
|
113
|
+
} catch (e) {
|
|
114
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
115
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
116
|
+
|
|
117
|
+
const [error] = e.getErrors();
|
|
118
|
+
|
|
119
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
120
|
+
expect(error.keyword).to.equal('maxItems');
|
|
121
|
+
expect(error.instancePath).to.equal('/saltedDomainHash');
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should not have additional properties', async () => {
|
|
127
|
+
rawPreorderDocument.someOtherProperty = 42;
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
131
|
+
|
|
132
|
+
expect.fail('should throw error');
|
|
133
|
+
} catch (e) {
|
|
134
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
135
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
136
|
+
|
|
137
|
+
const [error] = e.getErrors();
|
|
138
|
+
|
|
139
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
140
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
141
|
+
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should be valid', async () => {
|
|
146
|
+
const preorder = dpp.document.create(dataContract, identityId, 'preorder', rawPreorderDocument);
|
|
147
|
+
|
|
148
|
+
const result = await dpp.document.validate(preorder);
|
|
149
|
+
|
|
150
|
+
expect(result.isValid()).to.be.true();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('domain', () => {
|
|
155
|
+
let rawDomainDocument;
|
|
156
|
+
|
|
157
|
+
beforeEach(() => {
|
|
158
|
+
rawDomainDocument = {
|
|
159
|
+
label: 'Wallet',
|
|
160
|
+
normalizedLabel: 'wallet',
|
|
161
|
+
normalizedParentDomainName: 'dash',
|
|
162
|
+
preorderSalt: crypto.randomBytes(32),
|
|
163
|
+
records: {
|
|
164
|
+
dashUniqueIdentityId: generateRandomIdentifier(),
|
|
165
|
+
},
|
|
166
|
+
subdomainRules: {
|
|
167
|
+
allowSubdomains: false,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('label', () => {
|
|
173
|
+
it('should be present', async () => {
|
|
174
|
+
delete rawDomainDocument.label;
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
178
|
+
|
|
179
|
+
expect.fail('should throw error');
|
|
180
|
+
} catch (e) {
|
|
181
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
182
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
183
|
+
|
|
184
|
+
const [error] = e.getErrors();
|
|
185
|
+
|
|
186
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
187
|
+
expect(error.keyword).to.equal('required');
|
|
188
|
+
expect(error.params.missingProperty).to.equal('label');
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should follow pattern', async () => {
|
|
193
|
+
rawDomainDocument.label = 'invalid label';
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
197
|
+
|
|
198
|
+
expect.fail('should throw error');
|
|
199
|
+
} catch (e) {
|
|
200
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
201
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
202
|
+
|
|
203
|
+
const [error] = e.getErrors();
|
|
204
|
+
|
|
205
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
206
|
+
expect(error.keyword).to.equal('pattern');
|
|
207
|
+
expect(error.instancePath).to.equal('/label');
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('should be longer than 3 chars', async () => {
|
|
212
|
+
rawDomainDocument.label = 'ab';
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
216
|
+
|
|
217
|
+
expect.fail('should throw error');
|
|
218
|
+
} catch (e) {
|
|
219
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
220
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
221
|
+
|
|
222
|
+
const [error] = e.getErrors();
|
|
223
|
+
|
|
224
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
225
|
+
expect(error.keyword).to.equal('minLength');
|
|
226
|
+
expect(error.instancePath).to.equal('/label');
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('should be less than 63 chars', async () => {
|
|
231
|
+
rawDomainDocument.label = 'a'.repeat(64);
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
235
|
+
|
|
236
|
+
expect.fail('should throw error');
|
|
237
|
+
} catch (e) {
|
|
238
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
239
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
240
|
+
|
|
241
|
+
const [error] = e.getErrors();
|
|
242
|
+
|
|
243
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
244
|
+
expect(error.keyword).to.equal('maxLength');
|
|
245
|
+
expect(error.instancePath).to.equal('/label');
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('normalizedLabel', () => {
|
|
251
|
+
it('should be defined', async () => {
|
|
252
|
+
delete rawDomainDocument.normalizedLabel;
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
256
|
+
|
|
257
|
+
expect.fail('should throw error');
|
|
258
|
+
} catch (e) {
|
|
259
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
260
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
261
|
+
|
|
262
|
+
const [error] = e.getErrors();
|
|
263
|
+
|
|
264
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
265
|
+
expect(error.keyword).to.equal('required');
|
|
266
|
+
expect(error.params.missingProperty).to.equal('normalizedLabel');
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should follow pattern', async () => {
|
|
271
|
+
rawDomainDocument.normalizedLabel = 'InValiD label';
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
275
|
+
|
|
276
|
+
expect.fail('should throw error');
|
|
277
|
+
} catch (e) {
|
|
278
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
279
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
280
|
+
|
|
281
|
+
const [error] = e.getErrors();
|
|
282
|
+
|
|
283
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
284
|
+
expect(error.keyword).to.equal('pattern');
|
|
285
|
+
expect(error.instancePath).to.equal('/normalizedLabel');
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('should be less than 63 chars', async () => {
|
|
290
|
+
rawDomainDocument.normalizedLabel = 'a'.repeat(64);
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
294
|
+
|
|
295
|
+
expect.fail('should throw error');
|
|
296
|
+
} catch (e) {
|
|
297
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
298
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
299
|
+
|
|
300
|
+
const [error] = e.getErrors();
|
|
301
|
+
|
|
302
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
303
|
+
expect(error.keyword).to.equal('maxLength');
|
|
304
|
+
expect(error.instancePath).to.equal('/normalizedLabel');
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe('normalizedParentDomainName', () => {
|
|
310
|
+
it('should be defined', async () => {
|
|
311
|
+
delete rawDomainDocument.normalizedParentDomainName;
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
315
|
+
|
|
316
|
+
expect.fail('should throw error');
|
|
317
|
+
} catch (e) {
|
|
318
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
319
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
320
|
+
|
|
321
|
+
const [error] = e.getErrors();
|
|
322
|
+
|
|
323
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
324
|
+
expect(error.keyword).to.equal('required');
|
|
325
|
+
expect(error.params.missingProperty).to.equal('normalizedParentDomainName');
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('should be less than 190 chars', async () => {
|
|
330
|
+
rawDomainDocument.normalizedParentDomainName = 'a'.repeat(191);
|
|
331
|
+
|
|
332
|
+
try {
|
|
333
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
334
|
+
|
|
335
|
+
expect.fail('should throw error');
|
|
336
|
+
} catch (e) {
|
|
337
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
338
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
339
|
+
|
|
340
|
+
const [error] = e.getErrors();
|
|
341
|
+
|
|
342
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
343
|
+
expect(error.keyword).to.equal('maxLength');
|
|
344
|
+
expect(error.instancePath).to.equal('/normalizedParentDomainName');
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('should follow pattern', async () => {
|
|
349
|
+
rawDomainDocument.normalizedParentDomainName = '&'.repeat(100);
|
|
350
|
+
|
|
351
|
+
try {
|
|
352
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
353
|
+
|
|
354
|
+
expect.fail('should throw error');
|
|
355
|
+
} catch (e) {
|
|
356
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
357
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
358
|
+
|
|
359
|
+
const [error] = e.getErrors();
|
|
360
|
+
|
|
361
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
362
|
+
expect(error.keyword).to.equal('pattern');
|
|
363
|
+
expect(error.instancePath).to.equal('/normalizedParentDomainName');
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
describe('preorderSalt', () => {
|
|
369
|
+
it('should be defined', async () => {
|
|
370
|
+
delete rawDomainDocument.preorderSalt;
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
374
|
+
|
|
375
|
+
expect.fail('should throw error');
|
|
376
|
+
} catch (e) {
|
|
377
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
378
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
379
|
+
|
|
380
|
+
const [error] = e.getErrors();
|
|
381
|
+
|
|
382
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
383
|
+
expect(error.keyword).to.equal('required');
|
|
384
|
+
expect(error.params.missingProperty).to.equal('preorderSalt');
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('should not be empty', async () => {
|
|
389
|
+
rawDomainDocument.preorderSalt = Buffer.alloc(0);
|
|
390
|
+
|
|
391
|
+
try {
|
|
392
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
393
|
+
|
|
394
|
+
expect.fail('should throw error');
|
|
395
|
+
} catch (e) {
|
|
396
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
397
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
398
|
+
|
|
399
|
+
const [error] = e.getErrors();
|
|
400
|
+
|
|
401
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
402
|
+
expect(error.keyword).to.equal('minItems');
|
|
403
|
+
expect(error.instancePath).to.equal('/preorderSalt');
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('should be not less than 32 bytes', async () => {
|
|
408
|
+
rawDomainDocument.preorderSalt = crypto.randomBytes(10);
|
|
409
|
+
|
|
410
|
+
try {
|
|
411
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
412
|
+
|
|
413
|
+
expect.fail('should throw error');
|
|
414
|
+
} catch (e) {
|
|
415
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
416
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
417
|
+
|
|
418
|
+
const [error] = e.getErrors();
|
|
419
|
+
|
|
420
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
421
|
+
expect(error.keyword).to.equal('minItems');
|
|
422
|
+
expect(error.instancePath).to.equal('/preorderSalt');
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it('should be not longer than 32 bytes', async () => {
|
|
427
|
+
rawDomainDocument.preorderSalt = crypto.randomBytes(40);
|
|
428
|
+
|
|
429
|
+
try {
|
|
430
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
431
|
+
|
|
432
|
+
expect.fail('should throw error');
|
|
433
|
+
} catch (e) {
|
|
434
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
435
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
436
|
+
|
|
437
|
+
const [error] = e.getErrors();
|
|
438
|
+
|
|
439
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
440
|
+
expect(error.keyword).to.equal('maxItems');
|
|
441
|
+
expect(error.instancePath).to.equal('/preorderSalt');
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('should not have additional properties', async () => {
|
|
447
|
+
rawDomainDocument.someOtherProperty = 42;
|
|
448
|
+
|
|
449
|
+
try {
|
|
450
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
451
|
+
|
|
452
|
+
expect.fail('should throw error');
|
|
453
|
+
} catch (e) {
|
|
454
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
455
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
456
|
+
|
|
457
|
+
const [error] = e.getErrors();
|
|
458
|
+
|
|
459
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
460
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
461
|
+
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it('should be valid', async () => {
|
|
466
|
+
const domain = dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
467
|
+
|
|
468
|
+
const result = await dpp.document.validate(domain);
|
|
469
|
+
|
|
470
|
+
expect(result.isValid()).to.be.true();
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
describe('Records', () => {
|
|
474
|
+
it('should be defined', async () => {
|
|
475
|
+
delete rawDomainDocument.records;
|
|
476
|
+
|
|
477
|
+
try {
|
|
478
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
479
|
+
|
|
480
|
+
expect.fail('should throw error');
|
|
481
|
+
} catch (e) {
|
|
482
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
483
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
484
|
+
|
|
485
|
+
const [error] = e.getErrors();
|
|
486
|
+
|
|
487
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
488
|
+
expect(error.keyword).to.equal('required');
|
|
489
|
+
expect(error.params.missingProperty).to.equal('records');
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it('should not be empty', async () => {
|
|
494
|
+
rawDomainDocument.records = {};
|
|
495
|
+
|
|
496
|
+
try {
|
|
497
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
498
|
+
|
|
499
|
+
expect.fail('should throw error');
|
|
500
|
+
} catch (e) {
|
|
501
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
502
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
503
|
+
|
|
504
|
+
const [error] = e.getErrors();
|
|
505
|
+
|
|
506
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
507
|
+
expect(error.keyword).to.equal('minProperties');
|
|
508
|
+
expect(error.instancePath).to.equal('/records');
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('should not have additional properties', async () => {
|
|
513
|
+
rawDomainDocument.records = {
|
|
514
|
+
someOtherProperty: 42,
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
try {
|
|
518
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
519
|
+
|
|
520
|
+
expect.fail('should throw error');
|
|
521
|
+
} catch (e) {
|
|
522
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
523
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
524
|
+
|
|
525
|
+
const [error] = e.getErrors();
|
|
526
|
+
|
|
527
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
528
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
529
|
+
expect(error.instancePath).to.equal('/records');
|
|
530
|
+
expect(error.params.additionalProperty).to.equal('someOtherProperty');
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
describe('Dash Identity', () => {
|
|
535
|
+
it('should have either `dashUniqueIdentityId` or `dashAliasIdentityId`', async () => {
|
|
536
|
+
rawDomainDocument.records = {
|
|
537
|
+
dashUniqueIdentityId: identityId,
|
|
538
|
+
dashAliasIdentityId: identityId,
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
try {
|
|
542
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
543
|
+
|
|
544
|
+
expect.fail('should throw error');
|
|
545
|
+
} catch (e) {
|
|
546
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
547
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
548
|
+
|
|
549
|
+
const [error] = e.getErrors();
|
|
550
|
+
|
|
551
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
552
|
+
expect(error.keyword).to.equal('maxProperties');
|
|
553
|
+
expect(error.instancePath).to.equal('/records');
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
describe('dashUniqueIdentityId', () => {
|
|
558
|
+
it('should no less than 32 bytes', async () => {
|
|
559
|
+
rawDomainDocument.records = {
|
|
560
|
+
dashUniqueIdentityId: crypto.randomBytes(30),
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
try {
|
|
564
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
565
|
+
|
|
566
|
+
expect.fail('should throw error');
|
|
567
|
+
} catch (e) {
|
|
568
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
569
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
570
|
+
|
|
571
|
+
const [error] = e.getErrors();
|
|
572
|
+
|
|
573
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
574
|
+
expect(error.keyword).to.equal('minItems');
|
|
575
|
+
expect(error.instancePath).to.equal('/records/dashUniqueIdentityId');
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it('should no more than 32 bytes', async () => {
|
|
580
|
+
rawDomainDocument.records = {
|
|
581
|
+
dashUniqueIdentityId: crypto.randomBytes(64),
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
try {
|
|
585
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
586
|
+
|
|
587
|
+
expect.fail('should throw error');
|
|
588
|
+
} catch (e) {
|
|
589
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
590
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
591
|
+
|
|
592
|
+
const [error] = e.getErrors();
|
|
593
|
+
|
|
594
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
595
|
+
expect(error.keyword).to.equal('maxItems');
|
|
596
|
+
expect(error.instancePath).to.equal('/records/dashUniqueIdentityId');
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
describe('dashAliasIdentityId', () => {
|
|
602
|
+
it('should no less than 32 bytes', async () => {
|
|
603
|
+
rawDomainDocument.records = {
|
|
604
|
+
dashAliasIdentityId: crypto.randomBytes(30),
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
try {
|
|
608
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
609
|
+
|
|
610
|
+
expect.fail('should throw error');
|
|
611
|
+
} catch (e) {
|
|
612
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
613
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
614
|
+
|
|
615
|
+
const [error] = e.getErrors();
|
|
616
|
+
|
|
617
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
618
|
+
expect(error.keyword).to.equal('minItems');
|
|
619
|
+
expect(error.instancePath).to.equal('/records/dashAliasIdentityId');
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
it('should no more than 32 bytes', async () => {
|
|
624
|
+
rawDomainDocument.records = {
|
|
625
|
+
dashAliasIdentityId: crypto.randomBytes(64),
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
try {
|
|
629
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
630
|
+
|
|
631
|
+
expect.fail('should throw error');
|
|
632
|
+
} catch (e) {
|
|
633
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
634
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
635
|
+
|
|
636
|
+
const [error] = e.getErrors();
|
|
637
|
+
|
|
638
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
639
|
+
expect(error.keyword).to.equal('maxItems');
|
|
640
|
+
expect(error.instancePath).to.equal('/records/dashAliasIdentityId');
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
describe('subdomainRules', () => {
|
|
648
|
+
it('should be defined', async () => {
|
|
649
|
+
delete rawDomainDocument.subdomainRules;
|
|
650
|
+
|
|
651
|
+
try {
|
|
652
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
653
|
+
|
|
654
|
+
expect.fail('should throw error');
|
|
655
|
+
} catch (e) {
|
|
656
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
657
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
658
|
+
|
|
659
|
+
const [error] = e.getErrors();
|
|
660
|
+
|
|
661
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
662
|
+
expect(error.keyword).to.equal('required');
|
|
663
|
+
expect(error.params.missingProperty).to.equal('subdomainRules');
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it('should not have additional properties', async () => {
|
|
668
|
+
rawDomainDocument.subdomainRules.someOtherProperty = 42;
|
|
669
|
+
|
|
670
|
+
try {
|
|
671
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
672
|
+
|
|
673
|
+
expect.fail('should throw error');
|
|
674
|
+
} catch (e) {
|
|
675
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
676
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
677
|
+
|
|
678
|
+
const [error] = e.getErrors();
|
|
679
|
+
|
|
680
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
681
|
+
expect(error.keyword).to.equal('additionalProperties');
|
|
682
|
+
expect(error.instancePath).to.equal('/subdomainRules');
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
describe('allowSubdomains', () => {
|
|
687
|
+
it('should be boolean', async () => {
|
|
688
|
+
rawDomainDocument.subdomainRules.allowSubdomains = 'data';
|
|
689
|
+
|
|
690
|
+
try {
|
|
691
|
+
dpp.document.create(dataContract, identityId, 'domain', rawDomainDocument);
|
|
692
|
+
|
|
693
|
+
expect.fail('should throw error');
|
|
694
|
+
} catch (e) {
|
|
695
|
+
expect(e.name).to.equal('InvalidDocumentError');
|
|
696
|
+
expect(e.getErrors()).to.have.a.lengthOf(1);
|
|
697
|
+
|
|
698
|
+
const [error] = e.getErrors();
|
|
699
|
+
|
|
700
|
+
expect(error.name).to.equal('JsonSchemaError');
|
|
701
|
+
expect(error.keyword).to.equal('type');
|
|
702
|
+
expect(error.instancePath).to.equal('/subdomainRules/allowSubdomains');
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
});
|
|
708
|
+
});
|
|
709
|
+
});
|