Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6403eec
test(wasm-sdk): start state transition test suite
thephez Aug 21, 2025
a99458f
test(wasm-sdk): refactor data contract validation and add create+upda…
thephez Aug 25, 2025
91d9ccd
test(wasm-sdk): enhance UI navigation tests with comprehensive transi…
thephez Aug 25, 2025
3b805b4
test(wasm-sdk): enable error handling tests and fix invalid private k…
thephez Aug 25, 2025
be8e3cb
test(wasm-sdk): implement document state transition testing with dyna…
thephez Aug 25, 2025
48633bd
test(wasm-sdk): implement comprehensive document lifecycle testing wi…
thephez Aug 25, 2025
829b6ee
test(wasm-sdk): add placeholder tests and test data for document tran…
thephez Aug 25, 2025
77843fc
test(wasm-sdk): enable document replace test with persistent testnet …
thephez Aug 25, 2025
f4701a9
chore: add unstage change
thephez Aug 26, 2025
49ea038
test(wasm-sdk): add identity credit transfer state transition test
thephez Aug 26, 2025
03312ff
test(wasm-sdk): add identity credit withdrawal state transition test
thephez Aug 26, 2025
5592041
test(wasm-sdk): add environment variable support for sensitive test data
thephez Aug 26, 2025
f8b990b
test(wasm-sdk): complete environment variable configuration for all s…
thephez Aug 26, 2025
a248bdb
fix: run test serially to avoid unknown concurrency issue
thephez Aug 26, 2025
2b447cb
feat(wasm-sdk): add comprehensive token state transition tests
thephez Aug 26, 2025
1e271f4
test(wasm-sdk): add token freeze and unfreeze state transition tests
thephez Aug 26, 2025
4cd254e
test(wasm-sdk): add token destroy frozen state transition test and fi…
thephez Aug 26, 2025
cc102cb
chore: mint enough tokens to cover transfer and burn
thephez Aug 26, 2025
968d93a
test(wasm-sdk): add token claim and set price state transition tests
thephez Aug 27, 2025
dbb147c
test(wasm-sdk): add identity credit withdrawal state transition test
thephez Aug 27, 2025
83aafd0
test(wasm-sdk): add token direct purchase state transition test
thephez Aug 27, 2025
1553527
test(wasm-sdk): add token config update state transition test
thephez Aug 27, 2025
c3ee062
test: configure parallel and sequential test execution for playwright
thephez Aug 27, 2025
2f742b7
chore: trim trailing whitespace
thephez Aug 27, 2025
cccc462
ci: disable state transition testing in CI for now
thephez Aug 27, 2025
d4fdf1a
fix(wasm-sdk): fix getIdentitiesContractKeys test data and validation
thephez Aug 27, 2025
e3353ce
fix(wasm-sdk): remove incorrect amount parameter from tokenDestroyFro…
thephez Aug 28, 2025
c7b9e9d
fix(wasm-sdk): improve fillDocumentField value type handling
thephez Aug 28, 2025
8f1a149
chore: add example .env file
thephez Aug 28, 2025
24f891c
fix: handle bigint properly for document transitions
thephez Aug 28, 2025
5e8c0a4
test(wasm-sdk): update document marketplace test configurations with …
thephez Aug 28, 2025
f804602
fix(wasm-sdk): improve document purchase and price update transitions
thephez Aug 28, 2025
a2bfa8e
test(wasm-sdk): enable document transfer test with correct ownership …
thephez Aug 28, 2025
bc5be83
fix(wasm-sdk): increment document revision for transfer transitions
thephez Aug 28, 2025
e53a303
fix(wasm-sdk): improve document revision handling with error checking
thephez Sep 1, 2025
49c94dd
chore: update example .env
thephez Sep 1, 2025
435c89a
test: replace hard-coded private key with invalid base58 placeholder
thephez Sep 2, 2025
a02db31
test: remove sensitive parameter data from console logs
thephez Sep 2, 2025
ac0ddac
test(wasm-sdk): remove hard-coded identity ID in state transitions test
thephez Sep 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/wasm-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
playwright-report/
test-results/
test/test-report.html

# Environment variables with sensitive test data
test/ui-automation/.env
2 changes: 1 addition & 1 deletion packages/wasm-sdk/api-definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@
"required": true
},
{
"name": "identityId",
"name": "frozenIdentityId",
"type": "text",
"label": "Identity ID whose frozen tokens to destroy",
"required": true
Expand Down
6 changes: 3 additions & 3 deletions packages/wasm-sdk/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,7 @@ <h2>Results</h2>
result = await sdk.tokenDestroyFrozen(
values.contractId,
Number(values.tokenPosition),
values.identityId, // identity whose frozen tokens to destroy
values.frozenIdentityId, // identity whose frozen tokens to destroy
identityId, // destroyer ID
privateKey,
values.publicNote || null
Expand Down Expand Up @@ -3343,7 +3343,7 @@ <h2>Results</h2>
values.documentType,
values.documentId,
identityId,
values.price || 0, // price in credits, 0 to remove price
BigInt(values.price || 0), // price in credits, 0 to remove price
privateKey,
0 // key_id - using 0 as default
);
Expand Down Expand Up @@ -3477,7 +3477,7 @@ <h2>Results</h2>
values.documentType,
values.documentId,
identityId,
values.price,
BigInt(values.price),
privateKey,
0 // key_id - using 0 as default
);
Expand Down
104 changes: 67 additions & 37 deletions packages/wasm-sdk/src/state_transitions/documents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ impl WasmSdk {

Ok(result_obj.into())
}

/// Get the next revision for a document, handling errors for missing revisions and overflow
fn get_next_revision(document: &dash_sdk::platform::Document) -> Result<u64, JsValue> {
let current_revision = document.revision()
.ok_or_else(|| JsValue::from_str("Document revision is missing"))?;

current_revision.checked_add(1)
.ok_or_else(|| JsValue::from_str("Document revision overflow"))
}
}

#[wasm_bindgen]
Expand Down Expand Up @@ -835,7 +844,8 @@ impl WasmSdk {
.map_err(|e| JsValue::from_str(&format!("Failed to fetch document: {}", e)))?
.ok_or_else(|| JsValue::from_str("Document not found"))?;

let current_revision = existing_doc.revision().unwrap_or(0);
let current_revision = existing_doc.revision()
.ok_or_else(|| JsValue::from_str("Document revision is missing"))?;

// Fetch the identity to get the correct key
let identity = dash_sdk::platform::Identity::fetch(&sdk, owner_identifier)
Expand Down Expand Up @@ -965,6 +975,26 @@ impl WasmSdk {
.map_err(|e| JsValue::from_str(&format!("Failed to fetch document: {}", e)))?
.ok_or_else(|| JsValue::from_str("Document not found"))?;

// Get the current revision and increment it
let next_revision = Self::get_next_revision(&document)?;

// Create a modified document with incremented revision for the transfer transition
let transfer_document = Document::V0(DocumentV0 {
id: document.id(),
owner_id: document.owner_id(),
properties: document.properties().clone(),
revision: Some(next_revision),
created_at: document.created_at(),
updated_at: document.updated_at(),
transferred_at: document.transferred_at(),
created_at_block_height: document.created_at_block_height(),
updated_at_block_height: document.updated_at_block_height(),
transferred_at_block_height: document.transferred_at_block_height(),
created_at_core_block_height: document.created_at_core_block_height(),
updated_at_core_block_height: document.updated_at_core_block_height(),
transferred_at_core_block_height: document.transferred_at_core_block_height(),
});

// Fetch the identity to get the correct key
let identity = dash_sdk::platform::Identity::fetch(&sdk, owner_identifier)
.await
Expand All @@ -983,7 +1013,7 @@ impl WasmSdk {

// Create a transfer transition
let transition = BatchTransition::new_document_transfer_transition_from_document(
document,
transfer_document,
document_type_ref,
recipient_identifier,
matching_key,
Expand Down Expand Up @@ -1089,6 +1119,26 @@ impl WasmSdk {
)));
}

// Get the current revision and increment it
let next_revision = Self::get_next_revision(&document)?;

// Create a modified document with incremented revision for the purchase transition
let purchase_document = Document::V0(DocumentV0 {
id: document.id(),
owner_id: document.owner_id(),
properties: document.properties().clone(),
revision: Some(next_revision),
created_at: document.created_at(),
updated_at: document.updated_at(),
transferred_at: document.transferred_at(),
created_at_block_height: document.created_at_block_height(),
updated_at_block_height: document.updated_at_block_height(),
transferred_at_block_height: document.transferred_at_block_height(),
created_at_core_block_height: document.created_at_core_block_height(),
updated_at_core_block_height: document.updated_at_core_block_height(),
transferred_at_core_block_height: document.transferred_at_core_block_height(),
});

// Fetch buyer identity
let buyer_identity = dash_sdk::platform::Identity::fetch(&sdk, buyer_identifier)
.await
Expand All @@ -1107,7 +1157,7 @@ impl WasmSdk {

// Create document purchase transition
let transition = BatchTransition::new_document_purchase_transition_from_document(
document.into(),
purchase_document,
document_type_ref,
buyer_identifier,
price as Credits,
Expand Down Expand Up @@ -1226,25 +1276,15 @@ impl WasmSdk {
return Err(JsValue::from_str("Only the document owner can set its price"));
}

// Get existing document properties and convert to mutable map
let mut properties = existing_doc.properties().clone();

// Update the price in the document properties
let price_value = if price > 0 {
PlatformValue::U64(price)
} else {
PlatformValue::Null
};
// Get the current revision and increment it
let next_revision = Self::get_next_revision(&existing_doc)?;

properties.insert("$price".to_string(), price_value);

// Create updated document with new properties
let new_revision = existing_doc.revision().unwrap_or(0) + 1;
let updated_doc = Document::V0(DocumentV0 {
id: doc_id,
owner_id: owner_identifier,
properties,
revision: Some(new_revision),
// Create a modified document with incremented revision for the price update transition
let price_update_document = Document::V0(DocumentV0 {
id: existing_doc.id(),
owner_id: existing_doc.owner_id(),
properties: existing_doc.properties().clone(),
revision: Some(next_revision),
created_at: existing_doc.created_at(),
updated_at: existing_doc.updated_at(),
transferred_at: existing_doc.transferred_at(),
Expand Down Expand Up @@ -1272,30 +1312,20 @@ impl WasmSdk {
.await
.map_err(|e| JsValue::from_str(&format!("Failed to fetch nonce: {}", e)))?;

// Generate entropy for the state transition
let entropy_bytes = {
let mut entropy = [0u8; 32];
if let Some(window) = web_sys::window() {
if let Ok(crypto) = window.crypto() {
let _ = crypto.get_random_values_with_u8_array(&mut entropy);
}
}
entropy
};

// Create the price update transition
let transition = BatchTransition::new_document_replacement_transition_from_document(
updated_doc,
// Create the price update transition using the dedicated method
let transition = BatchTransition::new_document_update_price_transition_from_document(
price_update_document,
document_type_ref,
matching_key,
price,
&matching_key,
identity_contract_nonce,
UserFeeIncrease::default(),
None, // token_payment_info
&signer,
sdk.version(),
None, // options
)
.map_err(|e| JsValue::from_str(&format!("Failed to create transition: {}", e)))?;
.map_err(|e| JsValue::from_str(&format!("Failed to create price update transition: {}", e)))?;

// The transition is already signed, convert to StateTransition
let state_transition: StateTransition = transition.into();
Expand Down
12 changes: 12 additions & 0 deletions packages/wasm-sdk/test/ui-automation/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Test Credentials for WASM SDK UI Tests
# Copy this file to .env and fill with real values

# Private keys for state transitions (DON'T STORE in production)
TEST_PRIVATE_KEY_IDENTITY_1=YOUR_IDENTITY_PRIVATE_KEY_HERE
TEST_PRIVATE_KEY_TRANSFER=YOUR_TRANSFER_PRIVATE_KEY_HERE
TEST_PRIVATE_KEY_CONTRACT=YOUR_CONTRACT_PRIVATE_KEY_HERE
# Secondary private key (used by some document/token transitions)
TEST_PRIVATE_KEY_SECONDARY=YOUR_TEST_PRIVATE_KEY_SECONDARY

# Seed phrases for identity creation (not implemented yet)
TEST_SEED_PHRASE_1="your seed phrase here"
Loading
Loading