@dashevo/wasm-dpp 0.25.6 → 0.25.9
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/Cargo.toml +3 -2
- package/README.md +1 -1
- package/dist/wasm/wasm_dpp.d.ts +808 -712
- package/dist/wasm/wasm_dpp.js +853 -452
- package/dist/wasm/wasm_dpp_bg.js +1 -1
- package/lib/bls/bls.js +48 -0
- package/lib/test/fixtures/getChainAssetLockProofFixture.js +20 -1
- package/lib/test/fixtures/getDataContractFixture.js +4 -6
- package/lib/test/fixtures/getDocumentTransitionsFixture.js +31 -1
- package/lib/test/fixtures/getInstantAssetLockProofFixture.js +32 -12
- package/lib/test/mocks/getBlsAdapterMock.js +1 -1
- package/lib/utils/creditsConverter.js +14 -0
- package/lib/utils/hash.js +18 -0
- package/lib/wasm/wasm_dpp.d.ts +808 -712
- package/package.json +3 -5
- package/src/dash_platform_protocol.rs +5 -5
- package/src/document/errors/invalid_document_error.rs +5 -0
- package/src/document/extended_document.rs +15 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +219 -214
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +1 -1
- package/src/errors/consensus/basic/identity/identity_insufficient_balance_error.rs +4 -2
- package/src/errors/consensus/basic/json_schema_error.rs +35 -5
- package/src/identity/identity_facade.rs +7 -5
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +32 -17
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +22 -13
- package/src/identity/state_transition/asset_lock_proof/mod.rs +12 -11
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +1 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +1 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +1 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +1 -0
- package/src/lib.rs +1 -1
- package/src/validation/mod.rs +2 -2
- package/src/validation/validation_result.rs +16 -15
- package/test/integration/document/DocumentFacade.spec.js +11 -27
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +9 -19
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +2 -2
- package/test/integration/document/validation/validateDocumentFactory.spec.js +2 -2
- package/test/integration/identity/IdentityFacade.spec.js +1 -2
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +2 -2
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +2 -2
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +6 -8
- package/test/unit/document/Document.spec.js +30 -52
- package/test/unit/document/DocumentFactory.spec.js +2 -2
- package/test/unit/document/errors/InvalidDocumentError.spec.js +9 -9
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +158 -155
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +132 -134
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +3 -3
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +568 -591
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +5 -13
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +9 -28
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +19 -27
- package/lib/test/fixtures/getDashPayContractFixture.js +0 -1
- package/lib/test/fixtures/getDashPayDocumentFixture.js +0 -1
- package/lib/test/fixtures/getDpnsContractFixture.js +0 -1
- package/lib/test/fixtures/getDpnsDocumentFixture.js +0 -1
- package/lib/test/fixtures/getFeatureFlagsContractFixture.js +0 -1
- package/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js +0 -1
- package/lib/test/fixtures/getIdentityTopUpTransitionFixtureJs.js +0 -1
- package/lib/test/fixtures/getMasternodeRewardShareDocumentsFixture.js +0 -1
- package/lib/test/fixtures/getMasternodeRewardSharesContractFixture.js +0 -1
- package/lib/test/fixtures/getPreorderDocumentFixture.js +0 -1
- package/lib/test/fixtures/getRawTransactionFixture.js +0 -1
- package/lib/test/fixtures/js/generateRandomIdentifier.js +0 -1
- package/lib/test/fixtures/js/getChainAssetLockProofFixture.js +0 -1
- package/lib/test/fixtures/js/getDataContractFixture.js +0 -1
- package/lib/test/fixtures/js/getDocumentTransitionsFixture.js +0 -1
- package/lib/test/fixtures/js/getDocumentsFixture.js +0 -1
- package/lib/test/fixtures/js/getInstantAssetLockProofFixture.js +0 -1
- package/test/integration/DashPlatformProtocol.spec.js +0 -53
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +0 -195
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -500
- package/test/integration/stateTransition/calculateStateTransitionFeeFromOperationsFactory.spec.js +0 -53
- package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +0 -103
- package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +0 -84
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +0 -45
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +0 -49
- package/test/unit/dataTrigger/DataTrigger.spec.js +0 -132
- package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +0 -29
- package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +0 -107
- package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +0 -382
- package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +0 -99
- package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +0 -113
- package/test/unit/dataTrigger/rejectDataTrigger.spec.js +0 -51
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +0 -202
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +0 -256
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +0 -94
- package/test/unit/errors/consensus/codes.spec.js +0 -102
- package/test/unit/identity/creditsConverter.spec.js +0 -34
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +0 -83
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +0 -138
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +0 -100
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +0 -36
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +0 -63
- package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +0 -47
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
const SimplifiedMNListEntry = require('@dashevo/dashcore-lib/lib/deterministicmnlist/SimplifiedMNListEntry');
|
|
2
|
-
const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFixture');
|
|
3
|
-
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
4
|
-
const getMasternodeRewardShareDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getMasternodeRewardShareDocumentsFixture');
|
|
5
|
-
const getMasternodeRewardSharesContractFixture = require('@dashevo/dpp/lib/test/fixtures/getMasternodeRewardSharesContractFixture');
|
|
6
|
-
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
7
|
-
const createRewardShareDataTrigger = require('@dashevo/dpp/lib/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger');
|
|
8
|
-
const DataTriggerExecutionResult = require('@dashevo/dpp/lib/dataTrigger/DataTriggerExecutionResult');
|
|
9
|
-
const DataTriggerConditionError = require('@dashevo/dpp/lib/errors/consensus/state/dataContract/dataTrigger/DataTriggerConditionError');
|
|
10
|
-
const StateTransitionExecutionContext = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
11
|
-
|
|
12
|
-
describe('createMasternodeRewardSharesDataTrigger', () => {
|
|
13
|
-
let contextMock;
|
|
14
|
-
let stateRepositoryMock;
|
|
15
|
-
let documentTransition;
|
|
16
|
-
let topLevelIdentityId;
|
|
17
|
-
let smlStoreMock;
|
|
18
|
-
let smlMock;
|
|
19
|
-
let documentsFixture;
|
|
20
|
-
let executionContext;
|
|
21
|
-
|
|
22
|
-
beforeEach(function beforeEach() {
|
|
23
|
-
topLevelIdentityId = Buffer.from('c286807d463b06c7aba3b9a60acf64c1fc03da8c1422005cd9b4293f08cf0562', 'hex');
|
|
24
|
-
|
|
25
|
-
smlMock = {
|
|
26
|
-
getQuorum: this.sinonSandbox.stub(),
|
|
27
|
-
toSimplifiedMNListDiff: this.sinonSandbox.stub(),
|
|
28
|
-
getQuorumsOfType: this.sinonSandbox.stub(),
|
|
29
|
-
getValidMasternodesList: this.sinonSandbox.stub().returns([
|
|
30
|
-
new SimplifiedMNListEntry({
|
|
31
|
-
proRegTxHash: 'c286807d463b06c7aba3b9a60acf64c1fc03da8c1422005cd9b4293f08cf0562',
|
|
32
|
-
confirmedHash: '4eb56228c535db3b234907113fd41d57bcc7cdcb8e0e00e57590af27ee88c119',
|
|
33
|
-
service: '192.168.65.2:20101',
|
|
34
|
-
pubKeyOperator: '809519c5f6f3be1c08782ac42ae9a83b6c7205eba43f9a96a4f032ec7a73f1a7c25fa78cce0d6d9c135f7e2c28527179',
|
|
35
|
-
votingAddress: 'yXmprXYP51uzfMyndtWwxz96MnkCKkFc9x',
|
|
36
|
-
nType: 0,
|
|
37
|
-
isValid: true,
|
|
38
|
-
}),
|
|
39
|
-
new SimplifiedMNListEntry({
|
|
40
|
-
proRegTxHash: 'a3e1edc6bd352eeaf0ae58e30781ef4b127854241a3fe7fddf36d5b7e1dc2b3f',
|
|
41
|
-
confirmedHash: '27a0b637b56af038c45e2fd1f06c2401c8dadfa28ca5e0d19ca836cc984a8378',
|
|
42
|
-
service: '192.168.65.2:20201',
|
|
43
|
-
pubKeyOperator: '987a4873caba62cd45a2f7d4aa6d94519ee6753e9bef777c927cb94ade768a542b0ff34a93231d3a92b4e75ffdaa366e',
|
|
44
|
-
votingAddress: 'ycL7L4mhYoaZdm9TH85svvpfeKtdfo249u',
|
|
45
|
-
nType: 0,
|
|
46
|
-
isValid: true,
|
|
47
|
-
}),
|
|
48
|
-
]),
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const dataContract = getMasternodeRewardSharesContractFixture();
|
|
52
|
-
|
|
53
|
-
documentsFixture = getMasternodeRewardShareDocumentsFixture(undefined, undefined, dataContract);
|
|
54
|
-
|
|
55
|
-
smlStoreMock = {
|
|
56
|
-
getSMLbyHeight: this.sinonSandbox.stub().returns(smlMock),
|
|
57
|
-
getCurrentSML: this.sinonSandbox.stub().returns(smlMock),
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
61
|
-
stateRepositoryMock.fetchSMLStore.resolves(smlStoreMock);
|
|
62
|
-
stateRepositoryMock.fetchIdentity.resolves(getIdentityFixture());
|
|
63
|
-
stateRepositoryMock.fetchDocuments.resolves([]);
|
|
64
|
-
|
|
65
|
-
const [document] = getMasternodeRewardShareDocumentsFixture(undefined, undefined, dataContract);
|
|
66
|
-
|
|
67
|
-
[documentTransition] = getDocumentTransitionsFixture({
|
|
68
|
-
create: [document],
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
executionContext = new StateTransitionExecutionContext();
|
|
72
|
-
|
|
73
|
-
contextMock = {
|
|
74
|
-
getStateRepository: () => stateRepositoryMock,
|
|
75
|
-
getOwnerId: this.sinonSandbox.stub(),
|
|
76
|
-
getDataContract: () => dataContract,
|
|
77
|
-
getStateTransitionExecutionContext: () => executionContext,
|
|
78
|
-
};
|
|
79
|
-
contextMock.getOwnerId.returns(topLevelIdentityId);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should return an error if percentage > 10000', async () => {
|
|
83
|
-
stateRepositoryMock.fetchDocuments.resolves(documentsFixture);
|
|
84
|
-
// documentsFixture contains percentage = 500
|
|
85
|
-
documentTransition.data.percentage = 9501;
|
|
86
|
-
|
|
87
|
-
const result = await createRewardShareDataTrigger(
|
|
88
|
-
documentTransition, contextMock,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
92
|
-
expect(result.isOk()).to.be.false();
|
|
93
|
-
|
|
94
|
-
const [error] = result.getErrors();
|
|
95
|
-
|
|
96
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
97
|
-
expect(error.message).to.equal('Percentage can not be more than 10000');
|
|
98
|
-
|
|
99
|
-
expect(stateRepositoryMock.fetchSMLStore).to.be.calledOnce();
|
|
100
|
-
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
101
|
-
documentTransition.data.payToId,
|
|
102
|
-
executionContext,
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should return an error if payToId does not exist', async () => {
|
|
107
|
-
stateRepositoryMock.fetchIdentity.resolves(null);
|
|
108
|
-
|
|
109
|
-
const result = await createRewardShareDataTrigger(
|
|
110
|
-
documentTransition, contextMock,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
114
|
-
expect(result.isOk()).to.be.false();
|
|
115
|
-
|
|
116
|
-
const [error] = result.getErrors();
|
|
117
|
-
|
|
118
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
119
|
-
expect(error.message).to.equal(`Identity ${documentTransition.data.payToId} doesn't exist`);
|
|
120
|
-
|
|
121
|
-
expect(stateRepositoryMock.fetchSMLStore).to.be.calledOnce();
|
|
122
|
-
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
123
|
-
documentTransition.data.payToId,
|
|
124
|
-
executionContext,
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should return an error if ownerId is not a masternode identity', async () => {
|
|
129
|
-
contextMock.getOwnerId.returns(getIdentityFixture().getId());
|
|
130
|
-
|
|
131
|
-
const result = await createRewardShareDataTrigger(
|
|
132
|
-
documentTransition, contextMock,
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
136
|
-
expect(result.isOk()).to.be.false();
|
|
137
|
-
|
|
138
|
-
const [error] = result.getErrors();
|
|
139
|
-
|
|
140
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
141
|
-
expect(error.message).to.equal('Only masternode identities can share rewards');
|
|
142
|
-
|
|
143
|
-
expect(stateRepositoryMock.fetchSMLStore).to.be.calledOnce();
|
|
144
|
-
expect(stateRepositoryMock.fetchIdentity).to.be.not.called();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('should pass', async () => {
|
|
148
|
-
const result = await createRewardShareDataTrigger(
|
|
149
|
-
documentTransition, contextMock,
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
153
|
-
expect(result.isOk()).to.be.true();
|
|
154
|
-
|
|
155
|
-
expect(stateRepositoryMock.fetchSMLStore).to.be.calledOnce();
|
|
156
|
-
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
157
|
-
documentTransition.data.payToId,
|
|
158
|
-
executionContext,
|
|
159
|
-
);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should pass on dry run', async () => {
|
|
163
|
-
stateRepositoryMock.fetchIdentity.resolves(null);
|
|
164
|
-
|
|
165
|
-
executionContext.enableDryRun();
|
|
166
|
-
|
|
167
|
-
const result = await createRewardShareDataTrigger(
|
|
168
|
-
documentTransition, contextMock,
|
|
169
|
-
);
|
|
170
|
-
executionContext.disableDryRun();
|
|
171
|
-
|
|
172
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
173
|
-
expect(result.isOk()).to.be.true();
|
|
174
|
-
expect(stateRepositoryMock.fetchSMLStore).to.not.be.called();
|
|
175
|
-
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
176
|
-
documentTransition.data.payToId,
|
|
177
|
-
executionContext,
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should return an error if there are 16 stored shares', async () => {
|
|
182
|
-
stateRepositoryMock.fetchDocuments.resolves(new Array(16).fill(0));
|
|
183
|
-
|
|
184
|
-
const result = await createRewardShareDataTrigger(
|
|
185
|
-
documentTransition, contextMock,
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
expect(result).to.be.an.instanceOf(DataTriggerExecutionResult);
|
|
189
|
-
expect(result.isOk()).to.be.false();
|
|
190
|
-
|
|
191
|
-
const [error] = result.getErrors();
|
|
192
|
-
|
|
193
|
-
expect(error).to.be.an.instanceOf(DataTriggerConditionError);
|
|
194
|
-
expect(error.message).to.equal('Reward shares cannot contain more than 16 identities');
|
|
195
|
-
|
|
196
|
-
expect(stateRepositoryMock.fetchSMLStore).to.be.calledOnce();
|
|
197
|
-
expect(stateRepositoryMock.fetchIdentity).to.be.calledOnceWithExactly(
|
|
198
|
-
documentTransition.data.payToId,
|
|
199
|
-
executionContext,
|
|
200
|
-
);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
const DocumentJs = require('@dashevo/dpp/lib/document/Document');
|
|
2
|
-
const DocumentsBatchTransitionJs = require(
|
|
3
|
-
'@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/DocumentsBatchTransition',
|
|
4
|
-
);
|
|
5
|
-
|
|
6
|
-
const applyDocumentsBatchTransitionFactory = require(
|
|
7
|
-
'@dashevo/dpp/lib/document/stateTransition/DocumentsBatchTransition/applyDocumentsBatchTransitionFactory',
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
const StateTransitionExecutionContextJs = require('@dashevo/dpp/lib/stateTransition/StateTransitionExecutionContext');
|
|
11
|
-
const getDataContractFixture = require('../../../../../lib/test/fixtures/js/getDataContractFixture');
|
|
12
|
-
const getDocumentsFixture = require('../../../../../lib/test/fixtures/js/getDocumentsFixture');
|
|
13
|
-
const getDocumentTransitionsFixture = require(
|
|
14
|
-
'../../../../../lib/test/fixtures/js/getDocumentTransitionsFixture',
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const createStateRepositoryMock = require('../../../../../lib/test/mocks/createStateRepositoryMock');
|
|
18
|
-
|
|
19
|
-
const { default: loadWasmDpp } = require('../../../../..');
|
|
20
|
-
const { getLatestProtocolVersion } = require('../../../../..');
|
|
21
|
-
|
|
22
|
-
let ExtendedDocument;
|
|
23
|
-
let DocumentsBatchTransition;
|
|
24
|
-
let DataContract;
|
|
25
|
-
let StateTransitionExecutionContext;
|
|
26
|
-
let applyDocumentsBatchTransition;
|
|
27
|
-
let DocumentNotProvidedError;
|
|
28
|
-
|
|
29
|
-
describe.skip('applyDocumentsBatchTransitionFactory', () => {
|
|
30
|
-
let documentsJs;
|
|
31
|
-
let dataContractJs;
|
|
32
|
-
let dataContract;
|
|
33
|
-
let documentTransitionsJs;
|
|
34
|
-
let ownerId;
|
|
35
|
-
let replaceDocumentJs;
|
|
36
|
-
let replaceDocument;
|
|
37
|
-
let stateTransitionJs;
|
|
38
|
-
let stateTransition;
|
|
39
|
-
let documentsFixtureJs;
|
|
40
|
-
let documentsFixture;
|
|
41
|
-
let applyDocumentsBatchTransitionJs;
|
|
42
|
-
let stateRepositoryMockJs;
|
|
43
|
-
let stateRepositoryMock;
|
|
44
|
-
let fetchExtendedDocumentsMock;
|
|
45
|
-
let executionContextJs;
|
|
46
|
-
let executionContext;
|
|
47
|
-
let blockTimeMs;
|
|
48
|
-
|
|
49
|
-
beforeEach(async function beforeEach() {
|
|
50
|
-
({
|
|
51
|
-
DataContract,
|
|
52
|
-
ExtendedDocument,
|
|
53
|
-
DocumentsBatchTransition,
|
|
54
|
-
StateTransitionExecutionContext,
|
|
55
|
-
applyDocumentsBatchTransition,
|
|
56
|
-
// Errors:
|
|
57
|
-
DocumentNotProvidedError,
|
|
58
|
-
} = await loadWasmDpp());
|
|
59
|
-
|
|
60
|
-
dataContractJs = getDataContractFixture();
|
|
61
|
-
dataContract = DataContract.fromBuffer(dataContractJs.toBuffer());
|
|
62
|
-
|
|
63
|
-
documentsFixtureJs = getDocumentsFixture(dataContractJs);
|
|
64
|
-
documentsFixture = documentsFixtureJs.map((d) => {
|
|
65
|
-
const doc = new ExtendedDocument(d.toObject(), dataContract);
|
|
66
|
-
doc.setEntropy(d.entropy);
|
|
67
|
-
return doc;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
ownerId = getDocumentsFixture.ownerId;
|
|
71
|
-
|
|
72
|
-
replaceDocumentJs = new DocumentJs({
|
|
73
|
-
...documentsFixtureJs[1].toObject(),
|
|
74
|
-
lastName: 'NotSoShiny',
|
|
75
|
-
}, dataContractJs);
|
|
76
|
-
|
|
77
|
-
replaceDocument = new ExtendedDocument({
|
|
78
|
-
...documentsFixture[1].toObject(),
|
|
79
|
-
lastName: 'NotSoShiny',
|
|
80
|
-
}, dataContract);
|
|
81
|
-
|
|
82
|
-
blockTimeMs = Date.now();
|
|
83
|
-
documentsJs = [replaceDocumentJs, documentsFixtureJs[2]];
|
|
84
|
-
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
85
|
-
create: [documentsFixtureJs[0]],
|
|
86
|
-
replace: [documentsJs[0]],
|
|
87
|
-
delete: [documentsJs[1]],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
stateTransitionJs = new DocumentsBatchTransitionJs({
|
|
91
|
-
protocolVersion: getLatestProtocolVersion(),
|
|
92
|
-
ownerId,
|
|
93
|
-
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
94
|
-
}, [dataContractJs]);
|
|
95
|
-
|
|
96
|
-
stateTransition = new DocumentsBatchTransition({
|
|
97
|
-
protocolVersion: getLatestProtocolVersion(),
|
|
98
|
-
ownerId,
|
|
99
|
-
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
100
|
-
}, [dataContract]);
|
|
101
|
-
|
|
102
|
-
executionContextJs = new StateTransitionExecutionContextJs();
|
|
103
|
-
executionContext = new StateTransitionExecutionContext();
|
|
104
|
-
|
|
105
|
-
stateTransitionJs.setExecutionContext(executionContextJs);
|
|
106
|
-
|
|
107
|
-
stateRepositoryMockJs = createStateRepositoryMock(this.sinonSandbox);
|
|
108
|
-
stateRepositoryMockJs.fetchDataContract.resolves(dataContractJs);
|
|
109
|
-
stateRepositoryMockJs.fetchLatestPlatformBlockTime.resolves(blockTimeMs);
|
|
110
|
-
|
|
111
|
-
fetchExtendedDocumentsMock = this.sinonSandbox.stub();
|
|
112
|
-
fetchExtendedDocumentsMock.resolves([
|
|
113
|
-
replaceDocumentJs,
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
117
|
-
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
118
|
-
stateRepositoryMock.fetchLatestPlatformBlockTime.resolves(blockTimeMs);
|
|
119
|
-
stateRepositoryMock.updateDocument.resolves(null);
|
|
120
|
-
stateRepositoryMock.removeDocument.resolves(null);
|
|
121
|
-
stateRepositoryMock.createDocument.resolves(null);
|
|
122
|
-
stateRepositoryMock.fetchExtendedDocuments.resolves([replaceDocument]);
|
|
123
|
-
|
|
124
|
-
applyDocumentsBatchTransitionJs = applyDocumentsBatchTransitionFactory(
|
|
125
|
-
stateRepositoryMockJs,
|
|
126
|
-
fetchExtendedDocumentsMock,
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should call `store`, `replace` and `remove` functions for specific type of transitions', async () => {
|
|
131
|
-
await applyDocumentsBatchTransitionJs(stateTransitionJs);
|
|
132
|
-
|
|
133
|
-
const replaceDocumentTransition = documentTransitionsJs[1];
|
|
134
|
-
|
|
135
|
-
expect(fetchExtendedDocumentsMock).to.have.been.calledOnceWithExactly(
|
|
136
|
-
[replaceDocumentTransition],
|
|
137
|
-
executionContextJs,
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
expect(stateRepositoryMockJs.createDocument).to.have.been.calledOnce();
|
|
141
|
-
expect(stateRepositoryMockJs.updateDocument).to.have.been.calledOnce();
|
|
142
|
-
|
|
143
|
-
const callsArgs = [
|
|
144
|
-
...stateRepositoryMockJs.createDocument.getCall(0).args,
|
|
145
|
-
...stateRepositoryMockJs.updateDocument.getCall(0).args,
|
|
146
|
-
];
|
|
147
|
-
|
|
148
|
-
expect(callsArgs).to.have.deep.members([
|
|
149
|
-
documentsFixtureJs[0],
|
|
150
|
-
documentsJs[0],
|
|
151
|
-
executionContextJs,
|
|
152
|
-
executionContextJs,
|
|
153
|
-
]);
|
|
154
|
-
|
|
155
|
-
expect(stateRepositoryMockJs.removeDocument).to.have.been.calledOnceWithExactly(
|
|
156
|
-
documentTransitionsJs[2].getDataContract(),
|
|
157
|
-
documentTransitionsJs[2].getType(),
|
|
158
|
-
documentTransitionsJs[2].getId(),
|
|
159
|
-
executionContextJs,
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should call `store`, `replace` and `remove` functions for specific type of transitions - Rust', async () => {
|
|
164
|
-
await applyDocumentsBatchTransition(stateRepositoryMock, stateTransition, executionContext);
|
|
165
|
-
expect(stateRepositoryMock.createDocument).to.have.been.calledOnce();
|
|
166
|
-
|
|
167
|
-
const [fetchContractId, fetchDocumentType] = stateRepositoryMock
|
|
168
|
-
.fetchExtendedDocuments.getCall(0).args;
|
|
169
|
-
expect(fetchContractId.toBuffer()).to.deep.equal(documentTransitionsJs[1].getDataContractId());
|
|
170
|
-
expect(fetchDocumentType).to.equal(documentTransitionsJs[1].getType());
|
|
171
|
-
|
|
172
|
-
expect(stateRepositoryMock.updateDocument).to.have.been.calledOnce();
|
|
173
|
-
expect(stateRepositoryMock.fetchExtendedDocuments).to.have.been.calledOnce();
|
|
174
|
-
|
|
175
|
-
const [createDocument] = stateRepositoryMock.createDocument.getCall(0).args;
|
|
176
|
-
const [updateDocument] = stateRepositoryMock.updateDocument.getCall(0).args;
|
|
177
|
-
const [
|
|
178
|
-
deleteDataContract,
|
|
179
|
-
deleteDocumentType,
|
|
180
|
-
deleteDocumentId,
|
|
181
|
-
] = stateRepositoryMock.removeDocument.getCall(0).args;
|
|
182
|
-
|
|
183
|
-
expect(createDocument.toObject()).to.deep.equal(documentsFixtureJs[0].toObject());
|
|
184
|
-
const expectDocument = documentsJs[0].toJSON();
|
|
185
|
-
|
|
186
|
-
// ! Why we need to replace. Apparently, `applyDocumentsTransition` somehow
|
|
187
|
-
// ! modifies `documentsJs` and increments revision and $updatedAt. I have
|
|
188
|
-
// ! no clue how it's possible.
|
|
189
|
-
expectDocument.$updatedAt = documentTransitionsJs[1].toJSON().$updatedAt;
|
|
190
|
-
expectDocument.$revision = documentTransitionsJs[1].toJSON().$revision;
|
|
191
|
-
expect(updateDocument.toJSON()).to.deep.equal(expectDocument);
|
|
192
|
-
|
|
193
|
-
expect(deleteDataContract.toObject()).to.deep.equal(dataContract.toObject());
|
|
194
|
-
expect(deleteDocumentType).to.deep.equal(documentTransitionsJs[2].getType());
|
|
195
|
-
expect(deleteDocumentId.toBuffer()).to.deep.equal(documentTransitionsJs[2].getId());
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should throw an error if document was not provided for a replacement - Rust', async () => {
|
|
199
|
-
stateRepositoryMock.fetchExtendedDocuments.resolves([]);
|
|
200
|
-
|
|
201
|
-
const replaceDocumentTransition = documentTransitionsJs[1];
|
|
202
|
-
|
|
203
|
-
try {
|
|
204
|
-
await applyDocumentsBatchTransition(stateRepositoryMock, stateTransition, executionContext);
|
|
205
|
-
expect.fail('Error was not thrown');
|
|
206
|
-
} catch (e) {
|
|
207
|
-
expect(e).to.be.an.instanceOf(DocumentNotProvidedError);
|
|
208
|
-
expect(e.getDocumentTransition().toObject())
|
|
209
|
-
.to.deep.equal(replaceDocumentTransition.toObject());
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('should call `replace` functions on dry run - Rust', async function test() {
|
|
214
|
-
this.timeout(10000);
|
|
215
|
-
stateRepositoryMock.fetchLatestPlatformBlockTime.resolves(blockTimeMs);
|
|
216
|
-
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
217
|
-
create: [],
|
|
218
|
-
replace: [documentsJs[0]],
|
|
219
|
-
delete: [],
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
stateTransition = new DocumentsBatchTransition({
|
|
223
|
-
protocolVersion: getLatestProtocolVersion(),
|
|
224
|
-
ownerId,
|
|
225
|
-
transitions: documentTransitionsJs.map((t) => t.toObject()),
|
|
226
|
-
}, [dataContract]);
|
|
227
|
-
|
|
228
|
-
executionContext.enableDryRun();
|
|
229
|
-
|
|
230
|
-
await applyDocumentsBatchTransition(stateRepositoryMock, stateTransition, executionContext);
|
|
231
|
-
|
|
232
|
-
executionContext.disableDryRun();
|
|
233
|
-
|
|
234
|
-
const [documentTransition] = stateTransition.getTransitions();
|
|
235
|
-
|
|
236
|
-
// the owner_id are 0s in dry_run
|
|
237
|
-
const newDocument = new ExtendedDocument({
|
|
238
|
-
$protocolVersion: stateTransitionJs.getProtocolVersion(),
|
|
239
|
-
$id: documentTransition.getId(),
|
|
240
|
-
$type: documentTransition.getType(),
|
|
241
|
-
$dataContractId: documentTransition.getDataContractId(),
|
|
242
|
-
$ownerId: ownerId,
|
|
243
|
-
$createdAt: documentTransition.getUpdatedAt().getTime(),
|
|
244
|
-
...documentTransition.getData(),
|
|
245
|
-
}, documentTransition.getDataContract());
|
|
246
|
-
|
|
247
|
-
newDocument.setRevision(documentTransition.getRevision());
|
|
248
|
-
newDocument.setData(documentTransition.getData());
|
|
249
|
-
newDocument.setUpdatedAt(documentTransition.getUpdatedAt());
|
|
250
|
-
|
|
251
|
-
expect(stateRepositoryMock.updateDocument).to.have.been.called.calledOnce();
|
|
252
|
-
const [updateDocument] = stateRepositoryMock.updateDocument.getCall(0).args;
|
|
253
|
-
|
|
254
|
-
expect(updateDocument.toObject()).to.be.deep.equal(newDocument.toObject());
|
|
255
|
-
});
|
|
256
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
const getDocumentsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentsFixture');
|
|
2
|
-
const getDocumentTransitionsFixture = require('@dashevo/dpp/lib/test/fixtures/getDocumentTransitionsFixture');
|
|
3
|
-
|
|
4
|
-
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
5
|
-
|
|
6
|
-
const generateRandomIdentifierJs = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
|
|
7
|
-
|
|
8
|
-
const sinon = require('sinon');
|
|
9
|
-
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
10
|
-
|
|
11
|
-
let Identifier;
|
|
12
|
-
let DataContract;
|
|
13
|
-
let fetchExtendedDocuments;
|
|
14
|
-
let DocumentTransition;
|
|
15
|
-
let DocumentCreateTransition;
|
|
16
|
-
let StateTransitionExecutionContext;
|
|
17
|
-
let ExtendedDocument;
|
|
18
|
-
|
|
19
|
-
describe.skip('fetchDocumentsFactory', () => {
|
|
20
|
-
let stateRepositoryMock;
|
|
21
|
-
let documentTransitionsJs;
|
|
22
|
-
let documentTransitions;
|
|
23
|
-
let documentsJs;
|
|
24
|
-
let documents;
|
|
25
|
-
let executionContext;
|
|
26
|
-
|
|
27
|
-
beforeEach(async function beforeEach() {
|
|
28
|
-
({
|
|
29
|
-
Identifier,
|
|
30
|
-
DataContract,
|
|
31
|
-
DocumentTransition,
|
|
32
|
-
DocumentCreateTransition,
|
|
33
|
-
StateTransitionExecutionContext,
|
|
34
|
-
fetchExtendedDocuments,
|
|
35
|
-
ExtendedDocument,
|
|
36
|
-
} = await loadWasmDpp());
|
|
37
|
-
|
|
38
|
-
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
39
|
-
|
|
40
|
-
executionContext = new StateTransitionExecutionContext();
|
|
41
|
-
|
|
42
|
-
documentsJs = getDocumentsFixture().slice(0, 5);
|
|
43
|
-
const dataContractBuffer = documentsJs[0].dataContract.toBuffer();
|
|
44
|
-
const dataContract = DataContract.fromBuffer(dataContractBuffer);
|
|
45
|
-
|
|
46
|
-
documents = documentsJs.map((document) => {
|
|
47
|
-
document.toObject();
|
|
48
|
-
|
|
49
|
-
return new ExtendedDocument(
|
|
50
|
-
document.toObject(), dataContract.clone(), // document.getType(),
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
documentTransitionsJs = getDocumentTransitionsFixture({
|
|
54
|
-
create: documentsJs,
|
|
55
|
-
});
|
|
56
|
-
documentTransitions = documentTransitionsJs.map(
|
|
57
|
-
(transition) => DocumentTransition.fromTransitionCreate(
|
|
58
|
-
new DocumentCreateTransition(
|
|
59
|
-
transition.toObject(), dataContract.clone(),
|
|
60
|
-
),
|
|
61
|
-
),
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should fetch specified Documents using StateRepository - Rust', async () => {
|
|
66
|
-
const firstDocumentDataContractId = generateRandomIdentifierJs().toBuffer();
|
|
67
|
-
|
|
68
|
-
documentTransitions[0].setDataContractId(firstDocumentDataContractId);
|
|
69
|
-
documents[0].setDataContractId(firstDocumentDataContractId);
|
|
70
|
-
|
|
71
|
-
stateRepositoryMock.fetchExtendedDocuments.withArgs(
|
|
72
|
-
sinon.match.instanceOf(Identifier),
|
|
73
|
-
documentTransitions[0].getType(),
|
|
74
|
-
).resolves([documents[0]]);
|
|
75
|
-
|
|
76
|
-
stateRepositoryMock.fetchExtendedDocuments.withArgs(
|
|
77
|
-
sinon.match.instanceOf(Identifier),
|
|
78
|
-
documentTransitions[1].getType(),
|
|
79
|
-
).resolves([documents[1], documents[2]]);
|
|
80
|
-
|
|
81
|
-
stateRepositoryMock.fetchExtendedDocuments.withArgs(
|
|
82
|
-
sinon.match.instanceOf(Identifier),
|
|
83
|
-
documentTransitionsJs[3].getType(),
|
|
84
|
-
).resolves([documents[3], documents[4]]);
|
|
85
|
-
|
|
86
|
-
await fetchExtendedDocuments(
|
|
87
|
-
stateRepositoryMock,
|
|
88
|
-
documentTransitions,
|
|
89
|
-
executionContext,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(stateRepositoryMock.fetchExtendedDocuments).to.have.been.calledThrice();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const codes = require('@dashevo/dpp/lib/errors/consensus/codes');
|
|
4
|
-
const AbstractConsensusError = require('@dashevo/dpp/lib/errors/consensus/AbstractConsensusError');
|
|
5
|
-
const AbstractBasicError = require('@dashevo/dpp/lib/errors/consensus/basic/AbstractBasicError');
|
|
6
|
-
const AbstractSignatureError = require('@dashevo/dpp/lib/errors/consensus/signature/AbstractSignatureError');
|
|
7
|
-
const AbstractFeeError = require('@dashevo/dpp/lib/errors/consensus/fee/AbstractFeeError');
|
|
8
|
-
const AbstractStateError = require('@dashevo/dpp/lib/errors/consensus/state/AbstractStateError');
|
|
9
|
-
|
|
10
|
-
const getAllFiles = (dirPath, arrayOfFiles) => {
|
|
11
|
-
const files = fs.readdirSync(dirPath);
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line no-param-reassign
|
|
14
|
-
arrayOfFiles = arrayOfFiles || [];
|
|
15
|
-
|
|
16
|
-
files.forEach((file) => {
|
|
17
|
-
if (fs.statSync(`${dirPath}/${file}`).isDirectory()) {
|
|
18
|
-
// eslint-disable-next-line no-param-reassign
|
|
19
|
-
arrayOfFiles = getAllFiles(`${dirPath}/${file}`, arrayOfFiles);
|
|
20
|
-
} else if (file.slice(-3) === '.js') {
|
|
21
|
-
arrayOfFiles.push(path.join(dirPath, '/', file));
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return arrayOfFiles;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function isChildOf(classToCheck, parentClass) {
|
|
29
|
-
if (!classToCheck || !classToCheck.prototype) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (classToCheck.prototype instanceof parentClass) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return isChildOf(classToCheck.prototype, parentClass);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const errorClasses = Object.values(codes).map((ErrorClass) => ErrorClass);
|
|
41
|
-
const errorClassDuplicates = errorClasses.filter((item, index) => (
|
|
42
|
-
errorClasses.indexOf(item) !== index
|
|
43
|
-
));
|
|
44
|
-
|
|
45
|
-
describe('Consensus error codes', () => {
|
|
46
|
-
// Skip the tests for browsers
|
|
47
|
-
if (global.window !== undefined) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const normalizedPath = path.join(__dirname, '../../../../../js-dpp/lib/errors/');
|
|
52
|
-
const allFiles = getAllFiles(normalizedPath);
|
|
53
|
-
|
|
54
|
-
allFiles.forEach((fileName) => {
|
|
55
|
-
// eslint-disable-next-line global-require,import/no-dynamic-require
|
|
56
|
-
const ErrorClass = require(fileName);
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
(isChildOf(ErrorClass, AbstractConsensusError)) && !ErrorClass.name.startsWith('Abstract')
|
|
60
|
-
) {
|
|
61
|
-
context(ErrorClass.name, () => {
|
|
62
|
-
let code;
|
|
63
|
-
let AssignedErrorClass;
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
const result = Object.entries(codes)
|
|
67
|
-
.find(([, ErrorClassWithCode]) => ErrorClassWithCode === ErrorClass);
|
|
68
|
-
|
|
69
|
-
if (result) {
|
|
70
|
-
code = Number(result[0]);
|
|
71
|
-
// eslint-disable-next-line prefer-destructuring
|
|
72
|
-
AssignedErrorClass = result[1];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should have error code defined', () => {
|
|
77
|
-
expect(AssignedErrorClass).to.exist();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should have been define in the correct code range', () => {
|
|
81
|
-
if (isChildOf(ErrorClass, AbstractBasicError)) {
|
|
82
|
-
expect(code).to.be.above(999);
|
|
83
|
-
expect(code).to.be.below(2000);
|
|
84
|
-
} else if (isChildOf(ErrorClass, AbstractSignatureError)) {
|
|
85
|
-
expect(code).to.be.above(1999);
|
|
86
|
-
expect(code).to.be.below(3000);
|
|
87
|
-
} else if (isChildOf(ErrorClass, AbstractFeeError)) {
|
|
88
|
-
expect(code).to.be.above(2999);
|
|
89
|
-
expect(code).to.be.below(4000);
|
|
90
|
-
} else if (isChildOf(ErrorClass, AbstractStateError)) {
|
|
91
|
-
expect(code).to.be.above(3999);
|
|
92
|
-
expect(code).to.be.below(5000);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should not have duplicates', () => {
|
|
97
|
-
expect(errorClassDuplicates).to.not.include(ErrorClass);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
convertSatoshiToCredits,
|
|
3
|
-
convertCreditsToSatoshi,
|
|
4
|
-
RATIO,
|
|
5
|
-
} = require('@dashevo/dpp/lib/identity/creditsConverter');
|
|
6
|
-
|
|
7
|
-
describe('creditsConverter', () => {
|
|
8
|
-
describe('convertSatoshiToCredits', () => {
|
|
9
|
-
it('should convert satoshi to credits', () => {
|
|
10
|
-
const amount = 42;
|
|
11
|
-
|
|
12
|
-
const convertedAmount = convertSatoshiToCredits(amount);
|
|
13
|
-
|
|
14
|
-
expect(convertedAmount).to.equal(amount * RATIO);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe('convertCreditsToSatoshi', () => {
|
|
18
|
-
it('should convert credits to satoshi', () => {
|
|
19
|
-
const amount = 10000;
|
|
20
|
-
|
|
21
|
-
const convertedAmount = convertCreditsToSatoshi(amount);
|
|
22
|
-
|
|
23
|
-
expect(convertedAmount).to.equal(Math.floor(amount / RATIO));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should convert credits to 0 satoshi if amount < RATIO', () => {
|
|
27
|
-
const amount = RATIO - 1;
|
|
28
|
-
|
|
29
|
-
const convertedAmount = convertCreditsToSatoshi(amount);
|
|
30
|
-
|
|
31
|
-
expect(convertedAmount).to.equal(0);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|