pshenmic-dpp 2.0.0-dev.15 → 2.0.0-dev.17
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/dist/binaries/native/aarch64-apple-darwin/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-apple-darwin/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-unknown-linux-gnu/pshenmic_dpp.node +0 -0
- package/dist/binaries/native/x86_64-unknown-linux-musl/pshenmic_dpp.node +0 -0
- package/dist/binaries/pshenmic_dpp.android.node/arm64-v8a/libpshenmic_dpp.so +0 -0
- package/dist/binaries/pshenmic_dpp.apple.node/ios-arm64-simulator/libpshenmic_dpp.framework/libpshenmic_dpp +0 -0
- package/dist/binaries/wasm/wasmBytes.cjs +1 -1
- package/dist/binaries/wasm/wasmBytes.d.cts +1 -1
- package/dist/binaries/wasm.js +2 -2
- package/dist/binaries/wasmCreation.cjs +2 -1
- package/package.json +3 -2
- package/tests/unit/DataContract.spec.ts +232 -0
- package/tests/unit/TokenConfiguration.spec.ts +114 -0
- package/tests/unit/utils/buildTokenConfiguration.ts +66 -0
package/dist/binaries/wasm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import protocol from "./wasmCreation.cjs";
|
|
2
|
-
export const { verifyAddressesInfos, verifyAddressInfo, verifyContractProof, verifyDocumentsProof, verifyEpochsInfoProof, verifyIdentifierByNonUniquePublicKeyHashProof, verifyIdentityBalanceProof, verifyIdentityByIdentifierProof, verifyIdentityByUniqueKeyHashProof, verifyIdentityContractNonceProof, verifyIdentityKeysByIdentifierProof, verifyIdentityNonceProof, verifySignatureDigest, verifyStateTransitionResult, verifyTokenBalancesForIdentitiesProof, verifyTokenContractInfoProof, verifyTokenDirectPurchasePrices, verifyTokensBalancesForIdentityProof, verifyTokenTotalSupplyProof, verifyTotalCreditsProof, verifyVotePollVoteStateProof, ActionTakerNAPI, AddressCreditWithdrawalTransitionNAPI, AddressFundingFromAssetLockTransitionNAPI, AddressFundsFeeStrategyStepNAPI, AddressFundsTransferTransitionNAPI, AddressWitnessNAPI, AssetLockProofNAPI, AuthorizedActionTakersNAPI, BatchedTransitionNAPI, BatchTransitionNAPI, BlockBasedDistributionNAPI, BlockInfoNAPI, ChainAssetLockProofNAPI, ChangeControlRulesNAPI, ConsensusErrorNAPI, ContenderWithSerializedDocumentNAPI, ContestedDocumentVotePollQueryExecutionResultNAPI, ContractBoundsNAPI, CoreScriptNAPI, DataContractCreateTransitionNAPI, DataContractNAPI, DataContractUpdateTransitionNAPI, DistributionFunctionNAPI, DocumentBaseTransitionNAPI, DocumentCreateTransitionNAPI, DocumentDeleteTransitionNAPI, DocumentNAPI, DocumentPurchaseTransitionNAPI, DocumentReplaceTransitionNAPI, DocumentTransferTransitionNAPI, DocumentTransitionNAPI, DocumentUpdatePriceTransitionNAPI, DynamicValue, EpochBasedDistributionNAPI, ExtendedEpochInfoNAPI, GroupNAPI, GroupStateTransitionInfoNAPI, IdentifierNAPI, IdentityCreateFromAddressesTransitionNAPI, IdentityCreateTransitionNAPI, IdentityCreditTransferNAPI, IdentityCreditTransferToAddressesTransitionNAPI, IdentityCreditWithdrawalTransitionNAPI, IdentityNAPI, IdentityPublicKeyInCreationNAPI, IdentityPublicKeyNAPI, IdentityTokenBalanceNAPI, IdentityTokenBalanceOptionalNAPI, IdentityTokenInfoNAPI, IdentityTopUpFromAddressesTransitionNAPI, IdentityTopUpTransitionNAPI, IdentityUpdateTransitionNAPI, InputAddressNAPI, InstantAssetLockProofNAPI, InstantLockNAPI, MasternodeVoteTransitionNAPI, OutPointNAPI, OutputAddressNAPI, OutputAddressNullableCreditsNAPI, PartialIdentityNAPI, PlatformAddressInfoNAPI, PlatformAddressNAPI, PrefundedVotingBalanceNAPI, PrivateEncryptedNoteNAPI, PrivateKeyNAPI, PublicKeyNAPI, ResourceVoteChoiceNAPI, RewardDistributionTypeNAPI, SharedEncryptedNoteNAPI, StateTransitionNAPI, TimeBasedDistributionNAPI, TokenBaseTransitionNAPI, TokenBurnTransitionNAPI, TokenClaimTransitionNAPI, TokenConfigUpdateTransitionNAPI, TokenConfigurationChangeItemNAPI, TokenConfigurationConventionNAPI, TokenConfigurationLocalizationNAPI, TokenConfigurationNAPI, TokenContractInfoNAPI, TokenDestroyFrozenFundsTransitionNAPI, TokenDirectPurchaseTransitionNAPI, TokenDistributionRecipientNAPI, TokenDistributionRulesNAPI, TokenEmergencyActionTransitionNAPI, TokenFreezeTransitionNAPI, TokenKeepsHistoryRulesNAPI, TokenMarketplaceRulesNAPI, TokenMintTransitionNAPI, TokenPaymentInfoNAPI, TokenPerpetualDistributionNAPI, TokenPreProgrammedDistributionNAPI, TokenPricingScheduleNAPI, TokenSetPriceForDirectPurchaseTransitionNAPI, TokenStatusNAPI, TokenTradeModeNAPI, TokenTransferTransitionNAPI, TokenTransitionNAPI, TokenUnFreezeTransitionNAPI, TotalSingleTokenBalanceNAPI, TransactionNAPI, TxInNAPI, TxOutNAPI, VerifiedBalanceTransferNAPI, VerifiedContractNAPI, VerifiedDocumentNAPI, VerifiedDocumentsNAPI, VerifiedEpochsInfoNAPI, VerifiedIdentifierByNonUniquePublicKeyHashNAPI, VerifiedIdentityBalanceRootHashNAPI, VerifiedIdentityByIdentifierNAPI, VerifiedIdentityByUniqueKeyHashNAPI, VerifiedIdentityContractNonceNAPI, VerifiedIdentityFullWithAddressInfosNAPI, VerifiedIdentityKeysByIdentifierNAPI, VerifiedIdentityNonceNAPI, VerifiedIdentityTokenInfoNAPI, VerifiedIdentityWithAddressInfosNAPI, VerifiedPlatformAddressesInfosNAPI, VerifiedPlatformAddressInfoNAPI, VerifiedStateTransitionResultNAPI, VerifiedTokenBalancesForIdentitiesNAPI, VerifiedTokenContractInfoNAPI, VerifiedTokenDirectPurchasePricesNAPI, VerifiedTokenGroupActionWithDocumentNAPI, VerifiedTokenGroupActionWithTokenBalanceNAPI, VerifiedTokenGroupActionWithTokenIdentityInfoNAPI, VerifiedTokenGroupActionWithTokenPricingScheduleNAPI, VerifiedTokenPricingScheduleNAPI, VerifiedTokensBalancesForIdentityNAPI, VerifiedTokenTotalSupplyNAPI, VerifiedTotalCreditsNAPI, VerifiedVoteStateNAPI, VoteNAPI, VotePollNAPI, WitnessNAPI, ActionGoalNAPI, AssetLockProofTypeNAPI, BatchTypeNAPI, GasFeesPaidByNAPI, GroupActionStatusNAPI, KeyTypeNAPI, NetworkNAPI, PlatformVersionNAPI, PoolingNAPI, PurposeNAPI, SecurityLevelNAPI, TokenDistributionTypeNAPI, TokenEmergencyActionNAPI, VoteStateResultTypeNAPI } = protocol;
|
|
1
|
+
import * as protocol from "./wasmCreation.cjs";
|
|
2
|
+
export const { verifyAddressesInfos, verifyAddressInfo, verifyContractProof, verifyDocumentsProof, verifyEpochsInfoProof, verifyIdentifierByNonUniquePublicKeyHashProof, verifyIdentityBalanceProof, verifyIdentityByIdentifierProof, verifyIdentityByUniqueKeyHashProof, verifyIdentityContractNonceProof, verifyIdentityKeysByIdentifierProof, verifyIdentityNonceProof, verifySignatureDigest, verifyStateTransitionResult, verifyTokenBalancesForIdentitiesProof, verifyTokenContractInfoProof, verifyTokenDirectPurchasePrices, verifyTokensBalancesForIdentityProof, verifyTokenTotalSupplyProof, verifyTotalCreditsProof, verifyVotePollVoteStateProof, ActionTakerNAPI, AddressCreditWithdrawalTransitionNAPI, AddressFundingFromAssetLockTransitionNAPI, AddressFundsFeeStrategyStepNAPI, AddressFundsTransferTransitionNAPI, AddressWitnessNAPI, AssetLockProofNAPI, AuthorizedActionTakersNAPI, BatchedTransitionNAPI, BatchTransitionNAPI, BlockBasedDistributionNAPI, BlockInfoNAPI, ChainAssetLockProofNAPI, ChangeControlRulesNAPI, ConsensusErrorNAPI, ContenderWithSerializedDocumentNAPI, ContestedDocumentVotePollQueryExecutionResultNAPI, ContractBoundsNAPI, CoreScriptNAPI, DataContractCreateTransitionNAPI, DataContractNAPI, DataContractUpdateTransitionNAPI, DistributionFunctionNAPI, DocumentBaseTransitionNAPI, DocumentCreateTransitionNAPI, DocumentDeleteTransitionNAPI, DocumentNAPI, DocumentPurchaseTransitionNAPI, DocumentReplaceTransitionNAPI, DocumentTransferTransitionNAPI, DocumentTransitionNAPI, DocumentUpdatePriceTransitionNAPI, DynamicValue, EpochBasedDistributionNAPI, ExtendedEpochInfoNAPI, GroupNAPI, GroupStateTransitionInfoNAPI, IdentifierNAPI, IdentityCreateFromAddressesTransitionNAPI, IdentityCreateTransitionNAPI, IdentityCreditTransferNAPI, IdentityCreditTransferToAddressesTransitionNAPI, IdentityCreditWithdrawalTransitionNAPI, IdentityNAPI, IdentityPublicKeyInCreationNAPI, IdentityPublicKeyNAPI, IdentityTokenBalanceNAPI, IdentityTokenBalanceOptionalNAPI, IdentityTokenInfoNAPI, IdentityTopUpFromAddressesTransitionNAPI, IdentityTopUpTransitionNAPI, IdentityUpdateTransitionNAPI, InputAddressNAPI, InstantAssetLockProofNAPI, InstantLockNAPI, MasternodeVoteTransitionNAPI, OutPointNAPI, OutputAddressNAPI, OutputAddressNullableCreditsNAPI, PartialIdentityNAPI, PlatformAddressInfoNAPI, PlatformAddressNAPI, PrefundedVotingBalanceNAPI, PrivateEncryptedNoteNAPI, PrivateKeyNAPI, PublicKeyNAPI, ResourceVoteChoiceNAPI, RewardDistributionTypeNAPI, SharedEncryptedNoteNAPI, StateTransitionNAPI, TimeBasedDistributionNAPI, TokenBaseTransitionNAPI, TokenBurnTransitionNAPI, TokenClaimTransitionNAPI, TokenConfigUpdateTransitionNAPI, TokenConfigurationChangeItemNAPI, TokenConfigurationConventionNAPI, TokenConfigurationLocalizationNAPI, TokenConfigurationNAPI, TokenContractInfoNAPI, TokenDestroyFrozenFundsTransitionNAPI, TokenDirectPurchaseTransitionNAPI, TokenDistributionRecipientNAPI, TokenDistributionRulesNAPI, TokenEmergencyActionTransitionNAPI, TokenFreezeTransitionNAPI, TokenKeepsHistoryRulesNAPI, TokenMarketplaceRulesNAPI, TokenMintTransitionNAPI, TokenPaymentInfoNAPI, TokenPerpetualDistributionNAPI, TokenPreProgrammedDistributionNAPI, TokenPricingScheduleNAPI, TokenSetPriceForDirectPurchaseTransitionNAPI, TokenStatusNAPI, TokenTradeModeNAPI, TokenTransferTransitionNAPI, TokenTransitionNAPI, TokenUnFreezeTransitionNAPI, TotalSingleTokenBalanceNAPI, TransactionNAPI, TxInNAPI, TxOutNAPI, VerifiedBalanceTransferNAPI, VerifiedContractNAPI, VerifiedDocumentNAPI, VerifiedDocumentsNAPI, VerifiedEpochsInfoNAPI, VerifiedIdentifierByNonUniquePublicKeyHashNAPI, VerifiedIdentityBalanceRootHashNAPI, VerifiedIdentityByIdentifierNAPI, VerifiedIdentityByUniqueKeyHashNAPI, VerifiedIdentityContractNonceNAPI, VerifiedIdentityFullWithAddressInfosNAPI, VerifiedIdentityKeysByIdentifierNAPI, VerifiedIdentityNonceNAPI, VerifiedIdentityTokenInfoNAPI, VerifiedIdentityWithAddressInfosNAPI, VerifiedPlatformAddressesInfosNAPI, VerifiedPlatformAddressInfoNAPI, VerifiedStateTransitionResultNAPI, VerifiedTokenBalancesForIdentitiesNAPI, VerifiedTokenContractInfoNAPI, VerifiedTokenDirectPurchasePricesNAPI, VerifiedTokenGroupActionWithDocumentNAPI, VerifiedTokenGroupActionWithTokenBalanceNAPI, VerifiedTokenGroupActionWithTokenIdentityInfoNAPI, VerifiedTokenGroupActionWithTokenPricingScheduleNAPI, VerifiedTokenPricingScheduleNAPI, VerifiedTokensBalancesForIdentityNAPI, VerifiedTokenTotalSupplyNAPI, VerifiedTotalCreditsNAPI, VerifiedVoteStateNAPI, VoteNAPI, VotePollNAPI, WitnessNAPI, ActionGoalNAPI, AssetLockProofTypeNAPI, BatchTypeNAPI, GasFeesPaidByNAPI, GroupActionStatusNAPI, KeyTypeNAPI, NetworkNAPI, PlatformVersionNAPI, PoolingNAPI, PurposeNAPI, SecurityLevelNAPI, TokenDistributionTypeNAPI, TokenEmergencyActionNAPI, VoteStateResultTypeNAPI } = protocol.default;
|
|
@@ -3,7 +3,7 @@ const { WASI } = require('@tybys/wasm-util');
|
|
|
3
3
|
const { getDefaultContext } = require('@emnapi/runtime');
|
|
4
4
|
const { instantiateNapiModuleSync } = require('@emnapi/core');
|
|
5
5
|
const { bytes } = require('./wasm/wasmBytes.cjs');
|
|
6
|
-
const { decode } = require('../utils/base122.
|
|
6
|
+
const { decode } = require('../utils/base122.cjs');
|
|
7
7
|
const { decompressSync } = require('fflate');
|
|
8
8
|
const wasmBytes = new Uint8Array(decode(bytes));
|
|
9
9
|
const wasi = new WASI({
|
|
@@ -43,3 +43,4 @@ const wasm = instantiateNapiModuleSync(decompressSync(wasmBytes), {
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
module.exports = wasm.napiModule.exports;
|
|
46
|
+
module.exports.default = wasm.napiModule.exports;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pshenmic-dpp",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.17",
|
|
4
4
|
"main": "dist/src/wasm.js",
|
|
5
5
|
"types": "dist/src/wasm.d.ts",
|
|
6
6
|
"react-native": "./dist/src/react-native.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/owl352/pshenmic-dpp"
|
|
10
|
+
"url": "git+https://github.com/owl352/pshenmic-dpp.git"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build:bin": "node build.cjs",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
+
"browser": "./dist/src/wasm.js",
|
|
32
33
|
"node": "./dist/src/native.js",
|
|
33
34
|
"react-native": "./dist/src/react-native.js",
|
|
34
35
|
"default": "./dist/src/wasm.js"
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { DataContractWASM, IdentifierWASM, PlatformVersionWASM } from 'pshenmic-dpp'
|
|
2
|
+
import { buildTokenConfiguration } from './utils/buildTokenConfiguration'
|
|
3
|
+
|
|
4
|
+
const OWNER_ID_BASE58 = 'HEAmUtC72dPcZ59yyLUgfS8pfrEWqzYfDPzTofgWxXRr'
|
|
5
|
+
|
|
6
|
+
const DOCUMENT_SCHEMA = {
|
|
7
|
+
note: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
message: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
position: 0
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
additionalProperties: false
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('DataContract', function () {
|
|
20
|
+
describe('constructor', function () {
|
|
21
|
+
test('should create a contract with document schemas only', function () {
|
|
22
|
+
const contract = new DataContractWASM(
|
|
23
|
+
OWNER_ID_BASE58,
|
|
24
|
+
BigInt(1),
|
|
25
|
+
DOCUMENT_SCHEMA,
|
|
26
|
+
undefined,
|
|
27
|
+
undefined,
|
|
28
|
+
true,
|
|
29
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
expect(contract).toBeInstanceOf(DataContractWASM)
|
|
33
|
+
expect(contract.ownerId.base58()).toEqual(OWNER_ID_BASE58)
|
|
34
|
+
expect(contract.tokens.length).toEqual(0)
|
|
35
|
+
expect(Object.keys(contract.getSchemas())).toEqual(['note'])
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('should create a tokens-only contract (no document schemas)', function () {
|
|
39
|
+
const tokenConfig = buildTokenConfiguration()
|
|
40
|
+
|
|
41
|
+
const contract = new DataContractWASM(
|
|
42
|
+
OWNER_ID_BASE58,
|
|
43
|
+
BigInt(1),
|
|
44
|
+
{},
|
|
45
|
+
undefined,
|
|
46
|
+
[{ position: 0, tokenConfiguration: tokenConfig }],
|
|
47
|
+
true,
|
|
48
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
expect(contract).toBeInstanceOf(DataContractWASM)
|
|
52
|
+
expect(contract.tokens.length).toEqual(1)
|
|
53
|
+
expect(contract.tokens[0].position).toEqual(0)
|
|
54
|
+
expect(contract.tokens[0].tokenConfiguration.baseSupply).toEqual(BigInt(100000))
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('should fail to create a contract with neither documents nor tokens', function () {
|
|
58
|
+
expect(() => new DataContractWASM(
|
|
59
|
+
OWNER_ID_BASE58,
|
|
60
|
+
BigInt(1),
|
|
61
|
+
{},
|
|
62
|
+
undefined,
|
|
63
|
+
undefined,
|
|
64
|
+
true,
|
|
65
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
66
|
+
)).toThrow()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('should create a contract with both documents and tokens', function () {
|
|
70
|
+
const tokenConfig = buildTokenConfiguration({ baseSupply: BigInt(50) })
|
|
71
|
+
|
|
72
|
+
const contract = new DataContractWASM(
|
|
73
|
+
OWNER_ID_BASE58,
|
|
74
|
+
BigInt(1),
|
|
75
|
+
DOCUMENT_SCHEMA,
|
|
76
|
+
undefined,
|
|
77
|
+
[{ position: 0, tokenConfiguration: tokenConfig }],
|
|
78
|
+
true,
|
|
79
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
expect(contract.tokens.length).toEqual(1)
|
|
83
|
+
expect(Object.keys(contract.getSchemas())).toEqual(['note'])
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('should generate a deterministic id from owner id and nonce', function () {
|
|
87
|
+
const contract = new DataContractWASM(
|
|
88
|
+
OWNER_ID_BASE58,
|
|
89
|
+
BigInt(42),
|
|
90
|
+
DOCUMENT_SCHEMA,
|
|
91
|
+
undefined,
|
|
92
|
+
undefined,
|
|
93
|
+
true,
|
|
94
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
const expectedId = DataContractWASM.generateId(OWNER_ID_BASE58, BigInt(42))
|
|
98
|
+
|
|
99
|
+
expect(contract.id.base58()).toEqual(expectedId.base58())
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe('serialization', function () {
|
|
104
|
+
test('should serialize / deserialize via bytes', function () {
|
|
105
|
+
const contract = new DataContractWASM(
|
|
106
|
+
OWNER_ID_BASE58,
|
|
107
|
+
BigInt(1),
|
|
108
|
+
DOCUMENT_SCHEMA,
|
|
109
|
+
undefined,
|
|
110
|
+
undefined,
|
|
111
|
+
true,
|
|
112
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
const bytes = contract.bytes(PlatformVersionWASM.PLATFORM_V10)
|
|
116
|
+
const restored = DataContractWASM.fromBytes(bytes, true, PlatformVersionWASM.PLATFORM_V10)
|
|
117
|
+
|
|
118
|
+
expect(restored.id.base58()).toEqual(contract.id.base58())
|
|
119
|
+
expect(restored.ownerId.base58()).toEqual(contract.ownerId.base58())
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('should serialize / deserialize a tokens-only contract via bytes', function () {
|
|
123
|
+
const tokenConfig = buildTokenConfiguration()
|
|
124
|
+
|
|
125
|
+
const contract = new DataContractWASM(
|
|
126
|
+
OWNER_ID_BASE58,
|
|
127
|
+
BigInt(1),
|
|
128
|
+
{},
|
|
129
|
+
undefined,
|
|
130
|
+
[{ position: 0, tokenConfiguration: tokenConfig }],
|
|
131
|
+
true,
|
|
132
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
const bytes = contract.bytes(PlatformVersionWASM.PLATFORM_V10)
|
|
136
|
+
const restored = DataContractWASM.fromBytes(bytes, true, PlatformVersionWASM.PLATFORM_V10)
|
|
137
|
+
|
|
138
|
+
expect(restored.tokens.length).toEqual(1)
|
|
139
|
+
expect(restored.tokens[0].tokenConfiguration.baseSupply).toEqual(tokenConfig.baseSupply)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('should round-trip via hex', function () {
|
|
143
|
+
const contract = new DataContractWASM(
|
|
144
|
+
OWNER_ID_BASE58,
|
|
145
|
+
BigInt(1),
|
|
146
|
+
DOCUMENT_SCHEMA,
|
|
147
|
+
undefined,
|
|
148
|
+
undefined,
|
|
149
|
+
true,
|
|
150
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
const hex = contract.hex(PlatformVersionWASM.PLATFORM_V10)
|
|
154
|
+
const restored = DataContractWASM.fromHex(hex, true, PlatformVersionWASM.PLATFORM_V10)
|
|
155
|
+
|
|
156
|
+
expect(restored.id.base58()).toEqual(contract.id.base58())
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test('should round-trip via base64', function () {
|
|
160
|
+
const contract = new DataContractWASM(
|
|
161
|
+
OWNER_ID_BASE58,
|
|
162
|
+
BigInt(1),
|
|
163
|
+
DOCUMENT_SCHEMA,
|
|
164
|
+
undefined,
|
|
165
|
+
undefined,
|
|
166
|
+
true,
|
|
167
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
const b64 = contract.base64(PlatformVersionWASM.PLATFORM_V10)
|
|
171
|
+
const restored = DataContractWASM.fromBase64(b64, true, PlatformVersionWASM.PLATFORM_V10)
|
|
172
|
+
|
|
173
|
+
expect(restored.id.base58()).toEqual(contract.id.base58())
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
describe('mutators', function () {
|
|
178
|
+
test('should allow setting tokens after construction', function () {
|
|
179
|
+
const contract = new DataContractWASM(
|
|
180
|
+
OWNER_ID_BASE58,
|
|
181
|
+
BigInt(1),
|
|
182
|
+
DOCUMENT_SCHEMA,
|
|
183
|
+
undefined,
|
|
184
|
+
undefined,
|
|
185
|
+
true,
|
|
186
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
expect(contract.tokens.length).toEqual(0)
|
|
190
|
+
|
|
191
|
+
contract.tokens = [{ position: 0, tokenConfiguration: buildTokenConfiguration() }]
|
|
192
|
+
|
|
193
|
+
expect(contract.tokens.length).toEqual(1)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test('should allow setting and reading description / keywords', function () {
|
|
197
|
+
const contract = new DataContractWASM(
|
|
198
|
+
OWNER_ID_BASE58,
|
|
199
|
+
BigInt(1),
|
|
200
|
+
DOCUMENT_SCHEMA,
|
|
201
|
+
undefined,
|
|
202
|
+
undefined,
|
|
203
|
+
true,
|
|
204
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
contract.description = 'test contract'
|
|
208
|
+
contract.keywords = ['alpha', 'beta']
|
|
209
|
+
|
|
210
|
+
expect(contract.description).toEqual('test contract')
|
|
211
|
+
expect(contract.keywords).toEqual(['alpha', 'beta'])
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('should allow changing the owner id', function () {
|
|
215
|
+
const contract = new DataContractWASM(
|
|
216
|
+
OWNER_ID_BASE58,
|
|
217
|
+
BigInt(1),
|
|
218
|
+
DOCUMENT_SCHEMA,
|
|
219
|
+
undefined,
|
|
220
|
+
undefined,
|
|
221
|
+
true,
|
|
222
|
+
PlatformVersionWASM.PLATFORM_V10
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
const newOwner = new IdentifierWASM('ckBqfQe7LU7vwrwXopyCB4n5phZShjA16BGhNGpsD5U')
|
|
226
|
+
|
|
227
|
+
contract.ownerId = newOwner
|
|
228
|
+
|
|
229
|
+
expect(contract.ownerId.base58()).toEqual(newOwner.base58())
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthorizedActionTakersWASM,
|
|
3
|
+
IdentifierWASM,
|
|
4
|
+
TokenConfigurationWASM
|
|
5
|
+
} from 'pshenmic-dpp'
|
|
6
|
+
import { buildTokenConfiguration } from './utils/buildTokenConfiguration'
|
|
7
|
+
|
|
8
|
+
describe('TokenConfiguration', function () {
|
|
9
|
+
describe('constructor', function () {
|
|
10
|
+
test('should build a token configuration with defaults from the helper', function () {
|
|
11
|
+
const config = buildTokenConfiguration()
|
|
12
|
+
|
|
13
|
+
expect(config).toBeInstanceOf(TokenConfigurationWASM)
|
|
14
|
+
expect(config.baseSupply).toEqual(BigInt(100000))
|
|
15
|
+
expect(config.maxSupply).toBeUndefined()
|
|
16
|
+
expect(config.description).toBeUndefined()
|
|
17
|
+
expect(config.startAsPaused).toEqual(false)
|
|
18
|
+
expect(config.isAllowedTransferToFrozenBalance).toEqual(false)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('should set max supply and description when provided', function () {
|
|
22
|
+
const config = buildTokenConfiguration({
|
|
23
|
+
baseSupply: BigInt(500),
|
|
24
|
+
maxSupply: BigInt(1000),
|
|
25
|
+
description: 'hello'
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
expect(config.baseSupply).toEqual(BigInt(500))
|
|
29
|
+
expect(config.maxSupply).toEqual(BigInt(1000))
|
|
30
|
+
expect(config.description).toEqual('hello')
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('getters', function () {
|
|
35
|
+
test('should expose the convention decimals', function () {
|
|
36
|
+
const config = buildTokenConfiguration()
|
|
37
|
+
|
|
38
|
+
expect(config.conventions.decimals).toEqual(8)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('should default mainControlGroup to undefined', function () {
|
|
42
|
+
const config = buildTokenConfiguration()
|
|
43
|
+
|
|
44
|
+
expect(config.mainControlGroup).toBeUndefined()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('setters', function () {
|
|
49
|
+
test('should allow updating baseSupply', function () {
|
|
50
|
+
const config = buildTokenConfiguration()
|
|
51
|
+
|
|
52
|
+
config.baseSupply = BigInt(7)
|
|
53
|
+
|
|
54
|
+
expect(config.baseSupply).toEqual(BigInt(7))
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('should allow updating maxSupply to a value and back to undefined', function () {
|
|
58
|
+
const config = buildTokenConfiguration()
|
|
59
|
+
|
|
60
|
+
config.maxSupply = BigInt(42)
|
|
61
|
+
expect(config.maxSupply).toEqual(BigInt(42))
|
|
62
|
+
|
|
63
|
+
config.maxSupply = undefined
|
|
64
|
+
expect(config.maxSupply).toBeUndefined()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('should allow updating description', function () {
|
|
68
|
+
const config = buildTokenConfiguration()
|
|
69
|
+
|
|
70
|
+
config.description = 'updated'
|
|
71
|
+
|
|
72
|
+
expect(config.description).toEqual('updated')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('should allow updating startAsPaused / isAllowedTransferToFrozenBalance', function () {
|
|
76
|
+
const config = buildTokenConfiguration()
|
|
77
|
+
|
|
78
|
+
config.startAsPaused = true
|
|
79
|
+
config.isAllowedTransferToFrozenBalance = true
|
|
80
|
+
|
|
81
|
+
expect(config.startAsPaused).toEqual(true)
|
|
82
|
+
expect(config.isAllowedTransferToFrozenBalance).toEqual(true)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('should allow updating mainControlGroup', function () {
|
|
86
|
+
const config = buildTokenConfiguration()
|
|
87
|
+
|
|
88
|
+
config.mainControlGroup = 3
|
|
89
|
+
|
|
90
|
+
expect(config.mainControlGroup).toEqual(3)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('should allow updating mainControlGroupCanBeModified', function () {
|
|
94
|
+
const config = buildTokenConfiguration()
|
|
95
|
+
|
|
96
|
+
config.mainControlGroupCanBeModified = AuthorizedActionTakersWASM.ContractOwner()
|
|
97
|
+
|
|
98
|
+
expect(config.mainControlGroupCanBeModified).toBeDefined()
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('calculateTokenId', function () {
|
|
103
|
+
test('should derive a deterministic token id from a contract id and position', function () {
|
|
104
|
+
const contractId = new IdentifierWASM('HEAmUtC72dPcZ59yyLUgfS8pfrEWqzYfDPzTofgWxXRr')
|
|
105
|
+
|
|
106
|
+
const tokenIdA = TokenConfigurationWASM.calculateTokenId(contractId, 0)
|
|
107
|
+
const tokenIdB = TokenConfigurationWASM.calculateTokenId(contractId, 0)
|
|
108
|
+
const tokenIdC = TokenConfigurationWASM.calculateTokenId(contractId, 1)
|
|
109
|
+
|
|
110
|
+
expect(tokenIdA.base58()).toEqual(tokenIdB.base58())
|
|
111
|
+
expect(tokenIdA.base58()).not.toEqual(tokenIdC.base58())
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthorizedActionTakersWASM,
|
|
3
|
+
ChangeControlRulesWASM,
|
|
4
|
+
TokenConfigurationConventionWASM,
|
|
5
|
+
TokenConfigurationWASM,
|
|
6
|
+
TokenDistributionRulesWASM,
|
|
7
|
+
TokenKeepsHistoryRulesWASM,
|
|
8
|
+
TokenMarketplaceRulesWASM,
|
|
9
|
+
TokenTradeModeWASM
|
|
10
|
+
} from 'pshenmic-dpp'
|
|
11
|
+
|
|
12
|
+
export function buildChangeControlRules (): ChangeControlRulesWASM {
|
|
13
|
+
return new ChangeControlRulesWASM(
|
|
14
|
+
AuthorizedActionTakersWASM.NoOne(),
|
|
15
|
+
AuthorizedActionTakersWASM.NoOne(),
|
|
16
|
+
false,
|
|
17
|
+
false,
|
|
18
|
+
false
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function buildTokenConfiguration (
|
|
23
|
+
overrides: { baseSupply?: bigint, maxSupply?: bigint, description?: string } = {}
|
|
24
|
+
): TokenConfigurationWASM {
|
|
25
|
+
const conventions = new TokenConfigurationConventionWASM({}, 8)
|
|
26
|
+
|
|
27
|
+
const keepsHistory = new TokenKeepsHistoryRulesWASM(false, false, false, false, false, false)
|
|
28
|
+
|
|
29
|
+
const distributionRules = new TokenDistributionRulesWASM(
|
|
30
|
+
buildChangeControlRules(),
|
|
31
|
+
buildChangeControlRules(),
|
|
32
|
+
false,
|
|
33
|
+
buildChangeControlRules(),
|
|
34
|
+
buildChangeControlRules(),
|
|
35
|
+
undefined,
|
|
36
|
+
undefined,
|
|
37
|
+
undefined
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const marketplaceRules = new TokenMarketplaceRulesWASM(
|
|
41
|
+
TokenTradeModeWASM.NotTradeable(),
|
|
42
|
+
buildChangeControlRules()
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return new TokenConfigurationWASM(
|
|
46
|
+
conventions,
|
|
47
|
+
buildChangeControlRules(),
|
|
48
|
+
overrides.baseSupply ?? BigInt(100000),
|
|
49
|
+
keepsHistory,
|
|
50
|
+
false,
|
|
51
|
+
false,
|
|
52
|
+
buildChangeControlRules(),
|
|
53
|
+
distributionRules,
|
|
54
|
+
marketplaceRules,
|
|
55
|
+
buildChangeControlRules(),
|
|
56
|
+
buildChangeControlRules(),
|
|
57
|
+
buildChangeControlRules(),
|
|
58
|
+
buildChangeControlRules(),
|
|
59
|
+
buildChangeControlRules(),
|
|
60
|
+
buildChangeControlRules(),
|
|
61
|
+
AuthorizedActionTakersWASM.NoOne(),
|
|
62
|
+
overrides.maxSupply,
|
|
63
|
+
undefined,
|
|
64
|
+
overrides.description
|
|
65
|
+
)
|
|
66
|
+
}
|