@dashevo/wasm-dpp 0.23.0-dev.10
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/.babelrc +5 -0
- package/.editorconfig +13 -0
- package/.eslintignore +1 -0
- package/.eslintrc +15 -0
- package/.mocharc.yml +4 -0
- package/CHANGELOG.md +397 -0
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/karma.conf.js +53 -0
- package/package.json +107 -0
- package/test/.eslintrc +12 -0
- package/test/integration/DashPlatformProtocol.spec.js +53 -0
- package/test/integration/ajv/keywords/byteArray/addByteArrayKeyword.spec.js +148 -0
- package/test/integration/dataContract/DataContractFacade.spec.js +84 -0
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +357 -0
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +444 -0
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +2191 -0
- package/test/integration/document/Document.spec.js +90 -0
- package/test/integration/document/DocumentFacade.spec.js +155 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +83 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +1146 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +294 -0
- package/test/integration/document/validation/validateDocumentFactory.spec.js +447 -0
- package/test/integration/error/consensus/createConsensusError.spec.js +21 -0
- package/test/integration/identity/IdentityFacade.spec.js +187 -0
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +422 -0
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +361 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/basic/validateIdentityUpdateTransitionBasicFactory.spec.js +595 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +299 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +66 -0
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +415 -0
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +134 -0
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +401 -0
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +205 -0
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +127 -0
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +370 -0
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +497 -0
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +507 -0
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +418 -0
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +35 -0
- package/test/integration/util/generateEntropy.spec.js +17 -0
- package/test/integration/util/serializer.spec.js +24 -0
- package/test/unit/DashPlatformProtocol.spec.js +79 -0
- package/test/unit/Identifier.spec.js +123 -0
- package/test/unit/Metadata.spec.js +37 -0
- package/test/unit/dataContract/DataContract.spec.js +407 -0
- package/test/unit/dataContract/DataContractFactory.spec.js +178 -0
- package/test/unit/dataContract/createDataContract.spec.js +57 -0
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +46 -0
- package/test/unit/dataContract/generateDataContractId.spec.js +19 -0
- package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +103 -0
- package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +84 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +160 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +48 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +85 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +158 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +47 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +121 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +111 -0
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +93 -0
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +64 -0
- package/test/unit/dataTrigger/DataTrigger.spec.js +132 -0
- package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +29 -0
- package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +109 -0
- package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +382 -0
- package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +101 -0
- package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +113 -0
- package/test/unit/dataTrigger/rejectDataTrigger.spec.js +51 -0
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +200 -0
- package/test/unit/decodeProtocolEntityFactory.spec.js +75 -0
- package/test/unit/document/Document.spec.js +444 -0
- package/test/unit/document/DocumentFactory.spec.js +376 -0
- package/test/unit/document/errors/InvalidDocumentError.spec.js +46 -0
- package/test/unit/document/fetchAndValidateDataContractFactory.spec.js +66 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +168 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +171 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/documentTransition/DocumentCreateTransition.spec.js +25 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesById.spec.js +31 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +122 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +75 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +128 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +811 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +279 -0
- package/test/unit/errors/consensus/codes.spec.js +102 -0
- package/test/unit/identity/Identity.spec.js +243 -0
- package/test/unit/identity/IdentityFactory.spec.js +274 -0
- package/test/unit/identity/IdentityPublicKey.spec.js +273 -0
- package/test/unit/identity/creditsConverter.spec.js +34 -0
- package/test/unit/identity/errors/InvalidIdentityError.spec.js +46 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +184 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +90 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +71 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +137 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +108 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +22 -0
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +219 -0
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +149 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +21 -0
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +36 -0
- package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +47 -0
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +160 -0
- package/test/unit/stateTransition/createStateTransitionFactory.spec.js +72 -0
- package/test/unit/stateTransition/errors/InvalidStateTransitionError.spec.js +51 -0
- package/test/unit/stateTransition/validation/validateStateTransitionBasicFactory.spec.js +138 -0
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +372 -0
- package/test/unit/stateTransition/validation/validateStateTransitionIdentitySignatureFactory.spec.js +339 -0
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +86 -0
- package/test/unit/stateTransition/validation/validateStateTransitionStateFactory.spec.js +89 -0
- package/test/unit/version/validateProtocolVersionFactory.spec.js +80 -0
- package/webpack.config.js +49 -0
package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const IdentityPublicKey = require('../../../../../lib/identity/IdentityPublicKey');
|
|
2
|
+
|
|
3
|
+
const stateTransitionTypes = require(
|
|
4
|
+
'../../../../../lib/stateTransition/stateTransitionTypes',
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
const protocolVersion = require('../../../../../lib/version/protocolVersion');
|
|
8
|
+
const Identifier = require('../../../../../lib/identifier/Identifier');
|
|
9
|
+
|
|
10
|
+
const getIdentityUpdateTransitionFixture = require('../../../../../lib/test/fixtures/getIdentityUpdateTransitionFixture');
|
|
11
|
+
const generateRandomIdentifier = require('../../../../../lib/test/utils/generateRandomIdentifier');
|
|
12
|
+
|
|
13
|
+
describe('IdentityUpdateTransition', () => {
|
|
14
|
+
let rawStateTransition;
|
|
15
|
+
let stateTransition;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
stateTransition = getIdentityUpdateTransitionFixture();
|
|
19
|
+
rawStateTransition = stateTransition.toObject();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('#getType', () => {
|
|
23
|
+
it('should return IDENTITY_UPDATE type', () => {
|
|
24
|
+
expect(stateTransition.getType()).to.equal(stateTransitionTypes.IDENTITY_UPDATE);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('#setIdentityId', () => {
|
|
29
|
+
it('should set identityId', () => {
|
|
30
|
+
const id = generateRandomIdentifier();
|
|
31
|
+
|
|
32
|
+
stateTransition.setIdentityId(id);
|
|
33
|
+
|
|
34
|
+
expect(stateTransition.identityId).to.deep.equal(id);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('#getIdentityId', () => {
|
|
39
|
+
it('should return identityId', () => {
|
|
40
|
+
expect(stateTransition.getIdentityId()).to.deep.equal(rawStateTransition.identityId);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('#getRevision', () => {
|
|
45
|
+
it('should return revision', () => {
|
|
46
|
+
expect(stateTransition.getRevision()).to.equal(rawStateTransition.revision);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('#setRevision', () => {
|
|
51
|
+
it('should set revision', () => {
|
|
52
|
+
stateTransition.setRevision(42);
|
|
53
|
+
|
|
54
|
+
expect(stateTransition.revision).to.equal(42);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('#getOwnerId', () => {
|
|
59
|
+
it('should return owner id', () => {
|
|
60
|
+
expect(stateTransition.getOwnerId()).to.deep.equal(
|
|
61
|
+
rawStateTransition.identityId,
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('#getPublicKeysToAdd', () => {
|
|
67
|
+
it('should return public keys to add', () => {
|
|
68
|
+
expect(stateTransition.getPublicKeysToAdd()).to.deep.equal(
|
|
69
|
+
rawStateTransition.addPublicKeys.map((rawPublicKey) => new IdentityPublicKey(rawPublicKey)),
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('#setPublicKeysToAdd', () => {
|
|
75
|
+
it('should set public keys to add', () => {
|
|
76
|
+
const publicKeys = [new IdentityPublicKey({
|
|
77
|
+
id: 0,
|
|
78
|
+
type: IdentityPublicKey.TYPES.BLS12_381,
|
|
79
|
+
purpose: 0,
|
|
80
|
+
securityLevel: 0,
|
|
81
|
+
readOnly: true,
|
|
82
|
+
data: Buffer.from('01fac99ca2c8f39c286717c213e190aba4b7af76db320ec43f479b7d9a2012313a0ae59ca576edf801444bc694686694', 'hex'),
|
|
83
|
+
})];
|
|
84
|
+
|
|
85
|
+
stateTransition.setPublicKeysToAdd(publicKeys);
|
|
86
|
+
|
|
87
|
+
expect(stateTransition.addPublicKeys).to.have.deep.members(publicKeys);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('#getPublicKeyIdsToDisable', () => {
|
|
92
|
+
it('should return public key ids to disable', () => {
|
|
93
|
+
expect(stateTransition.getPublicKeyIdsToDisable())
|
|
94
|
+
.to.deep.equal(stateTransition.disablePublicKeys);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('#setPublicKeyIdsToDisable', () => {
|
|
99
|
+
it('should set public key ids to disable', () => {
|
|
100
|
+
stateTransition.setPublicKeyIdsToDisable([1, 2]);
|
|
101
|
+
|
|
102
|
+
expect(stateTransition.disablePublicKeys).to.deep.equal([1, 2]);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('#getPublicKeysDisabledAt', () => {
|
|
107
|
+
it('should return time to disable public keys', () => {
|
|
108
|
+
expect(stateTransition.getPublicKeysDisabledAt())
|
|
109
|
+
.to.deep.equal(new Date(stateTransition.publicKeysDisabledAt));
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('#setPublicKeysDisabledAt', () => {
|
|
114
|
+
it('should set time to disable public keys', () => {
|
|
115
|
+
const now = new Date();
|
|
116
|
+
|
|
117
|
+
stateTransition.setPublicKeysDisabledAt(now);
|
|
118
|
+
|
|
119
|
+
expect(stateTransition.publicKeysDisabledAt).to.deep.equal(new Date(now));
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('#toObject', () => {
|
|
124
|
+
it('should return raw state transition', () => {
|
|
125
|
+
rawStateTransition = stateTransition.toObject();
|
|
126
|
+
|
|
127
|
+
expect(rawStateTransition).to.deep.equal({
|
|
128
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
129
|
+
type: stateTransitionTypes.IDENTITY_UPDATE,
|
|
130
|
+
signature: undefined,
|
|
131
|
+
identityId: rawStateTransition.identityId,
|
|
132
|
+
revision: rawStateTransition.revision,
|
|
133
|
+
publicKeysDisabledAt: rawStateTransition.publicKeysDisabledAt,
|
|
134
|
+
addPublicKeys: rawStateTransition.addPublicKeys,
|
|
135
|
+
disablePublicKeys: rawStateTransition.disablePublicKeys,
|
|
136
|
+
signaturePublicKeyId: undefined,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should return raw state transition without signature', () => {
|
|
141
|
+
rawStateTransition = stateTransition.toObject({ skipSignature: true });
|
|
142
|
+
|
|
143
|
+
expect(rawStateTransition).to.deep.equal({
|
|
144
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
145
|
+
type: stateTransitionTypes.IDENTITY_UPDATE,
|
|
146
|
+
identityId: rawStateTransition.identityId,
|
|
147
|
+
revision: rawStateTransition.revision,
|
|
148
|
+
publicKeysDisabledAt: rawStateTransition.publicKeysDisabledAt,
|
|
149
|
+
addPublicKeys: rawStateTransition.addPublicKeys,
|
|
150
|
+
disablePublicKeys: rawStateTransition.disablePublicKeys,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should return raw state transition without optional properties', () => {
|
|
155
|
+
stateTransition.setPublicKeyIdsToDisable(undefined);
|
|
156
|
+
stateTransition.setPublicKeysDisabledAt(undefined);
|
|
157
|
+
stateTransition.setPublicKeysToAdd(undefined);
|
|
158
|
+
|
|
159
|
+
rawStateTransition = stateTransition.toObject();
|
|
160
|
+
|
|
161
|
+
expect(rawStateTransition).to.deep.equal({
|
|
162
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
163
|
+
type: stateTransitionTypes.IDENTITY_UPDATE,
|
|
164
|
+
signature: undefined,
|
|
165
|
+
identityId: rawStateTransition.identityId,
|
|
166
|
+
revision: rawStateTransition.revision,
|
|
167
|
+
signaturePublicKeyId: undefined,
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('#toJSON ', () => {
|
|
173
|
+
it('should return JSON representation of state transition', () => {
|
|
174
|
+
const jsonStateTransition = stateTransition.toJSON();
|
|
175
|
+
|
|
176
|
+
expect(jsonStateTransition).to.deep.equal({
|
|
177
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
178
|
+
type: stateTransitionTypes.IDENTITY_UPDATE,
|
|
179
|
+
signature: undefined,
|
|
180
|
+
identityId: stateTransition.getIdentityId().toString(),
|
|
181
|
+
revision: rawStateTransition.revision,
|
|
182
|
+
publicKeysDisabledAt: rawStateTransition.publicKeysDisabledAt,
|
|
183
|
+
addPublicKeys: stateTransition.getPublicKeysToAdd().map((k) => k.toJSON()),
|
|
184
|
+
disablePublicKeys: rawStateTransition.disablePublicKeys,
|
|
185
|
+
signaturePublicKeyId: undefined,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('#getModifiedDataIds', () => {
|
|
191
|
+
it('should return ids of topped up identity', () => {
|
|
192
|
+
const result = stateTransition.getModifiedDataIds();
|
|
193
|
+
|
|
194
|
+
expect(result.length).to.be.equal(1);
|
|
195
|
+
const identityId = result[0];
|
|
196
|
+
|
|
197
|
+
expect(identityId).to.be.an.instanceOf(Identifier);
|
|
198
|
+
expect(identityId).to.be.deep.equal(rawStateTransition.identityId);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('#isDataContractStateTransition', () => {
|
|
203
|
+
it('should return false', () => {
|
|
204
|
+
expect(stateTransition.isDataContractStateTransition()).to.be.false();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('#isDocumentStateTransition', () => {
|
|
209
|
+
it('should return false', () => {
|
|
210
|
+
expect(stateTransition.isDocumentStateTransition()).to.be.false();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe('#isIdentityStateTransition', () => {
|
|
215
|
+
it('should return true', () => {
|
|
216
|
+
expect(stateTransition.isIdentityStateTransition()).to.be.true();
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const applyIdentityUpdateTransitionFactory = require('../../../../../lib/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory');
|
|
2
|
+
const createStateRepositoryMock = require('../../../../../lib/test/mocks/createStateRepositoryMock');
|
|
3
|
+
const getIdentityUpdateTransitionFixture = require('../../../../../lib/test/fixtures/getIdentityUpdateTransitionFixture');
|
|
4
|
+
const getIdentityFixture = require('../../../../../lib/test/fixtures/getIdentityFixture');
|
|
5
|
+
const StateTransitionExecutionContext = require('../../../../../lib/stateTransition/StateTransitionExecutionContext');
|
|
6
|
+
const getBiggestPossibleIdentity = require('../../../../../lib/identity/getBiggestPossibleIdentity');
|
|
7
|
+
|
|
8
|
+
describe('applyIdentityUpdateTransition', () => {
|
|
9
|
+
let applyIdentityUpdateTransition;
|
|
10
|
+
let stateRepositoryMock;
|
|
11
|
+
let stateTransition;
|
|
12
|
+
let identity;
|
|
13
|
+
let executionContext;
|
|
14
|
+
|
|
15
|
+
beforeEach(function beforeEach() {
|
|
16
|
+
stateTransition = getIdentityUpdateTransitionFixture();
|
|
17
|
+
stateTransition.setRevision(stateTransition.getRevision() + 1);
|
|
18
|
+
identity = getIdentityFixture();
|
|
19
|
+
|
|
20
|
+
executionContext = new StateTransitionExecutionContext();
|
|
21
|
+
|
|
22
|
+
stateTransition.setExecutionContext(executionContext);
|
|
23
|
+
|
|
24
|
+
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
25
|
+
stateRepositoryMock.fetchIdentity.resolves(identity);
|
|
26
|
+
|
|
27
|
+
applyIdentityUpdateTransition = applyIdentityUpdateTransitionFactory(
|
|
28
|
+
stateRepositoryMock,
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should add public keys', async () => {
|
|
33
|
+
stateTransition.setPublicKeysDisabledAt(undefined);
|
|
34
|
+
stateTransition.setPublicKeyIdsToDisable(undefined);
|
|
35
|
+
|
|
36
|
+
await applyIdentityUpdateTransition(stateTransition);
|
|
37
|
+
|
|
38
|
+
expect(identity.getPublicKeys()).to.have.lengthOf(3);
|
|
39
|
+
|
|
40
|
+
expect(identity.getPublicKeyById(3).toObject())
|
|
41
|
+
.to.deep.equal(stateTransition.getPublicKeysToAdd()[0]);
|
|
42
|
+
|
|
43
|
+
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
44
|
+
stateTransition.getIdentityId(),
|
|
45
|
+
executionContext,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect(stateRepositoryMock.updateIdentity).to.be.calledOnceWithExactly(
|
|
49
|
+
identity,
|
|
50
|
+
executionContext,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const publicKeyHashes = stateTransition.getPublicKeysToAdd()
|
|
54
|
+
.map((publicKey) => publicKey.hash());
|
|
55
|
+
|
|
56
|
+
expect(stateRepositoryMock.storeIdentityPublicKeyHashes).to.be.calledOnceWithExactly(
|
|
57
|
+
identity.getId(),
|
|
58
|
+
publicKeyHashes,
|
|
59
|
+
executionContext,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(identity.getRevision()).to.equal(stateTransition.getRevision());
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should disable public key', async () => {
|
|
66
|
+
stateTransition.setPublicKeysToAdd(undefined);
|
|
67
|
+
|
|
68
|
+
await applyIdentityUpdateTransition(stateTransition);
|
|
69
|
+
|
|
70
|
+
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
71
|
+
stateTransition.getIdentityId(),
|
|
72
|
+
executionContext,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(stateRepositoryMock.storeIdentityPublicKeyHashes).to.not.be.called();
|
|
76
|
+
|
|
77
|
+
expect(stateRepositoryMock.updateIdentity).to.be.calledOnceWithExactly(
|
|
78
|
+
identity,
|
|
79
|
+
executionContext,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const [id] = stateTransition.getPublicKeyIdsToDisable();
|
|
83
|
+
|
|
84
|
+
expect(identity.getPublicKeyById(id).getDisabledAt())
|
|
85
|
+
.to.equal(stateTransition.getPublicKeysDisabledAt().getTime());
|
|
86
|
+
|
|
87
|
+
expect(identity.getRevision()).to.equal(stateTransition.getRevision());
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should not add public keys on dry run', async () => {
|
|
91
|
+
const biggestPossibleIdentity = getBiggestPossibleIdentity();
|
|
92
|
+
|
|
93
|
+
stateTransition.setPublicKeysDisabledAt(undefined);
|
|
94
|
+
stateTransition.setPublicKeyIdsToDisable(undefined);
|
|
95
|
+
|
|
96
|
+
stateTransition.getExecutionContext().enableDryRun();
|
|
97
|
+
|
|
98
|
+
await applyIdentityUpdateTransition(stateTransition);
|
|
99
|
+
|
|
100
|
+
stateTransition.getExecutionContext().disableDryRun();
|
|
101
|
+
|
|
102
|
+
expect(identity.getPublicKeys()).to.have.lengthOf(2);
|
|
103
|
+
|
|
104
|
+
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
105
|
+
stateTransition.getIdentityId(),
|
|
106
|
+
executionContext,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
expect(stateRepositoryMock.updateIdentity).to.be.calledOnceWithExactly(
|
|
110
|
+
biggestPossibleIdentity,
|
|
111
|
+
executionContext,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const publicKeyHashes = stateTransition.getPublicKeysToAdd()
|
|
115
|
+
.map((publicKey) => publicKey.hash());
|
|
116
|
+
|
|
117
|
+
expect(stateRepositoryMock.storeIdentityPublicKeyHashes).to.be.calledOnceWithExactly(
|
|
118
|
+
biggestPossibleIdentity.getId(),
|
|
119
|
+
publicKeyHashes,
|
|
120
|
+
executionContext,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(biggestPossibleIdentity.getRevision()).to.equal(stateTransition.getRevision());
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should use biggestPossibleIdentity on dry run', async () => {
|
|
127
|
+
const biggestPossibleIdentity = getBiggestPossibleIdentity();
|
|
128
|
+
|
|
129
|
+
stateTransition.setPublicKeysToAdd(undefined);
|
|
130
|
+
|
|
131
|
+
stateTransition.getExecutionContext().enableDryRun();
|
|
132
|
+
|
|
133
|
+
await applyIdentityUpdateTransition(stateTransition);
|
|
134
|
+
|
|
135
|
+
stateTransition.getExecutionContext().disableDryRun();
|
|
136
|
+
|
|
137
|
+
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
138
|
+
stateTransition.getIdentityId(),
|
|
139
|
+
executionContext,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(stateRepositoryMock.storeIdentityPublicKeyHashes).to.not.be.called();
|
|
143
|
+
|
|
144
|
+
expect(stateRepositoryMock.updateIdentity).to.be.calledOnceWithExactly(
|
|
145
|
+
biggestPossibleIdentity,
|
|
146
|
+
executionContext,
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const createAssetLockProofInstance = require('../../../../../lib/identity/stateTransition/assetLockProof/createAssetLockProofInstance');
|
|
2
|
+
const getChainAssetLockFixture = require('../../../../../lib/test/fixtures/getChainAssetLockProofFixture');
|
|
3
|
+
const getInstantAssetLockProofFixture = require('../../../../../lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
4
|
+
const ChainAssetLockProof = require('../../../../../lib/identity/stateTransition/assetLockProof/chain/ChainAssetLockProof');
|
|
5
|
+
const InstantAssetLockProof = require('../../../../../lib/identity/stateTransition/assetLockProof/instant/InstantAssetLockProof');
|
|
6
|
+
|
|
7
|
+
describe('createAssetLockProofInstance', () => {
|
|
8
|
+
it('should create an instance of InstantAssetLockProof', () => {
|
|
9
|
+
const assetLockProofFixture = getInstantAssetLockProofFixture();
|
|
10
|
+
const instance = createAssetLockProofInstance(assetLockProofFixture.toObject());
|
|
11
|
+
|
|
12
|
+
expect(instance).to.be.an.instanceOf(InstantAssetLockProof);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should create an instance of ChainAssetLockProof', () => {
|
|
16
|
+
const assetLockProofFixture = getChainAssetLockFixture();
|
|
17
|
+
const instance = createAssetLockProofInstance(assetLockProofFixture.toObject());
|
|
18
|
+
|
|
19
|
+
expect(instance).to.be.an.instanceOf(ChainAssetLockProof);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const fetchAssetLockPublicKeyHashFactory = require('../../../../../lib/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory');
|
|
2
|
+
const getInstantAssetLockProofFixture = require('../../../../../lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
3
|
+
const AssetLockOutputNotFoundError = require('../../../../../lib/identity/errors/AssetLockOutputNotFoundError');
|
|
4
|
+
|
|
5
|
+
describe('fetchAssetLockPublicKeyHashFactory', () => {
|
|
6
|
+
let fetchAssetLockPublicKeyHash;
|
|
7
|
+
let fetchAssetLockTransactionOutputMock;
|
|
8
|
+
let assetLockProof;
|
|
9
|
+
|
|
10
|
+
beforeEach(function beforeEach() {
|
|
11
|
+
fetchAssetLockTransactionOutputMock = this.sinonSandbox.stub();
|
|
12
|
+
|
|
13
|
+
fetchAssetLockPublicKeyHash = fetchAssetLockPublicKeyHashFactory(
|
|
14
|
+
fetchAssetLockTransactionOutputMock,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
assetLockProof = getInstantAssetLockProofFixture();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return public key hash for specified asset lock proof', async () => {
|
|
21
|
+
fetchAssetLockTransactionOutputMock.resolves(assetLockProof.getOutput());
|
|
22
|
+
|
|
23
|
+
const result = await fetchAssetLockPublicKeyHash(assetLockProof);
|
|
24
|
+
|
|
25
|
+
expect(result).to.deep.equal(assetLockProof.getOutput().script.getData());
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should throw AssetLockOutputNotFoundError if output is not found', async () => {
|
|
29
|
+
try {
|
|
30
|
+
await fetchAssetLockPublicKeyHash(assetLockProof);
|
|
31
|
+
expect.fail('should throw AssetLockOutputNotFoundError');
|
|
32
|
+
} catch (e) {
|
|
33
|
+
expect(e).to.be.an.instanceOf(AssetLockOutputNotFoundError);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const IdentityPublicKey = require('../../../../lib/identity/IdentityPublicKey');
|
|
2
|
+
|
|
3
|
+
const validateRequiredPurposeAndSecurityLevelFactory = require('../../../../lib/identity/validation/validateRequiredPurposeAndSecurityLevelFactory');
|
|
4
|
+
|
|
5
|
+
const { expectValidationError } = require('../../../../lib/test/expect/expectError');
|
|
6
|
+
|
|
7
|
+
const ValidationResult = require('../../../../lib/validation/ValidationResult');
|
|
8
|
+
|
|
9
|
+
const MissingMasterPublicKeyError = require('../../../../lib/errors/consensus/basic/identity/MissingMasterPublicKeyError');
|
|
10
|
+
|
|
11
|
+
describe('validateRequiredPurposeAndSecurityLevel', () => {
|
|
12
|
+
let validateRequiredPurposeAndSecurityLevel;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
validateRequiredPurposeAndSecurityLevel = (
|
|
16
|
+
validateRequiredPurposeAndSecurityLevelFactory()
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return invalid result if the state transition does not contain master key', async () => {
|
|
21
|
+
const result = await validateRequiredPurposeAndSecurityLevel([{
|
|
22
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
23
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.CRITICAL,
|
|
24
|
+
}, {
|
|
25
|
+
// this key must be filtered out
|
|
26
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
27
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
28
|
+
disabledAt: 42,
|
|
29
|
+
}]);
|
|
30
|
+
|
|
31
|
+
expectValidationError(result, MissingMasterPublicKeyError);
|
|
32
|
+
|
|
33
|
+
const [error] = result.getErrors();
|
|
34
|
+
|
|
35
|
+
expect(error.getCode()).to.equal(1046);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return valid result', async () => {
|
|
39
|
+
const result = await validateRequiredPurposeAndSecurityLevel([{
|
|
40
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
41
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
42
|
+
}]);
|
|
43
|
+
|
|
44
|
+
expect(result).to.be.an.instanceOf(ValidationResult);
|
|
45
|
+
expect(result.isValid()).to.be.true();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
const getDataContractFixture = require('../../../lib/test/fixtures/getDataContractFixture');
|
|
2
|
+
|
|
3
|
+
const DataContractCreateTransition = require('../../../lib/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition');
|
|
4
|
+
|
|
5
|
+
const ValidationResult = require('../../../lib/validation/ValidationResult');
|
|
6
|
+
|
|
7
|
+
const InvalidStateTransitionError = require('../../../lib/stateTransition/errors/InvalidStateTransitionError');
|
|
8
|
+
|
|
9
|
+
const SerializedObjectParsingError = require('../../../lib/errors/consensus/basic/decode/SerializedObjectParsingError');
|
|
10
|
+
|
|
11
|
+
const createDPPMock = require('../../../lib/test/mocks/createDPPMock');
|
|
12
|
+
const StateTransitionFactory = require('../../../lib/stateTransition/StateTransitionFactory');
|
|
13
|
+
const SomeConsensusError = require('../../../lib/test/mocks/SomeConsensusError');
|
|
14
|
+
|
|
15
|
+
describe('StateTransitionFactory', () => {
|
|
16
|
+
let validateStateTransitionBasicMock;
|
|
17
|
+
let createStateTransitionMock;
|
|
18
|
+
let factory;
|
|
19
|
+
let stateTransition;
|
|
20
|
+
let rawStateTransition;
|
|
21
|
+
let decodeProtocolEntityMock;
|
|
22
|
+
let dppMock;
|
|
23
|
+
|
|
24
|
+
beforeEach(function beforeEach() {
|
|
25
|
+
const dataContract = getDataContractFixture();
|
|
26
|
+
|
|
27
|
+
stateTransition = new DataContractCreateTransition({
|
|
28
|
+
dataContract: dataContract.toObject(),
|
|
29
|
+
entropy: dataContract.getEntropy(),
|
|
30
|
+
});
|
|
31
|
+
rawStateTransition = stateTransition.toObject();
|
|
32
|
+
|
|
33
|
+
decodeProtocolEntityMock = this.sinonSandbox.stub();
|
|
34
|
+
|
|
35
|
+
validateStateTransitionBasicMock = this.sinonSandbox.stub();
|
|
36
|
+
createStateTransitionMock = this.sinonSandbox.stub().returns(stateTransition);
|
|
37
|
+
|
|
38
|
+
dppMock = createDPPMock();
|
|
39
|
+
|
|
40
|
+
factory = new StateTransitionFactory(
|
|
41
|
+
validateStateTransitionBasicMock,
|
|
42
|
+
createStateTransitionMock,
|
|
43
|
+
dppMock,
|
|
44
|
+
decodeProtocolEntityMock,
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('createFromObject', () => {
|
|
49
|
+
it('should return new State Transition with data from passed object', async () => {
|
|
50
|
+
validateStateTransitionBasicMock.returns(new ValidationResult());
|
|
51
|
+
|
|
52
|
+
const result = await factory.createFromObject(rawStateTransition);
|
|
53
|
+
|
|
54
|
+
expect(result).to.equal(stateTransition);
|
|
55
|
+
|
|
56
|
+
expect(validateStateTransitionBasicMock).to.have.been.calledOnceWith(rawStateTransition);
|
|
57
|
+
|
|
58
|
+
expect(createStateTransitionMock).to.have.been.calledOnceWith(rawStateTransition);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should return new State Transition without validation if "skipValidation" option is passed', async () => {
|
|
62
|
+
const result = await factory.createFromObject(rawStateTransition, { skipValidation: true });
|
|
63
|
+
|
|
64
|
+
expect(result).to.equal(stateTransition);
|
|
65
|
+
|
|
66
|
+
expect(validateStateTransitionBasicMock).to.have.not.been.called();
|
|
67
|
+
|
|
68
|
+
expect(createStateTransitionMock).to.have.been.calledOnceWith(rawStateTransition);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should throw InvalidStateTransitionError if passed object is not valid', async () => {
|
|
72
|
+
const validationError = new SomeConsensusError('test');
|
|
73
|
+
|
|
74
|
+
validateStateTransitionBasicMock.returns(new ValidationResult([validationError]));
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await factory.createFromObject(rawStateTransition);
|
|
78
|
+
|
|
79
|
+
expect.fail('InvalidStateTransitionError is not thrown');
|
|
80
|
+
} catch (e) {
|
|
81
|
+
expect(e).to.be.an.instanceOf(InvalidStateTransitionError);
|
|
82
|
+
expect(e.getRawStateTransition()).to.equal(rawStateTransition);
|
|
83
|
+
|
|
84
|
+
expect(e.getErrors()).to.have.length(1);
|
|
85
|
+
|
|
86
|
+
const [consensusError] = e.getErrors();
|
|
87
|
+
|
|
88
|
+
expect(consensusError).to.equal(validationError);
|
|
89
|
+
|
|
90
|
+
expect(validateStateTransitionBasicMock).to.have.been.calledOnceWith(
|
|
91
|
+
rawStateTransition,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('createFromBuffer', () => {
|
|
98
|
+
let serializedStateTransition;
|
|
99
|
+
|
|
100
|
+
beforeEach(function beforeEach() {
|
|
101
|
+
this.sinonSandbox.stub(factory, 'createFromObject');
|
|
102
|
+
|
|
103
|
+
serializedStateTransition = stateTransition.toBuffer();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
factory.createFromObject.restore();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should return new State Transition from serialized contract', async () => {
|
|
111
|
+
decodeProtocolEntityMock.returns([rawStateTransition.protocolVersion, rawStateTransition]);
|
|
112
|
+
|
|
113
|
+
factory.createFromObject.resolves(stateTransition);
|
|
114
|
+
|
|
115
|
+
const result = await factory.createFromBuffer(serializedStateTransition);
|
|
116
|
+
|
|
117
|
+
expect(result).to.equal(stateTransition);
|
|
118
|
+
|
|
119
|
+
expect(factory.createFromObject).to.have.been.calledOnceWith(rawStateTransition);
|
|
120
|
+
|
|
121
|
+
expect(decodeProtocolEntityMock).to.have.been.calledOnceWith(
|
|
122
|
+
serializedStateTransition,
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should throw InvalidStateTransitionError if the decoding fails with consensus error', async () => {
|
|
127
|
+
const parsingError = new SerializedObjectParsingError(
|
|
128
|
+
serializedStateTransition,
|
|
129
|
+
new Error(),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
decodeProtocolEntityMock.throws(parsingError);
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await factory.createFromBuffer(serializedStateTransition);
|
|
136
|
+
|
|
137
|
+
expect.fail('should throw InvalidStateTransitionError');
|
|
138
|
+
} catch (e) {
|
|
139
|
+
expect(e).to.be.an.instanceOf(InvalidStateTransitionError);
|
|
140
|
+
|
|
141
|
+
const [innerError] = e.getErrors();
|
|
142
|
+
expect(innerError).to.be.equal(parsingError);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should throw an error if decoding fails with any other error', async () => {
|
|
147
|
+
const otherParsingError = new Error();
|
|
148
|
+
|
|
149
|
+
decodeProtocolEntityMock.throws(otherParsingError);
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
await factory.createFromBuffer(serializedStateTransition);
|
|
153
|
+
|
|
154
|
+
expect.fail('should throw an error');
|
|
155
|
+
} catch (e) {
|
|
156
|
+
expect(e).to.be.equal(otherParsingError);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|