@dashevo/wasm-dpp 0.24.0-dev.10 → 0.24.0-dev.11

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.
Files changed (24) hide show
  1. package/Cargo.toml +2 -0
  2. package/dist/index.js +1 -1
  3. package/dist/wasm/wasm_dpp.d.ts +277 -183
  4. package/package.json +3 -3
  5. package/src/data_contract/state_transition/data_contract_create_transition/apply.rs +44 -0
  6. package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +103 -2
  7. package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +24 -0
  8. package/src/document/errors/document_already_exists_error.rs +1 -1
  9. package/src/document/errors/document_not_provided_error.rs +1 -1
  10. package/src/document/errors/invalid_document_action_error.rs +1 -1
  11. package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_condition_error.rs +1 -1
  12. package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_execution_error.rs +1 -1
  13. package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_invalid_result_error.rs +1 -1
  14. package/src/lib.rs +3 -2
  15. package/src/state_repository.rs +229 -0
  16. package/src/state_transition/mod.rs +41 -0
  17. package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +17 -64
  18. package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +28 -22
  19. package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +47 -44
  20. package/wasm/wasm_dpp.d.ts +277 -183
  21. package/wasm/wasm_dpp.js +473 -245
  22. package/wasm/wasm_dpp_bg.js +1 -1
  23. package/wasm/wasm_dpp_bg.wasm +0 -0
  24. package/wasm/wasm_dpp_bg.wasm.d.ts +201 -183
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/wasm-dpp",
3
- "version": "0.24.0-dev.10",
3
+ "version": "0.24.0-dev.11",
4
4
  "description": "The JavaScript implementation of the Dash Platform Protocol",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,8 +35,8 @@
35
35
  "devDependencies": {
36
36
  "@apidevtools/json-schema-ref-parser": "^8.0.0",
37
37
  "@dashevo/dashcore-lib": "~0.19.44",
38
- "@dashevo/dpns-contract": "0.24.0-dev.10",
39
- "@dashevo/dpp": "0.24.0-dev.10",
38
+ "@dashevo/dpns-contract": "0.24.0-dev.11",
39
+ "@dashevo/dpp": "0.24.0-dev.11",
40
40
  "@dashevo/wasm-re2": "~1.0.2",
41
41
  "@types/node": "^14.6.0",
42
42
  "ajv": "^8.6.0",
@@ -0,0 +1,44 @@
1
+ use std::ops::Deref;
2
+
3
+ use dpp::data_contract::state_transition::apply_data_contract_create_transition_factory::ApplyDataContractCreateTransition;
4
+ use wasm_bindgen::prelude::*;
5
+
6
+ use crate::{
7
+ state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
8
+ DataContractCreateTransitionWasm,
9
+ };
10
+
11
+ #[wasm_bindgen(js_name=ApplyDataContractCreateTransition)]
12
+ pub struct ApplyDataContractCreateTransitionWasm(
13
+ ApplyDataContractCreateTransition<ExternalStateRepositoryLikeWrapper>,
14
+ );
15
+
16
+ impl From<ApplyDataContractCreateTransition<ExternalStateRepositoryLikeWrapper>>
17
+ for ApplyDataContractCreateTransitionWasm
18
+ {
19
+ fn from(wa: ApplyDataContractCreateTransition<ExternalStateRepositoryLikeWrapper>) -> Self {
20
+ ApplyDataContractCreateTransitionWasm(wa)
21
+ }
22
+ }
23
+
24
+ #[wasm_bindgen(js_class=ApplyDataContractCreateTransition)]
25
+ impl ApplyDataContractCreateTransitionWasm {
26
+ #[wasm_bindgen(constructor)]
27
+ pub fn new(
28
+ state_repository: ExternalStateRepositoryLike,
29
+ ) -> ApplyDataContractCreateTransitionWasm {
30
+ let pinned_js_state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
31
+ ApplyDataContractCreateTransition::new(pinned_js_state_repository).into()
32
+ }
33
+
34
+ #[wasm_bindgen(js_name=applyDataContractCreateTransition)]
35
+ pub async fn apply_data_contract_create_transition(
36
+ &self,
37
+ transition: DataContractCreateTransitionWasm,
38
+ ) -> Result<(), JsError> {
39
+ self.0
40
+ .apply_data_contract_create_transition(&transition.into())
41
+ .await
42
+ .map_err(|e| e.deref().into())
43
+ }
44
+ }
@@ -1,7 +1,24 @@
1
- use dpp::data_contract::state_transition::DataContractCreateTransition;
1
+ mod apply;
2
+ mod validation;
3
+
4
+ pub use apply::*;
5
+ pub use validation::*;
6
+
7
+ use dpp::{
8
+ data_contract::state_transition::DataContractCreateTransition,
9
+ state_transition::{
10
+ StateTransitionConvert, StateTransitionIdentitySigned, StateTransitionLike,
11
+ },
12
+ };
13
+ use serde::{Deserialize, Serialize};
2
14
  use wasm_bindgen::prelude::*;
3
15
 
4
- use crate::{buffer::Buffer, DataContractWasm};
16
+ use crate::{
17
+ buffer::Buffer,
18
+ errors::{from_dpp_err, RustConversionError},
19
+ identifier::IdentifierWrapper,
20
+ with_js_error, DataContractParameters, DataContractWasm, StateTransitionExecutionContextWasm,
21
+ };
5
22
 
6
23
  #[wasm_bindgen(js_name=DataContractCreateTransition)]
7
24
  pub struct DataContractCreateTransitionWasm(DataContractCreateTransition);
@@ -18,8 +35,33 @@ impl Into<DataContractCreateTransition> for DataContractCreateTransitionWasm {
18
35
  }
19
36
  }
20
37
 
38
+ #[derive(Debug, Serialize, Deserialize)]
39
+ #[serde(rename_all = "camelCase")]
40
+ struct DataContractCreateTransitionParameters {
41
+ protocol_version: u32,
42
+ #[serde(skip_serializing_if = "Option::is_none", default)]
43
+ data_contract: Option<DataContractParameters>,
44
+ #[serde(skip_serializing_if = "Option::is_none", default)]
45
+ entropy: Option<Vec<u8>>,
46
+ #[serde(skip_serializing_if = "Option::is_none", default)]
47
+ signature_public_key_id: Option<u64>,
48
+ #[serde(skip_serializing_if = "Option::is_none", default)]
49
+ signature: Option<Vec<u8>>,
50
+ }
51
+
21
52
  #[wasm_bindgen(js_class=DataContractCreateTransition)]
22
53
  impl DataContractCreateTransitionWasm {
54
+ #[wasm_bindgen(constructor)]
55
+ pub fn new(raw_parameters: JsValue) -> Result<DataContractCreateTransitionWasm, JsValue> {
56
+ let parameters: DataContractCreateTransitionParameters =
57
+ with_js_error!(serde_wasm_bindgen::from_value(raw_parameters))?;
58
+ DataContractCreateTransition::from_raw_object(
59
+ serde_json::to_value(parameters).expect("the struct will be a valid json"),
60
+ )
61
+ .map(Into::into)
62
+ .map_err(from_dpp_err)
63
+ }
64
+
23
65
  #[wasm_bindgen(js_name=getDataContract)]
24
66
  pub fn get_data_contract(&self) -> DataContractWasm {
25
67
  self.0.data_contract.clone().into()
@@ -34,4 +76,63 @@ impl DataContractCreateTransitionWasm {
34
76
  pub fn get_entropy(&self) -> Buffer {
35
77
  Buffer::from_bytes(&self.0.entropy)
36
78
  }
79
+
80
+ #[wasm_bindgen(js_name=getOwnerId)]
81
+ pub fn get_owner_id(&self) -> IdentifierWrapper {
82
+ self.0.get_owner_id().clone().into()
83
+ }
84
+
85
+ #[wasm_bindgen(js_name=getType)]
86
+ pub fn get_type(&self) -> u32 {
87
+ self.0.get_type() as u32
88
+ }
89
+
90
+ #[wasm_bindgen(js_name=toJSON)]
91
+ pub fn to_json(&self, skip_signature: Option<bool>) -> Result<JsValue, JsValue> {
92
+ let serializer = serde_wasm_bindgen::Serializer::json_compatible();
93
+ Ok(self
94
+ .0
95
+ .to_json(skip_signature.unwrap_or(false))
96
+ .map_err(from_dpp_err)?
97
+ .serialize(&serializer)
98
+ .expect("JSON is a valid object"))
99
+ }
100
+
101
+ #[wasm_bindgen(js_name=toBuffer)]
102
+ pub fn to_buffer(&self, skip_signature: Option<bool>) -> Result<Buffer, JsValue> {
103
+ let bytes = self
104
+ .0
105
+ .to_buffer(skip_signature.unwrap_or(false))
106
+ .map_err(from_dpp_err)?;
107
+ Ok(Buffer::from_bytes(&bytes))
108
+ }
109
+
110
+ #[wasm_bindgen(js_name=getModifiedDataIds)]
111
+ pub fn get_modified_data_ids(&self) -> Vec<JsValue> {
112
+ self.0
113
+ .get_modified_data_ids()
114
+ .into_iter()
115
+ .map(|identifier| Into::<IdentifierWrapper>::into(identifier.clone()).into())
116
+ .collect()
117
+ }
118
+
119
+ #[wasm_bindgen(js_name=isDataContractStateTransition)]
120
+ pub fn is_data_contract_state_transition(&self) -> bool {
121
+ self.0.is_data_contract_state_transition()
122
+ }
123
+
124
+ #[wasm_bindgen(js_name=isDocumentStateTransition)]
125
+ pub fn is_document_state_transition(&self) -> bool {
126
+ self.0.is_document_state_transition()
127
+ }
128
+
129
+ #[wasm_bindgen(js_name=isIdentityStateTransition)]
130
+ pub fn is_identity_state_transition(&self) -> bool {
131
+ self.0.is_identity_state_transition()
132
+ }
133
+
134
+ #[wasm_bindgen(js_name=setExecutionContext)]
135
+ pub fn set_execution_context(&mut self, context: &StateTransitionExecutionContextWasm) {
136
+ self.0.set_execution_context(context.into())
137
+ }
37
138
  }
@@ -0,0 +1,24 @@
1
+ use dpp::data_contract::state_transition::data_contract_create_transition::validation::state::validate_data_contract_create_transition_state::validate_data_contract_create_transition_state as dpp_validate_data_contract_create_transition_state;
2
+ use wasm_bindgen::prelude::*;
3
+
4
+ use crate::{
5
+ errors::from_dpp_err,
6
+ state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
7
+ validation_result::ValidationResultWasm,
8
+ DataContractCreateTransitionWasm,
9
+ };
10
+
11
+ #[wasm_bindgen(js_name=validateDataContractCreateTransitionState)]
12
+ pub async fn validate_data_contract_create_transition_state(
13
+ state_repository: ExternalStateRepositoryLike,
14
+ state_transition: DataContractCreateTransitionWasm,
15
+ ) -> Result<ValidationResultWasm, JsValue> {
16
+ let wrapped_state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
17
+ dpp_validate_data_contract_create_transition_state(
18
+ &wrapped_state_repository,
19
+ &state_transition.into(),
20
+ )
21
+ .await
22
+ .map(Into::into)
23
+ .map_err(from_dpp_err)
24
+ }
@@ -1,4 +1,4 @@
1
- use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
1
+ use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
2
2
  use dpp::prelude::DocumentTransition;
3
3
  use thiserror::Error;
4
4
 
@@ -1,4 +1,4 @@
1
- use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
1
+ use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
2
2
  use dpp::prelude::DocumentTransition;
3
3
  use thiserror::Error;
4
4
 
@@ -1,4 +1,4 @@
1
- use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
1
+ use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
2
2
  use dpp::prelude::DocumentTransition;
3
3
  use thiserror::Error;
4
4
 
@@ -1,5 +1,5 @@
1
1
  use crate::buffer::Buffer;
2
- use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
2
+ use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
3
3
 
4
4
  use dpp::identifier::Identifier;
5
5
  use dpp::prelude::DocumentTransition;
@@ -1,5 +1,5 @@
1
1
  use crate::buffer::Buffer;
2
- use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
2
+ use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
3
3
 
4
4
  use dpp::identifier::Identifier;
5
5
  use dpp::prelude::DocumentTransition;
@@ -1,5 +1,5 @@
1
1
  use crate::buffer::Buffer;
2
- use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
2
+ use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
3
3
 
4
4
  use dpp::identifier::Identifier;
5
5
  use dpp::prelude::DocumentTransition;
package/src/lib.rs CHANGED
@@ -1,5 +1,3 @@
1
- extern crate web_sys;
2
-
3
1
  pub use dash_platform_protocol::*;
4
2
  pub use data_contract::*;
5
3
  pub use data_contract_factory::*;
@@ -9,6 +7,7 @@ pub use identity::*;
9
7
  pub use identity_facade::*;
10
8
  pub use identity_public_key::*;
11
9
  pub use metadata::*;
10
+ pub use state_transition::*;
12
11
 
13
12
  mod dash_platform_protocol;
14
13
  mod data_contract;
@@ -20,6 +19,8 @@ mod identity;
20
19
  mod identity_facade;
21
20
  mod identity_public_key;
22
21
  mod metadata;
22
+ mod state_repository;
23
+ mod state_transition;
23
24
 
24
25
  mod utils;
25
26
 
@@ -0,0 +1,229 @@
1
+ //! Bindings for state repository -like objects coming from JS.
2
+
3
+ use std::{convert::Infallible, pin::Pin, sync::Mutex};
4
+
5
+ use async_trait::async_trait;
6
+ use dpp::{
7
+ dashcore::InstantLock,
8
+ data_contract::DataContract,
9
+ document::Document,
10
+ prelude::{Identifier, Identity},
11
+ state_repository::StateRepositoryLike,
12
+ state_transition::state_transition_execution_context::StateTransitionExecutionContext,
13
+ };
14
+ use wasm_bindgen::prelude::*;
15
+
16
+ use crate::{identifier::IdentifierWrapper, DataContractWasm, StateTransitionExecutionContextWasm};
17
+
18
+ #[wasm_bindgen]
19
+ extern "C" {
20
+ pub type ExternalStateRepositoryLike;
21
+
22
+ #[wasm_bindgen(structural, method, js_name=fetchDataContract)]
23
+ pub fn fetch_data_contract(
24
+ this: &ExternalStateRepositoryLike,
25
+ data_contract_id: IdentifierWrapper,
26
+ execution_context: StateTransitionExecutionContextWasm,
27
+ ) -> Option<DataContractWasm>;
28
+
29
+ #[wasm_bindgen(structural, method, js_name=storeDataContract)]
30
+ pub fn store_data_contract(
31
+ this: &ExternalStateRepositoryLike,
32
+ data_contract: DataContractWasm,
33
+ execution_context: StateTransitionExecutionContextWasm,
34
+ ) -> JsValue;
35
+
36
+ // TODO add missing declarations
37
+ }
38
+
39
+ /// Wraps external duck-typed thing into pinned box with mutex to ensure it'll stay at the same
40
+ /// place in memory and will have synchronized access.
41
+ pub(crate) struct ExternalStateRepositoryLikeWrapper(Pin<Box<Mutex<ExternalStateRepositoryLike>>>); // bruh
42
+
43
+ unsafe impl Send for ExternalStateRepositoryLikeWrapper {}
44
+ unsafe impl Sync for ExternalStateRepositoryLikeWrapper {}
45
+
46
+ impl ExternalStateRepositoryLikeWrapper {
47
+ pub(crate) fn new(state_repository: ExternalStateRepositoryLike) -> Self {
48
+ ExternalStateRepositoryLikeWrapper(Box::pin(Mutex::new(state_repository)))
49
+ }
50
+ }
51
+
52
+ #[async_trait]
53
+ impl StateRepositoryLike for ExternalStateRepositoryLikeWrapper {
54
+ type ConversionError = Infallible;
55
+ type FetchDataContract = DataContractWasm;
56
+
57
+ async fn fetch_data_contract(
58
+ &self,
59
+ data_contract_id: &Identifier,
60
+ execution_context: &StateTransitionExecutionContext,
61
+ ) -> anyhow::Result<Option<Self::FetchDataContract>> {
62
+ Ok(self
63
+ .0
64
+ .lock()
65
+ .expect("unexpected concurrency issue!")
66
+ .fetch_data_contract(
67
+ data_contract_id.clone().into(),
68
+ execution_context.clone().into(),
69
+ )
70
+ .map(Into::into))
71
+ }
72
+
73
+ async fn store_data_contract(
74
+ &self,
75
+ data_contract: DataContract,
76
+ execution_context: &StateTransitionExecutionContext,
77
+ ) -> anyhow::Result<()> {
78
+ self.0
79
+ .lock()
80
+ .expect("unexpected concurrency issue!")
81
+ .store_data_contract(data_contract.into(), execution_context.clone().into());
82
+ Ok(())
83
+ }
84
+
85
+ async fn fetch_documents<T>(
86
+ &self,
87
+ _contract_id: &Identifier,
88
+ _data_contract_type: &str,
89
+ _where_query: serde_json::Value,
90
+ _execution_context: &StateTransitionExecutionContext,
91
+ ) -> anyhow::Result<Vec<T>>
92
+ where
93
+ T: for<'de> serde::de::Deserialize<'de> + 'static,
94
+ {
95
+ todo!()
96
+ }
97
+
98
+ async fn create_document(
99
+ &self,
100
+ _document: &Document,
101
+ _execution_context: &StateTransitionExecutionContext,
102
+ ) -> anyhow::Result<()> {
103
+ todo!()
104
+ }
105
+
106
+ async fn update_document(
107
+ &self,
108
+ _document: &Document,
109
+ _execution_context: &StateTransitionExecutionContext,
110
+ ) -> anyhow::Result<()> {
111
+ todo!()
112
+ }
113
+
114
+ async fn remove_document(
115
+ &self,
116
+ _data_contract: &DataContract,
117
+ _data_contract_type: &str,
118
+ _document_id: &Identifier,
119
+ _execution_context: &StateTransitionExecutionContext,
120
+ ) -> anyhow::Result<()> {
121
+ todo!()
122
+ }
123
+
124
+ async fn fetch_transaction<T>(
125
+ &self,
126
+ _id: &str,
127
+ _execution_context: &StateTransitionExecutionContext,
128
+ ) -> anyhow::Result<Option<T>>
129
+ where
130
+ T: for<'de> serde::de::Deserialize<'de> + 'static,
131
+ {
132
+ todo!()
133
+ }
134
+
135
+ async fn fetch_identity<T>(
136
+ &self,
137
+ _id: &Identifier,
138
+ _execution_context: &StateTransitionExecutionContext,
139
+ ) -> anyhow::Result<Option<T>>
140
+ where
141
+ T: for<'de> serde::de::Deserialize<'de> + 'static,
142
+ {
143
+ todo!()
144
+ }
145
+
146
+ async fn store_identity_public_key_hashes(
147
+ &self,
148
+ _identity_id: &Identifier,
149
+ _public_key_hashes: Vec<Vec<u8>>,
150
+ _execution_context: &StateTransitionExecutionContext,
151
+ ) -> anyhow::Result<()> {
152
+ todo!()
153
+ }
154
+
155
+ async fn fetch_identity_by_public_key_hashes<T>(
156
+ &self,
157
+ _public_key_hashed: Vec<Vec<u8>>,
158
+ ) -> anyhow::Result<Vec<T>>
159
+ where
160
+ T: for<'de> serde::de::Deserialize<'de> + 'static,
161
+ {
162
+ todo!()
163
+ }
164
+
165
+ async fn fetch_latest_platform_block_header<T>(&self) -> anyhow::Result<T>
166
+ where
167
+ T: for<'de> serde::de::Deserialize<'de> + 'static,
168
+ {
169
+ todo!()
170
+ }
171
+
172
+ async fn verify_instant_lock(
173
+ &self,
174
+ _instant_lock: &InstantLock,
175
+ _execution_context: &StateTransitionExecutionContext,
176
+ ) -> anyhow::Result<bool> {
177
+ todo!()
178
+ }
179
+
180
+ async fn is_asset_lock_transaction_out_point_already_used(
181
+ &self,
182
+ _out_point_buffer: &[u8],
183
+ _execution_context: &StateTransitionExecutionContext,
184
+ ) -> anyhow::Result<bool> {
185
+ todo!()
186
+ }
187
+
188
+ async fn mark_asset_lock_transaction_out_point_as_used(
189
+ &self,
190
+ _out_point_buffer: &[u8],
191
+ ) -> anyhow::Result<()> {
192
+ todo!()
193
+ }
194
+
195
+ async fn fetch_sml_store<T>(&self) -> anyhow::Result<T>
196
+ where
197
+ T: for<'de> serde::de::Deserialize<'de> + 'static,
198
+ {
199
+ todo!()
200
+ }
201
+
202
+ async fn create_identity(
203
+ &self,
204
+ _identity: &Identity,
205
+ _execution_context: &StateTransitionExecutionContext,
206
+ ) -> anyhow::Result<()> {
207
+ todo!()
208
+ }
209
+
210
+ async fn update_identity(
211
+ &self,
212
+ _identity: &Identity,
213
+ _execution_context: &StateTransitionExecutionContext,
214
+ ) -> anyhow::Result<()> {
215
+ todo!()
216
+ }
217
+
218
+ async fn fetch_latest_withdrawal_transaction_index(&self) -> anyhow::Result<u64> {
219
+ todo!()
220
+ }
221
+
222
+ async fn enqueue_withdrawal_transaction(
223
+ &self,
224
+ _index: u64,
225
+ _transaction_bytes: Vec<u8>,
226
+ ) -> anyhow::Result<()> {
227
+ todo!()
228
+ }
229
+ }
@@ -0,0 +1,41 @@
1
+ use dpp::state_transition::state_transition_execution_context::StateTransitionExecutionContext;
2
+ use wasm_bindgen::prelude::*;
3
+
4
+ #[wasm_bindgen(js_name=StateTransitionExecutionContext)]
5
+ pub struct StateTransitionExecutionContextWasm(StateTransitionExecutionContext);
6
+
7
+ impl From<StateTransitionExecutionContext> for StateTransitionExecutionContextWasm {
8
+ fn from(rs: StateTransitionExecutionContext) -> Self {
9
+ StateTransitionExecutionContextWasm(rs)
10
+ }
11
+ }
12
+
13
+ impl From<StateTransitionExecutionContextWasm> for StateTransitionExecutionContext {
14
+ fn from(wa: StateTransitionExecutionContextWasm) -> Self {
15
+ wa.0
16
+ }
17
+ }
18
+
19
+ impl<'a> From<&'a StateTransitionExecutionContextWasm> for StateTransitionExecutionContext {
20
+ fn from(wa: &StateTransitionExecutionContextWasm) -> Self {
21
+ wa.0.clone()
22
+ }
23
+ }
24
+
25
+ #[wasm_bindgen(js_class=StateTransitionExecutionContext)]
26
+ impl StateTransitionExecutionContextWasm {
27
+ #[wasm_bindgen(constructor)]
28
+ pub fn new() -> StateTransitionExecutionContextWasm {
29
+ StateTransitionExecutionContext::default().into()
30
+ }
31
+
32
+ #[wasm_bindgen(js_name=enableDryRun)]
33
+ pub fn enable_dry_run(&self) {
34
+ self.0.enable_dry_run();
35
+ }
36
+
37
+ #[wasm_bindgen(js_name=disableDryRun)]
38
+ pub fn disable_dry_run(&self) {
39
+ self.0.disable_dry_run();
40
+ }
41
+ }
@@ -1,23 +1,24 @@
1
1
  const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
2
2
  const stateTransitionTypes = require('@dashevo/dpp/lib/stateTransition/stateTransitionTypes');
3
3
 
4
- const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
5
4
  const protocolVersion = require('@dashevo/dpp/lib/version/protocolVersion');
6
- const DataContractCreateTransition = require('@dashevo/dpp/lib/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition');
7
- const hash = require('@dashevo/dpp/lib/util/hash');
8
- const serializer = require('@dashevo/dpp/lib/util/serializer');
5
+
6
+ const { default: loadWasmDpp } = require('../../../../../dist');
9
7
 
10
8
  describe('DataContractCreateTransition', () => {
11
9
  let stateTransition;
12
10
  let dataContract;
13
- let hashMock;
14
- let encodeMock;
11
+ let DataContractCreateTransition;
12
+ let Identifier;
15
13
 
16
- beforeEach(function beforeEach() {
17
- dataContract = getDataContractFixture();
14
+ before(async () => {
15
+ ({
16
+ DataContractCreateTransition, Identifier,
17
+ } = await loadWasmDpp());
18
+ });
18
19
 
19
- encodeMock = this.sinonSandbox.stub(serializer, 'encode');
20
- hashMock = this.sinonSandbox.stub(hash, 'hash');
20
+ beforeEach(() => {
21
+ dataContract = getDataContractFixture();
21
22
 
22
23
  stateTransition = new DataContractCreateTransition({
23
24
  protocolVersion: protocolVersion.latestVersion,
@@ -26,11 +27,6 @@ describe('DataContractCreateTransition', () => {
26
27
  });
27
28
  });
28
29
 
29
- afterEach(() => {
30
- encodeMock.restore();
31
- hashMock.restore();
32
- });
33
-
34
30
  describe('#getProtocolVersion', () => {
35
31
  it('should return the current protocol version', () => {
36
32
  const result = stateTransition.getProtocolVersion();
@@ -57,12 +53,10 @@ describe('DataContractCreateTransition', () => {
57
53
 
58
54
  describe('#toJSON', () => {
59
55
  it('should return State Transition as plain JS object', () => {
60
- expect(stateTransition.toJSON()).to.deep.equal({
56
+ expect(stateTransition.toJSON(true)).to.deep.equal({
61
57
  protocolVersion: protocolVersion.latestVersion,
62
58
  type: stateTransitionTypes.DATA_CONTRACT_CREATE,
63
59
  dataContract: dataContract.toJSON(),
64
- signaturePublicKeyId: undefined,
65
- signature: undefined,
66
60
  entropy: dataContract.getEntropy().toString('base64'),
67
61
  });
68
62
  });
@@ -70,61 +64,20 @@ describe('DataContractCreateTransition', () => {
70
64
 
71
65
  describe('#toBuffer', () => {
72
66
  it('should return serialized State Transition', () => {
73
- const serializedStateTransition = Buffer.from('123');
74
-
75
- encodeMock.returns(serializedStateTransition);
76
-
77
67
  const protocolVersionUInt32 = Buffer.alloc(4);
78
- protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
68
+ protocolVersionUInt32.writeUInt32LE(stateTransition.getProtocolVersion(), 0);
79
69
 
80
70
  const result = stateTransition.toBuffer();
81
-
82
- expect(result).to.deep.equal(
83
- Buffer.concat([protocolVersionUInt32, serializedStateTransition]),
84
- );
85
-
86
- const dataToEncode = stateTransition.toObject();
87
- delete dataToEncode.protocolVersion;
88
-
89
- expect(encodeMock.getCall(0).args).to.have.deep.members([
90
- dataToEncode,
91
- ]);
92
- });
93
- });
94
-
95
- describe('#hash', () => {
96
- it('should return State Transition hash as hex', () => {
97
- const serializedDocument = Buffer.from('123');
98
- const hashedDocument = '456';
99
-
100
- encodeMock.returns(serializedDocument);
101
- hashMock.returns(hashedDocument);
102
-
103
- const result = stateTransition.hash();
104
-
105
- expect(result).to.equal(hashedDocument);
106
-
107
- const dataToEncode = stateTransition.toObject();
108
- delete dataToEncode.protocolVersion;
109
-
110
- expect(encodeMock.getCall(0).args).to.have.deep.members([
111
- dataToEncode,
112
- ]);
113
-
114
- const protocolVersionUInt32 = Buffer.alloc(4);
115
- protocolVersionUInt32.writeUInt32LE(stateTransition.protocolVersion, 0);
116
-
117
- expect(hashMock).to.have.been.calledOnceWith(
118
- Buffer.concat([protocolVersionUInt32, serializedDocument]),
119
- );
71
+ expect(result.compare(protocolVersionUInt32, 0, 4, 0, 4)).equals(0);
120
72
  });
121
73
  });
122
74
 
123
75
  describe('#getOwnerId', () => {
124
76
  it('should return owner id', async () => {
125
77
  const result = stateTransition.getOwnerId();
78
+ const reference = stateTransition.getDataContract().getOwnerId();
126
79
 
127
- expect(result).to.equal(stateTransition.getDataContract().getOwnerId());
80
+ expect(result.toBuffer()).to.deep.equal(reference.toBuffer());
128
81
  });
129
82
  });
130
83
 
@@ -136,7 +89,7 @@ describe('DataContractCreateTransition', () => {
136
89
  const contractId = result[0];
137
90
 
138
91
  expect(contractId).to.be.an.instanceOf(Identifier);
139
- expect(contractId).to.be.deep.equal(dataContract.getId());
92
+ expect(contractId.toBuffer()).to.be.deep.equal(dataContract.getId().toBuffer());
140
93
  });
141
94
  });
142
95