feat(wasm-sdk): add token-paid document support#3599
feat(wasm-sdk): add token-paid document support#3599PastaPastaPasta wants to merge 1 commit intodashpay:v3.1-devfrom
Conversation
📝 WalkthroughWalkthroughThis PR adds support for optional token-payment metadata ( ChangesToken Payment Info Support for Document Transitions
Sequence DiagramsequenceDiagram
actor User
participant JSClient as JavaScript<br/>Client
participant WasmSDK as Wasm SDK<br/>document_create()
participant Parser as Parser:<br/>try_from_options_optional<br/>_token_payment_info()
participant DashSDK as dash_sdk<br/>TokenPaymentInfo
participant Platform as Dash Platform
User->>JSClient: documentCreate(document, {<br/>tokenPaymentInfo: {<br/>contractId, position,<br/>minimumTokenCost,<br/>maximumTokenCost,<br/>gasFeesPaidBy<br/>}})
JSClient->>WasmSDK: call with options
WasmSDK->>Parser: extract & parse<br/>tokenPaymentInfo
Parser->>Parser: validate gasFeesPaidBy
Parser->>DashSDK: convert to TokenPaymentInfo
DashSDK-->>WasmSDK: Some(TokenPaymentInfo)
WasmSDK->>Platform: put_to_platform with<br/>token_payment_info
Platform-->>WasmSDK: state transition result
WasmSDK-->>JSClient: document created
JSClient-->>User: success
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review GateCommit:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/wasm-sdk/tests/functional/transitions/documents.spec.ts`:
- Around line 28-32: Replace the fixed sleep-based waitForPlatform helper with a
polling-based wait that repeatedly checks the desired condition until it becomes
true or a timeout is reached; specifically, replace uses of waitForPlatform() in
the purchase/ownership checks with a polling loop that calls
getSingleTokenBalance(identityId, tokenId) (or another deterministic query) at
intervals and resolves when the balance/ownership matches the expected value,
failing after a configurable timeout to avoid flakiness. Locate the helper
waitForPlatform and every test call that assumes immediate platform sync (e.g.,
where ownership is read after broadcast) and swap them to invoke the new polling
helper that uses getSingleTokenBalance to assert the final state. Ensure polling
interval and timeout are configurable and provide a clear error message on
timeout.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b9ee1b67-f584-41ab-a30e-6fd44b7368c8
📒 Files selected for processing (3)
packages/js-evo-sdk/tests/unit/facades/documents.spec.tspackages/wasm-sdk/src/state_transitions/document.rspackages/wasm-sdk/tests/functional/transitions/documents.spec.ts
| const waitForPlatform = async (ms = 2000) => new Promise((resolve) => { setTimeout(resolve, ms); }); | ||
| const getSingleTokenBalance = async (identityId: string, tokenId: string) => { | ||
| const balances = await client.getIdentityTokenBalances(identityId, [tokenId]); | ||
| return balances.get(tokenId); | ||
| }; |
There was a problem hiding this comment.
Replace fixed sleeps with condition polling to avoid flaky functional tests
Using a constant sleep for platform sync is brittle, and the purchase path reads ownership immediately after broadcast. On slower runs, this can intermittently fail despite correct behavior.
Suggested direction
-const waitForPlatform = async (ms = 2000) => new Promise((resolve) => { setTimeout(resolve, ms); });
+const waitForPlatform = async (
+ condition: () => Promise<boolean>,
+ timeoutMs = 20_000,
+ intervalMs = 250,
+) => {
+ const startedAt = Date.now();
+ while (Date.now() - startedAt < timeoutMs) {
+ if (await condition()) return;
+ await new Promise((resolve) => { setTimeout(resolve, intervalMs); });
+ }
+ throw new Error('Timed out waiting for platform state');
+};-const purchasedDocument = await client.getDocument(
- tokenPaidContractId,
- 'tokenPaidListing',
- tokenPaidDocumentId,
-);
+await waitForPlatform(async () => {
+ try {
+ const doc = await client.getDocument(
+ tokenPaidContractId,
+ 'tokenPaidListing',
+ tokenPaidDocumentId,
+ );
+ return doc.ownerId.toString() === testData.identityId3;
+ } catch {
+ return false;
+ }
+});
+
+const purchasedDocument = await client.getDocument(
+ tokenPaidContractId,
+ 'tokenPaidListing',
+ tokenPaidDocumentId,
+);Also applies to: 531-535
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/wasm-sdk/tests/functional/transitions/documents.spec.ts` around
lines 28 - 32, Replace the fixed sleep-based waitForPlatform helper with a
polling-based wait that repeatedly checks the desired condition until it becomes
true or a timeout is reached; specifically, replace uses of waitForPlatform() in
the purchase/ownership checks with a polling loop that calls
getSingleTokenBalance(identityId, tokenId) (or another deterministic query) at
intervals and resolves when the balance/ownership matches the expected value,
failing after a configurable timeout to avoid flakiness. Locate the helper
waitForPlatform and every test call that assumes immediate platform sync (e.g.,
where ownership is read after broadcast) and swap them to invoke the new polling
helper that uses getSingleTokenBalance to assert the final state. Ensure polling
interval and timeout are configurable and provide a clear error message on
timeout.
Issue being fixed or feature implemented
Add Evo SDK support for passing
tokenPaymentInfothrough document state transitions so document types that define schema-leveltokenCostcan be created, repriced, transferred, deleted, replaced, and purchased from JS.What was done?
tokenPaymentInfoparsing through the wasm document transition bindings instead of always passingNonetokenPaymentInfothrough unchangedmaximumTokenCostHow Has This Been Tested?
cargo check -p wasm-sdkCC=/opt/homebrew/opt/llvm/bin/clang npm exec -- yarn workspace @dashevo/wasm-sdk buildnpm exec -- yarn workspace @dashevo/evo-sdk buildnpm exec -- yarn workspace @dashevo/evo-sdk test:unit --grep "DocumentsFacade"npm exec -- yarn workspace @dashevo/wasm-sdk test:functional --grep "Document State Transitions"Breaking Changes
None.
Checklist:
This pull request was created by Codex.
Summary by CodeRabbit
Release Notes
New Features
Tests