Enforce stock issuance reference integrity - #239
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 41 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…ing' into codex/ocf-stock-issuance-reference-integrity
There was a problem hiding this comment.
Pull request overview
Adds generated CapTable validation for StockIssuance nested reference fields so that referenced IDs must exist at the contract level (on both create and edit), and updates tests/fixtures to create real referenced objects instead of relying on placeholder IDs.
Changes:
- Extended codegen validation syntax to support array references (
field_ids[]:map) and optional references (field_id?:map) and emitted the corresponding DAML checks in create/edit loops. - Enabled reference integrity checks for
StockIssuance.stock_legend_ids,stock_plan_id, andvesting_terms_idviacaptable-config.yaml. - Updated/added DAML Script tests and helpers to create
StockLegendTemplate,StockPlan, andVestingTermsrecords as prerequisites.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Test/daml/OpenCapTable/TestStockRetraction.daml | Updates stock issuance fixture to avoid referencing a non-existent legend ID. |
| Test/daml/OpenCapTable/TestStockIssuanceReferences.daml | Adds reference-integrity tests for missing/valid legend/plan/vesting terms and edit-time rejection. |
| Test/daml/OpenCapTable/TestStockIssuance.daml | Ensures referenced legend/plan/vesting terms are created before exercising optional fields. |
| Test/daml/OpenCapTable/TestStockCancellation.daml | Updates stock issuance fixture to avoid referencing a non-existent legend ID. |
| Test/daml/OpenCapTable/TestStockAcceptance.daml | Updates stock issuance fixture to avoid referencing a non-existent legend ID. |
| Test/daml/OpenCapTable/TestHelpers.daml | Defaults stock legend IDs to empty and adds helper constructors for new prerequisite OCF objects. |
| scripts/codegen/templates/loops/edit-case.daml | Emits generated validation for optional reference fields during edits. |
| scripts/codegen/templates/loops/create-case.daml | Emits generated validation for optional reference fields during creates. |
| scripts/codegen/generate-captable.ts | Parses new [] / ? validation syntax and propagates flags into templates. |
| scripts/codegen/captable-config.yaml | Applies new validations to StockIssuance for legend/plan/vesting-term references. |
| dars/OpenCapTable-v34/0.0.2/OpenCapTable-v34.dar | Updates compiled DAR artifact to include the regenerated CapTable logic. |
| dars/dars.lock | Updates DAR checksum/size metadata to match the new artifact. |
|
Superseded by #251, which consolidates the reference-integrity work into one PR. Before closing this stack PR, I rechecked the live review comments and folded the actionable improvements into #251: StockPlan create-tier ordering, document related-object error messages, stock-class conversion source IDs, warrant conversion validation across all OcfAnyConversionRight variants, WarrantIssuance same-batch vesting-term edits, and immutable DAR backup versioning. |
Summary
Stacked on #238.
This adds contract-level reference validation for
StockIssuancenested references that were previously accepted as arbitrary IDs:stock_legend_ids[]must reference existingStockLegendTemplatecontracts when provided.stock_plan_idmust reference an existingStockPlanwhen present.vesting_terms_idmust reference existingVestingTermswhen present.The generator now supports validation config syntax for array references (
field_ids[]:map_name) and optional references (field_id?:map_name), then applies those toStockIssuanceincaptable-config.yaml.OCF documentation
StockIssuance.stock_plan_id: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/transactions/issuance/StockIssuance.schema.json#L29-L31StockIssuance.vesting_terms_id: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/transactions/issuance/StockIssuance.schema.json#L48-L50StockIssuance.stock_legend_ids: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/transactions/issuance/StockIssuance.schema.json#L65-L70StockIssuancerequired fields includestock_legend_ids: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/transactions/issuance/StockIssuance.schema.json#L89StockLegendTemplateobject schema: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/StockLegendTemplate.schema.json#L3-L5StockPlanobject schema: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/StockPlan.schema.json#L3-L5VestingTermsstable object schema: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/VestingTerms.schema.json#L3-L12VestingTermsv1 object shape: https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/blob/main/schema/objects/versions/VestingTerms.v1.schema.json#L17-L41Tests
TestStockIssuanceReferencescovering missing legend, missing plan, missing vesting terms, valid same-batch references, and edit-time missing-reference rejection.StockIssuanceoptional-fields test populated by creating the referenced plan, vesting terms, and legends.Validation
NODE_PATH=/Users/fairnick/Documents/code/fairmint/open-captable-protocol-daml/node_modules PATH="/Users/fairnick/Documents/code/fairmint/open-captable-protocol-daml/node_modules/.bin:$HOME/.dpm/bin:$PATH" npm run buildTest/:JAVA_HOME=/opt/homebrew/opt/openjdk@17 PATH="/opt/homebrew/opt/openjdk@17/bin:$HOME/.dpm/bin:$PATH" dpm test --show-coverage --color --coverage-ignore-choice 'splice-amulet:.*'Note
Medium Risk
Tightens on-chain cap table validation for a core issuance type; updates that previously slipped through with invalid plan/legend/vesting IDs will now fail at create or edit.
Overview
Stock issuance create and edit paths now reject dangling references: every
stock_legend_idsentry must exist instock_legend_templates, and optionalstock_plan_id/vesting_terms_idmust resolve when set.The CapTable codegen gains config-driven rules for array (
field_ids[]:map) and optional (field_id?:map) lookups; create/edit templates emit the matchingassertMsg/mapA_/case … Somechecks.captable-config.yamlwires those rules toStockIssuance, and the packaged OpenCapTable-v34 DAR / lockfile are refreshed.Tests add
TestStockIssuanceReferences(missing refs, same-batch success, edit failure) and stop using placeholder legend IDs in defaults—fixtures now create legends, plans, and vesting terms when tests need them.Reviewed by Cursor Bugbot for commit b5f8bbc. Bugbot is set up for automated code reviews on this repo. Configure here.