@dashevo/wasm-dpp 0.24.0-dev.12 → 0.24.0-dev.13
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 -0
- package/README.md +5 -1
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/wasm/wasm_dpp.d.ts +1495 -565
- package/karma.conf.js +5 -0
- package/lib/identifier/patchIdentifier.ts +5 -4
- package/lib/index.ts +1 -1
- package/lib/test/bootstrap.js +5 -0
- package/lib/test/mocks/getBlsAdapterMock.js +36 -0
- package/lib/test/utils/newDocumentsContainer.js +36 -0
- package/package.json +7 -4
- package/src/bls_adapter.rs +16 -1
- package/src/data_contract/data_contract.rs +35 -7
- package/src/data_contract/errors/invalid_document_type.rs +1 -1
- package/src/data_contract/index.rs +56 -1
- package/src/data_contract/mod.rs +1 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +2 -4
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +3 -3
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +2 -4
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +9 -6
- package/src/data_contract_factory/data_contract_factory.rs +4 -6
- package/src/document/errors/invalid_document_error.rs +10 -9
- package/src/document/errors/invalid_initial_revision_error.rs +1 -1
- package/src/document/errors/mismatch_owners_ids_error.rs +14 -4
- package/src/document/errors/mod.rs +17 -13
- package/src/document/errors/no_documents_supplied_error.rs +4 -4
- package/src/document/factory.rs +192 -0
- package/src/document/mod.rs +222 -30
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +47 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +25 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +65 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +123 -3
- package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
- package/src/document/validator.rs +30 -0
- package/src/errors/consensus/basic/identity/identity_asset_lock_proof_locked_transaction_mismatch_error.rs +6 -2
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_out_point_already_exists_error.rs +5 -2
- package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs +3 -3
- package/src/errors/dpp_error.rs +17 -0
- package/src/errors/from.rs +5 -0
- package/src/errors/js_conversion.rs +19 -4
- package/src/errors/mod.rs +2 -0
- package/src/errors/protocol_error.rs +7 -4
- package/src/identifier/mod.rs +48 -3
- package/src/identity/errors/asset_lock_output_not_found_error.rs +11 -0
- package/src/identity/errors/asset_lock_transaction_is_not_found_error.rs +20 -0
- package/src/identity/errors/mod.rs +7 -0
- package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
- package/src/identity/identity_facade.rs +2 -4
- package/src/identity/identity_public_key/mod.rs +41 -7
- package/src/identity/mod.rs +14 -5
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +132 -0
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/chain/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +177 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/instant/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/mod.rs +269 -0
- package/src/identity/state_transition/identity_create_transition/apply_identity_create_transition.rs +26 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +335 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_basic_validator.rs +153 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_create_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +46 -0
- package/src/identity/state_transition/identity_topup_transition/apply_identity_topup_transition.rs +31 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +280 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_basic_validator.rs +113 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_topup_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +42 -0
- package/src/identity/state_transition/mod.rs +9 -0
- package/src/identity/state_transition/validate_public_key_signatures.rs +59 -0
- package/src/identity/validation/public_keys_validator.rs +16 -10
- package/src/identity_public_key/public_keys_validator.rs +44 -0
- package/src/lib.rs +2 -0
- package/src/lodash.rs +7 -0
- package/src/state_repository.rs +188 -36
- package/src/state_transition/mod.rs +12 -0
- package/src/utils.rs +102 -7
- package/src/validation/json_schema_validator.rs +41 -0
- package/src/validation/mod.rs +2 -0
- package/src/validation/validation_result.rs +23 -5
- package/src/version/mod.rs +2 -0
- package/src/version/protocol_version.rs +26 -0
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +579 -502
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +175 -165
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +83 -114
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +82 -91
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +75 -31
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -148
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +63 -75
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +48 -19
- package/test/unit/dataContract/DataContract.spec.js +3 -3
- package/test/unit/dataContract/createDataContract.spec.js +0 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +3 -3
- package/test/unit/decodeProtocolEntityFactory.spec.js +2 -2
- package/test/unit/document/Document.spec.js +147 -155
- package/test/unit/document/DocumentFactory.spec.js +325 -91
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +142 -64
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +69 -30
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +32 -32
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +56 -25
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +48 -46
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +63 -0
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +90 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +18 -3
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +38 -11
- package/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +1495 -565
- package/wasm/wasm_dpp.js +3654 -1206
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +557 -386
- package/webpack.config.js +9 -0
|
@@ -1,54 +1,85 @@
|
|
|
1
|
-
const { expectValidationError } = require(
|
|
2
|
-
'@dashevo/dpp/lib/test/expect/expectError',
|
|
3
|
-
);
|
|
4
|
-
|
|
5
|
-
const validateIdentityCreateTransitionStateFactory = require(
|
|
6
|
-
'@dashevo/dpp/lib/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory',
|
|
7
|
-
);
|
|
8
|
-
|
|
9
1
|
const getIdentityCreateTransitionFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityCreateTransitionFixture');
|
|
10
2
|
|
|
11
|
-
const IdentityAlreadyExistsError = require(
|
|
12
|
-
'@dashevo/dpp/lib/errors/consensus/state/identity/IdentityAlreadyExistsError',
|
|
13
|
-
);
|
|
14
|
-
|
|
15
3
|
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
16
|
-
|
|
4
|
+
|
|
5
|
+
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
6
|
+
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
7
|
+
const generateRandomIdentifierAsync = require('../../../../../../../lib/test/utils/generateRandomIdentifierAsync');
|
|
8
|
+
const { expectValidationError } = require('../../../../../../../lib/test/expect/expectError');
|
|
17
9
|
|
|
18
10
|
describe('validateIdentityCreateTransitionStateFactory', () => {
|
|
19
11
|
let validateIdentityCreateTransitionState;
|
|
20
12
|
let stateTransition;
|
|
21
13
|
let stateRepositoryMock;
|
|
14
|
+
let identity;
|
|
15
|
+
|
|
16
|
+
let IdentityCreateTransition;
|
|
17
|
+
let IdentityPublicKey;
|
|
18
|
+
let IdentityAlreadyExistsError;
|
|
19
|
+
let Identity;
|
|
20
|
+
let IdentityCreateTransitionStateValidator;
|
|
21
|
+
|
|
22
|
+
before(async () => {
|
|
23
|
+
({
|
|
24
|
+
IdentityCreateTransition,
|
|
25
|
+
IdentityAlreadyExistsError,
|
|
26
|
+
IdentityPublicKey,
|
|
27
|
+
Identity,
|
|
28
|
+
IdentityCreateTransitionStateValidator,
|
|
29
|
+
} = await loadWasmDpp());
|
|
30
|
+
});
|
|
22
31
|
|
|
23
|
-
beforeEach(async function
|
|
24
|
-
const privateKey = 'af432c476f65211f45f48f1d42c9c0b497e56696aa1736b40544ef1a496af837';
|
|
32
|
+
beforeEach(async function () {
|
|
33
|
+
const privateKey = Buffer.from('af432c476f65211f45f48f1d42c9c0b497e56696aa1736b40544ef1a496af837', 'hex');
|
|
25
34
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
36
|
+
const validator = new IdentityCreateTransitionStateValidator(stateRepositoryMock);
|
|
37
|
+
validateIdentityCreateTransitionState = (st) => validator.validate(st);
|
|
30
38
|
|
|
31
|
-
stateTransition =
|
|
39
|
+
stateTransition = new IdentityCreateTransition(
|
|
40
|
+
getIdentityCreateTransitionFixture().toObject(),
|
|
41
|
+
);
|
|
32
42
|
|
|
33
43
|
await stateTransition.signByPrivateKey(privateKey, IdentityPublicKey.TYPES.ECDSA_SECP256K1);
|
|
34
44
|
|
|
35
45
|
const rawTransaction = '030000000137feb5676d0851337ea3c9a992496aab7a0b3eee60aeeb9774000b7f4bababa5000000006b483045022100d91557de37645c641b948c6cd03b4ae3791a63a650db3e2fee1dcf5185d1b10402200e8bd410bf516ca61715867666d31e44495428ce5c1090bf2294a829ebcfa4ef0121025c3cc7fbfc52f710c941497fd01876c189171ea227458f501afcb38a297d65b4ffffffff021027000000000000166a14152073ca2300a86b510fa2f123d3ea7da3af68dcf77cb0090a0000001976a914152073ca2300a86b510fa2f123d3ea7da3af68dc88ac00000000';
|
|
36
46
|
|
|
37
|
-
stateRepositoryMock.fetchTransaction.
|
|
47
|
+
stateRepositoryMock.fetchTransaction.returns({
|
|
48
|
+
data: Buffer.from(rawTransaction, 'hex'),
|
|
49
|
+
height: 42,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
identity = new Identity({
|
|
53
|
+
protocolVersion: protocolVersion.latestVersion,
|
|
54
|
+
id: await generateRandomIdentifierAsync(),
|
|
55
|
+
publicKeys: [
|
|
56
|
+
{
|
|
57
|
+
id: 0,
|
|
58
|
+
type: 0,
|
|
59
|
+
data: Buffer.alloc(36).fill('a'),
|
|
60
|
+
purpose: 0,
|
|
61
|
+
securityLevel: 0,
|
|
62
|
+
readOnly: false,
|
|
63
|
+
signature: Buffer.alloc(36).fill('a'),
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
balance: 0,
|
|
67
|
+
revision: 0,
|
|
68
|
+
});
|
|
38
69
|
});
|
|
39
70
|
|
|
40
71
|
it('should return invalid result if identity already exists', async () => {
|
|
41
|
-
stateRepositoryMock.fetchIdentity.
|
|
72
|
+
stateRepositoryMock.fetchIdentity.returns(identity);
|
|
42
73
|
|
|
43
74
|
const result = await validateIdentityCreateTransitionState(stateTransition);
|
|
44
75
|
|
|
45
|
-
expectValidationError(result, IdentityAlreadyExistsError
|
|
76
|
+
await expectValidationError(result, IdentityAlreadyExistsError);
|
|
46
77
|
|
|
47
78
|
const [error] = result.getErrors();
|
|
48
79
|
|
|
49
80
|
expect(error.getCode()).to.equal(4011);
|
|
50
|
-
expect(
|
|
51
|
-
expect(error.getIdentityId()).to.deep.equal(stateTransition.getIdentityId());
|
|
81
|
+
expect(error.getIdentityId()).to.exist();
|
|
82
|
+
expect(error.getIdentityId()).to.deep.equal(stateTransition.getIdentityId().toBuffer());
|
|
52
83
|
});
|
|
53
84
|
|
|
54
85
|
it('should return valid result if state transition is valid', async () => {
|
|
@@ -58,7 +89,7 @@ describe('validateIdentityCreateTransitionStateFactory', () => {
|
|
|
58
89
|
});
|
|
59
90
|
|
|
60
91
|
it('should return valid result on dry run', async () => {
|
|
61
|
-
stateRepositoryMock.fetchIdentity.
|
|
92
|
+
stateRepositoryMock.fetchIdentity.returns(identity);
|
|
62
93
|
|
|
63
94
|
stateTransition.getExecutionContext().enableDryRun();
|
|
64
95
|
|
package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
const stateTransitionTypes = require(
|
|
2
|
-
'@dashevo/dpp/lib/stateTransition/stateTransitionTypes',
|
|
3
|
-
);
|
|
4
|
-
|
|
5
|
-
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
|
|
6
|
-
|
|
7
1
|
const getIdentityTopUpTransitionFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityTopUpTransitionFixture');
|
|
2
|
+
const getChainAssetLockProofFixture = require('@dashevo/dpp/lib/test/fixtures/getChainAssetLockProofFixture');
|
|
8
3
|
|
|
4
|
+
const stateTransitionTypes = require('@dashevo/dpp/lib/stateTransition/stateTransitionTypes');
|
|
9
5
|
const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
|
|
6
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
10
7
|
|
|
11
8
|
describe('IdentityTopUpTransition', () => {
|
|
12
9
|
let rawStateTransition;
|
|
13
10
|
let stateTransition;
|
|
14
11
|
|
|
12
|
+
let IdentityTopUpTransition;
|
|
13
|
+
let InstantAssetLockProof;
|
|
14
|
+
let Identifier;
|
|
15
|
+
|
|
16
|
+
before(async () => {
|
|
17
|
+
({
|
|
18
|
+
IdentityTopUpTransition, InstantAssetLockProof, Identifier,
|
|
19
|
+
} = await loadWasmDpp());
|
|
20
|
+
});
|
|
21
|
+
|
|
15
22
|
beforeEach(() => {
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
rawStateTransition = getIdentityTopUpTransitionFixture().toObject();
|
|
24
|
+
|
|
25
|
+
stateTransition = new IdentityTopUpTransition(
|
|
26
|
+
rawStateTransition,
|
|
27
|
+
);
|
|
18
28
|
});
|
|
19
29
|
|
|
20
30
|
describe('#constructor', () => {
|
|
@@ -22,10 +32,17 @@ describe('IdentityTopUpTransition', () => {
|
|
|
22
32
|
expect(stateTransition.getAssetLockProof().toObject()).to.be.deep.equal(
|
|
23
33
|
rawStateTransition.assetLockProof,
|
|
24
34
|
);
|
|
25
|
-
expect(stateTransition.getIdentityId()).to.be.deep.equal(
|
|
35
|
+
expect(stateTransition.getIdentityId().toBuffer()).to.be.deep.equal(
|
|
26
36
|
rawStateTransition.identityId,
|
|
27
37
|
);
|
|
28
38
|
});
|
|
39
|
+
|
|
40
|
+
it('should create instance with chain asset lock proof', () => {
|
|
41
|
+
rawStateTransition.assetLockProof = getChainAssetLockProofFixture().toObject();
|
|
42
|
+
stateTransition = new IdentityTopUpTransition(rawStateTransition);
|
|
43
|
+
expect(stateTransition.getAssetLockProof().toObject())
|
|
44
|
+
.to.deep.equal(rawStateTransition.assetLockProof);
|
|
45
|
+
});
|
|
29
46
|
});
|
|
30
47
|
|
|
31
48
|
describe('#getType', () => {
|
|
@@ -36,13 +53,16 @@ describe('IdentityTopUpTransition', () => {
|
|
|
36
53
|
|
|
37
54
|
describe('#setAssetLockProof', () => {
|
|
38
55
|
it('should set asset lock proof', () => {
|
|
39
|
-
stateTransition.setAssetLockProof(
|
|
56
|
+
stateTransition.setAssetLockProof(
|
|
57
|
+
new InstantAssetLockProof(rawStateTransition.assetLockProof),
|
|
58
|
+
);
|
|
40
59
|
|
|
41
|
-
expect(stateTransition.assetLockProof
|
|
60
|
+
expect(stateTransition.assetLockProof.toObject())
|
|
61
|
+
.to.deep.equal(rawStateTransition.assetLockProof);
|
|
42
62
|
});
|
|
43
63
|
});
|
|
44
64
|
|
|
45
|
-
describe('#
|
|
65
|
+
describe('#getAssetLockProof', () => {
|
|
46
66
|
it('should return currently set asset lock proof', () => {
|
|
47
67
|
expect(stateTransition.getAssetLockProof().toObject()).to.deep.equal(
|
|
48
68
|
rawStateTransition.assetLockProof,
|
|
@@ -52,7 +72,7 @@ describe('IdentityTopUpTransition', () => {
|
|
|
52
72
|
|
|
53
73
|
describe('#getIdentityId', () => {
|
|
54
74
|
it('should return identity id', () => {
|
|
55
|
-
expect(stateTransition.getIdentityId()).to.deep.equal(
|
|
75
|
+
expect(stateTransition.getIdentityId().toBuffer()).to.deep.equal(
|
|
56
76
|
rawStateTransition.identityId,
|
|
57
77
|
);
|
|
58
78
|
});
|
|
@@ -60,7 +80,7 @@ describe('IdentityTopUpTransition', () => {
|
|
|
60
80
|
|
|
61
81
|
describe('#getOwnerId', () => {
|
|
62
82
|
it('should return owner id', () => {
|
|
63
|
-
expect(stateTransition.getOwnerId()).to.deep.equal(
|
|
83
|
+
expect(stateTransition.getOwnerId().toBuffer()).to.deep.equal(
|
|
64
84
|
rawStateTransition.identityId,
|
|
65
85
|
);
|
|
66
86
|
});
|
|
@@ -99,7 +119,7 @@ describe('IdentityTopUpTransition', () => {
|
|
|
99
119
|
protocolVersion: protocolVersion.latestVersion,
|
|
100
120
|
type: stateTransitionTypes.IDENTITY_TOP_UP,
|
|
101
121
|
assetLockProof: stateTransition.getAssetLockProof().toJSON(),
|
|
102
|
-
identityId: Identifier(rawStateTransition.identityId).toString(),
|
|
122
|
+
identityId: new Identifier(rawStateTransition.identityId).toString(),
|
|
103
123
|
signature: undefined,
|
|
104
124
|
});
|
|
105
125
|
});
|
|
@@ -113,7 +133,7 @@ describe('IdentityTopUpTransition', () => {
|
|
|
113
133
|
const identityId = result[0];
|
|
114
134
|
|
|
115
135
|
expect(identityId).to.be.an.instanceOf(Identifier);
|
|
116
|
-
expect(identityId).to.be.deep.equal(rawStateTransition.identityId);
|
|
136
|
+
expect(identityId.toBuffer()).to.be.deep.equal(rawStateTransition.identityId);
|
|
117
137
|
});
|
|
118
138
|
});
|
|
119
139
|
|
|
@@ -1,47 +1,66 @@
|
|
|
1
|
-
const applyIdentityTopUpTransitionFactory = require(
|
|
2
|
-
'@dashevo/dpp/lib/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory',
|
|
3
|
-
);
|
|
4
|
-
|
|
5
1
|
const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFixture');
|
|
6
2
|
const getIdentityTopUpTransitionFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityTopUpTransitionFixture');
|
|
7
3
|
|
|
8
4
|
const { convertSatoshiToCredits } = require('@dashevo/dpp/lib/identity/creditsConverter');
|
|
9
5
|
|
|
10
6
|
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
11
|
-
|
|
12
|
-
const
|
|
7
|
+
|
|
8
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
9
|
+
const generateRandomIdentifierAsync = require('../../../../../lib/test/utils/generateRandomIdentifierAsync');
|
|
13
10
|
|
|
14
11
|
describe('applyIdentityTopUpTransitionFactory', () => {
|
|
15
12
|
let stateTransition;
|
|
16
13
|
let applyIdentityTopUpTransition;
|
|
17
14
|
let stateRepositoryMock;
|
|
18
15
|
let identity;
|
|
19
|
-
let fetchAssetLockTransactionOutputMock;
|
|
20
16
|
let executionContext;
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
let StateTransitionExecutionContext;
|
|
19
|
+
let IdentityTopUpTransition;
|
|
20
|
+
let Identity;
|
|
21
|
+
|
|
22
|
+
let applyIdentityTopUpTransitionDPP;
|
|
23
|
+
|
|
24
|
+
before(async () => {
|
|
25
|
+
({
|
|
26
|
+
StateTransitionExecutionContext,
|
|
27
|
+
IdentityTopUpTransition,
|
|
28
|
+
applyIdentityTopUpTransition: applyIdentityTopUpTransitionDPP,
|
|
29
|
+
Identity,
|
|
30
|
+
} = await loadWasmDpp());
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
beforeEach(async function beforeEach() {
|
|
34
|
+
const rawIdentity = getIdentityFixture().toObject();
|
|
35
|
+
// Patch identity id to match expectation of wasm Identity class
|
|
36
|
+
rawIdentity.id = await generateRandomIdentifierAsync();
|
|
37
|
+
identity = new Identity(rawIdentity);
|
|
24
38
|
|
|
25
39
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
26
|
-
stateRepositoryMock.fetchIdentity.
|
|
40
|
+
stateRepositoryMock.fetchIdentity.returns(identity);
|
|
27
41
|
|
|
28
|
-
|
|
42
|
+
const rawTransaction = '030000000137feb5676d0851337ea3c9a992496aab7a0b3eee60aeeb9774000b7f4bababa5000000006b483045022100d91557de37645c641b948c6cd03b4ae3791a63a650db3e2fee1dcf5185d1b10402200e8bd410bf516ca61715867666d31e44495428ce5c1090bf2294a829ebcfa4ef0121025c3cc7fbfc52f710c941497fd01876c189171ea227458f501afcb38a297d65b4ffffffff021027000000000000166a14152073ca2300a86b510fa2f123d3ea7da3af68dcf77cb0090a0000001976a914152073ca2300a86b510fa2f123d3ea7da3af68dc88ac00000000';
|
|
29
43
|
|
|
30
|
-
|
|
44
|
+
stateRepositoryMock.fetchTransaction.returns({
|
|
45
|
+
data: Buffer.from(rawTransaction, 'hex'),
|
|
46
|
+
height: 42,
|
|
47
|
+
});
|
|
31
48
|
|
|
32
|
-
stateTransition
|
|
49
|
+
stateTransition = new IdentityTopUpTransition(
|
|
50
|
+
getIdentityTopUpTransitionFixture().toObject(),
|
|
51
|
+
);
|
|
33
52
|
|
|
34
|
-
|
|
53
|
+
executionContext = new StateTransitionExecutionContext();
|
|
35
54
|
|
|
36
|
-
|
|
55
|
+
stateTransition.setExecutionContext(executionContext);
|
|
37
56
|
|
|
38
|
-
applyIdentityTopUpTransition =
|
|
57
|
+
applyIdentityTopUpTransition = (st) => applyIdentityTopUpTransitionDPP(
|
|
39
58
|
stateRepositoryMock,
|
|
40
|
-
|
|
59
|
+
st,
|
|
41
60
|
);
|
|
42
61
|
});
|
|
43
62
|
|
|
44
|
-
it('should store identity created from state transition', async ()
|
|
63
|
+
it('should store identity created from state transition', async function () {
|
|
45
64
|
const balanceBeforeTopUp = identity.getBalance();
|
|
46
65
|
|
|
47
66
|
const balanceToTopUp = convertSatoshiToCredits(
|
|
@@ -50,35 +69,24 @@ describe('applyIdentityTopUpTransitionFactory', () => {
|
|
|
50
69
|
|
|
51
70
|
await applyIdentityTopUpTransition(stateTransition);
|
|
52
71
|
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
const { args: [updatedIdentity] } = stateRepositoryMock.updateIdentity.firstCall;
|
|
73
|
+
|
|
74
|
+
expect(updatedIdentity.getBalance()).to.be.equal(balanceBeforeTopUp + balanceToTopUp);
|
|
75
|
+
expect(updatedIdentity.getBalance()).to.be.greaterThan(balanceBeforeTopUp);
|
|
55
76
|
|
|
56
77
|
expect(stateRepositoryMock.updateIdentity).to.have.been.calledOnceWithExactly(
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
updatedIdentity,
|
|
79
|
+
this.sinonSandbox.match.instanceOf(StateTransitionExecutionContext),
|
|
59
80
|
);
|
|
60
81
|
|
|
61
82
|
expect(stateRepositoryMock.markAssetLockTransactionOutPointAsUsed).to.have.been
|
|
62
83
|
.calledOnceWithExactly(
|
|
63
84
|
stateTransition.getAssetLockProof().getOutPoint(),
|
|
64
|
-
executionContext,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
expect(fetchAssetLockTransactionOutputMock)
|
|
68
|
-
.to.be.calledOnceWithExactly(
|
|
69
|
-
stateTransition.getAssetLockProof(),
|
|
70
|
-
executionContext,
|
|
71
85
|
);
|
|
72
86
|
});
|
|
73
87
|
|
|
74
|
-
it('should store biggest possible identity on dry run', async ()
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const balanceBeforeTopUp = biggestPossibleIdentity.getBalance();
|
|
78
|
-
|
|
79
|
-
const balanceToTopUp = convertSatoshiToCredits(
|
|
80
|
-
stateTransition.getAssetLockProof().getOutput().satoshis,
|
|
81
|
-
);
|
|
88
|
+
it('should store biggest possible identity on dry run', async function () {
|
|
89
|
+
const biggestPossibleBalance = 18446744073709552000;
|
|
82
90
|
|
|
83
91
|
executionContext.enableDryRun();
|
|
84
92
|
|
|
@@ -86,23 +94,17 @@ describe('applyIdentityTopUpTransitionFactory', () => {
|
|
|
86
94
|
|
|
87
95
|
executionContext.disableDryRun();
|
|
88
96
|
|
|
89
|
-
|
|
97
|
+
const { args: [biggestPossibleIdentity] } = stateRepositoryMock.updateIdentity.firstCall;
|
|
98
|
+
expect(biggestPossibleIdentity.getBalance()).to.be.equal(biggestPossibleBalance);
|
|
90
99
|
|
|
91
100
|
expect(stateRepositoryMock.updateIdentity).to.have.been.calledOnceWithExactly(
|
|
92
101
|
biggestPossibleIdentity,
|
|
93
|
-
|
|
102
|
+
this.sinonSandbox.match.instanceOf(StateTransitionExecutionContext),
|
|
94
103
|
);
|
|
95
104
|
|
|
96
105
|
expect(stateRepositoryMock.markAssetLockTransactionOutPointAsUsed).to.have.been
|
|
97
106
|
.calledOnceWithExactly(
|
|
98
107
|
stateTransition.getAssetLockProof().getOutPoint(),
|
|
99
|
-
executionContext,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
expect(fetchAssetLockTransactionOutputMock)
|
|
103
|
-
.to.be.calledOnceWithExactly(
|
|
104
|
-
stateTransition.getAssetLockProof(),
|
|
105
|
-
executionContext,
|
|
106
108
|
);
|
|
107
109
|
});
|
|
108
110
|
});
|
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
const getIdentityTopUpTransitionFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityTopUpTransitionFixture');
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
);
|
|
3
|
+
const createStateRepositoryMock = require('@dashevo/dpp/lib/test/mocks/createStateRepositoryMock');
|
|
4
|
+
const { default: loadWasmDpp } = require('../../../../../../../dist');
|
|
6
5
|
|
|
7
6
|
describe('validateIdentityTopUpTransitionStateFactory', () => {
|
|
8
7
|
let validateIdentityTopUpTransitionState;
|
|
9
8
|
let stateTransition;
|
|
9
|
+
let stateRepositoryMock;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let IdentityTopUpTransition;
|
|
12
|
+
let IdentityTopUpTransitionStateValidator;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
before(async () => {
|
|
15
|
+
({
|
|
16
|
+
IdentityTopUpTransition,
|
|
17
|
+
IdentityTopUpTransitionStateValidator,
|
|
18
|
+
} = await loadWasmDpp());
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
beforeEach(function () {
|
|
22
|
+
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
23
|
+
|
|
24
|
+
stateTransition = new IdentityTopUpTransition(
|
|
25
|
+
getIdentityTopUpTransitionFixture().toObject(),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const validator = new IdentityTopUpTransitionStateValidator(stateRepositoryMock);
|
|
29
|
+
|
|
30
|
+
validateIdentityTopUpTransitionState = (st) => validator.validate(
|
|
31
|
+
st,
|
|
32
|
+
);
|
|
15
33
|
});
|
|
16
34
|
|
|
17
35
|
it('should return valid result', async () => {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const getChainAssetLockFixture = require('@dashevo/dpp/lib/test/fixtures/getChainAssetLockProofFixture');
|
|
2
|
+
|
|
3
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
4
|
+
|
|
5
|
+
describe('ChainAssetLockProof', () => {
|
|
6
|
+
let ChainAssetLockProof;
|
|
7
|
+
let chainAssetLockProof;
|
|
8
|
+
let chainAssetLockProofJS;
|
|
9
|
+
|
|
10
|
+
before(async () => {
|
|
11
|
+
({ ChainAssetLockProof } = await loadWasmDpp());
|
|
12
|
+
|
|
13
|
+
chainAssetLockProofJS = getChainAssetLockFixture();
|
|
14
|
+
chainAssetLockProof = new ChainAssetLockProof(
|
|
15
|
+
chainAssetLockProofJS.toObject(),
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('#getType', () => {
|
|
20
|
+
it('should return correct type', () => {
|
|
21
|
+
expect(chainAssetLockProof.getType())
|
|
22
|
+
.to.equal(chainAssetLockProofJS.getType());
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('#getCoreChainLockedHeight', () => {
|
|
27
|
+
it('should return correct coreChainLockedHeight', () => {
|
|
28
|
+
expect(chainAssetLockProof.getCoreChainLockedHeight())
|
|
29
|
+
.to.equal(chainAssetLockProofJS.getCoreChainLockedHeight());
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('#getOutPoint', () => {
|
|
34
|
+
it('should return correct outPoint', () => {
|
|
35
|
+
expect(chainAssetLockProof.getOutPoint())
|
|
36
|
+
.to.deep.equal(chainAssetLockProofJS.getOutPoint());
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('#toJSON', () => {
|
|
41
|
+
it('should return correct JSON', () => {
|
|
42
|
+
expect(chainAssetLockProof.toJSON())
|
|
43
|
+
.to.deep.equal(chainAssetLockProofJS.toJSON());
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('#toObject', () => {
|
|
48
|
+
it('should return correct object', () => {
|
|
49
|
+
expect(chainAssetLockProof.toObject())
|
|
50
|
+
.to.deep.equal(chainAssetLockProofJS.toObject());
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('#createIdentifier', () => {
|
|
55
|
+
it('should return correct identifier', () => {
|
|
56
|
+
const identifier = chainAssetLockProof.createIdentifier();
|
|
57
|
+
const identifierJS = chainAssetLockProofJS.createIdentifier();
|
|
58
|
+
|
|
59
|
+
expect(identifier.toBuffer())
|
|
60
|
+
.to.deep.equal(identifierJS.toBuffer());
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const getInstantAssetLockProofFixture = require('@dashevo/dpp/lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
2
|
+
|
|
3
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
4
|
+
|
|
5
|
+
describe('InstantAssetLockProof', () => {
|
|
6
|
+
let InstantAssetLockProof;
|
|
7
|
+
let instantAssetLockProof;
|
|
8
|
+
let instantAssetLockProofJS;
|
|
9
|
+
|
|
10
|
+
before(async () => {
|
|
11
|
+
({ InstantAssetLockProof } = await loadWasmDpp());
|
|
12
|
+
|
|
13
|
+
instantAssetLockProofJS = getInstantAssetLockProofFixture();
|
|
14
|
+
instantAssetLockProof = new InstantAssetLockProof(
|
|
15
|
+
instantAssetLockProofJS.toObject(),
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('#getType', () => {
|
|
20
|
+
it('should return correct type', () => {
|
|
21
|
+
expect(instantAssetLockProof.getType())
|
|
22
|
+
.to.equal(instantAssetLockProofJS.getType());
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('#getOutputIndex', () => {
|
|
27
|
+
it('should return correct type', () => {
|
|
28
|
+
expect(instantAssetLockProof.getOutputIndex())
|
|
29
|
+
.to.equal(instantAssetLockProofJS.getOutputIndex());
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('#getOutPoint', () => {
|
|
34
|
+
it('should return correct outPoint', () => {
|
|
35
|
+
expect(instantAssetLockProof.getOutPoint())
|
|
36
|
+
.to.deep.equal(instantAssetLockProofJS.getOutPoint());
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('#getOutput', () => {
|
|
41
|
+
it('should return correct output', () => {
|
|
42
|
+
expect(instantAssetLockProof.getOutput())
|
|
43
|
+
.to.deep.equal(instantAssetLockProofJS.getOutput().toObject());
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('#createIdentifier', () => {
|
|
48
|
+
it('should return correct identifier', () => {
|
|
49
|
+
const identifier = instantAssetLockProof.createIdentifier();
|
|
50
|
+
const identifierJS = instantAssetLockProofJS.createIdentifier();
|
|
51
|
+
|
|
52
|
+
expect(identifier.toBuffer())
|
|
53
|
+
.to.deep.equal(identifierJS.toBuffer());
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('#getInstantLock', () => {
|
|
58
|
+
it('should return correct instant lock', () => {
|
|
59
|
+
const instantLock = instantAssetLockProof.getInstantLock();
|
|
60
|
+
const instantLockJS = instantAssetLockProofJS.getInstantLock();
|
|
61
|
+
|
|
62
|
+
expect(instantLock)
|
|
63
|
+
.to.deep.equal(instantLockJS.toBuffer());
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('#getTransaction', () => {
|
|
68
|
+
it('should return correct transaction', () => {
|
|
69
|
+
const transaction = instantAssetLockProof.getTransaction();
|
|
70
|
+
const transactionJS = instantAssetLockProofJS.getTransaction();
|
|
71
|
+
|
|
72
|
+
expect(transaction)
|
|
73
|
+
.to.deep.equal(transactionJS.toBuffer());
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('#toObject', () => {
|
|
78
|
+
it('should return correct object', () => {
|
|
79
|
+
expect(instantAssetLockProof.toObject())
|
|
80
|
+
.to.deep.equal(instantAssetLockProofJS.toObject());
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('#toJSON', () => {
|
|
85
|
+
it('should return correct JSON', () => {
|
|
86
|
+
expect(instantAssetLockProof.toJSON())
|
|
87
|
+
.to.deep.equal(instantAssetLockProofJS.toJSON());
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
const
|
|
1
|
+
const createAssetLockProofInstanceJS = require('@dashevo/dpp/lib/identity/stateTransition/assetLockProof/createAssetLockProofInstance');
|
|
2
2
|
const getChainAssetLockFixture = require('@dashevo/dpp/lib/test/fixtures/getChainAssetLockProofFixture');
|
|
3
3
|
const getInstantAssetLockProofFixture = require('@dashevo/dpp/lib/test/fixtures/getInstantAssetLockProofFixture');
|
|
4
|
-
const
|
|
5
|
-
const InstantAssetLockProof = require('@dashevo/dpp/lib/identity/stateTransition/assetLockProof/instant/InstantAssetLockProof');
|
|
4
|
+
const { default: loadWasmDpp } = require('../../../../../dist');
|
|
6
5
|
|
|
7
6
|
describe('createAssetLockProofInstance', () => {
|
|
7
|
+
let createAssetLockProofInstance;
|
|
8
|
+
let InstantAssetLockProof;
|
|
9
|
+
let ChainAssetLockProof;
|
|
10
|
+
|
|
11
|
+
before(async () => {
|
|
12
|
+
({
|
|
13
|
+
createAssetLockProofInstance,
|
|
14
|
+
InstantAssetLockProof,
|
|
15
|
+
ChainAssetLockProof,
|
|
16
|
+
} = await loadWasmDpp());
|
|
17
|
+
});
|
|
18
|
+
|
|
8
19
|
it('should create an instance of InstantAssetLockProof', () => {
|
|
9
20
|
const assetLockProofFixture = getInstantAssetLockProofFixture();
|
|
10
21
|
const instance = createAssetLockProofInstance(assetLockProofFixture.toObject());
|
|
22
|
+
const instanceJS = createAssetLockProofInstanceJS(assetLockProofFixture.toObject());
|
|
11
23
|
|
|
24
|
+
expect(instance.toObject()).to.deep.equal(instanceJS.toObject());
|
|
12
25
|
expect(instance).to.be.an.instanceOf(InstantAssetLockProof);
|
|
13
26
|
});
|
|
14
27
|
|
|
15
28
|
it('should create an instance of ChainAssetLockProof', () => {
|
|
16
29
|
const assetLockProofFixture = getChainAssetLockFixture();
|
|
17
30
|
const instance = createAssetLockProofInstance(assetLockProofFixture.toObject());
|
|
31
|
+
const instanceJS = createAssetLockProofInstanceJS(assetLockProofFixture.toObject());
|
|
18
32
|
|
|
33
|
+
expect(instance.toObject()).to.deep.equal(instanceJS.toObject());
|
|
19
34
|
expect(instance).to.be.an.instanceOf(ChainAssetLockProof);
|
|
20
35
|
});
|
|
21
36
|
});
|