@@ -9,8 +9,10 @@ import {
99 BtdFungibleMutationRejectedError ,
1010 BTD_MAX_MINTABLE_SUPPLY ,
1111 BITCODE_FEE_ASSET ,
12+ applyAssetPackSettlementUnlockToPreview ,
1213 assertBtdAccessPolicyTemplateCoverage ,
1314 assertBtdMintableSupplyLimit ,
15+ buildAssetPackSettlementUnlock ,
1416 buildBtdReadAccessProjectionFromRegistryRows ,
1517 calculateLlmBtcFeeEstimate ,
1618 calculateMeasuredBtdFromTokens ,
@@ -44,6 +46,97 @@ describe('calculateLlmBtcFeeEstimate', () => {
4446 } ) ;
4547} ) ;
4648
49+ describe ( 'AssetPack settlement unlock' , ( ) => {
50+ const completeReadback = {
51+ semanticMeasurement : true ,
52+ measureMintReceipt : true ,
53+ assetPackRange : true ,
54+ btdCell : true ,
55+ ownershipEvent : true ,
56+ readLicense : true ,
57+ mintReceipt : true ,
58+ btcFeeTransaction : true ,
59+ ledgerAnchor : true ,
60+ terminalJournal : true ,
61+ cryptoTelemetry : true ,
62+ } ;
63+
64+ it ( 'unlocks protected source only after settlement, readback, license, and delivery agree' , ( ) => {
65+ const unlock = buildAssetPackSettlementUnlock ( {
66+ ledgerSettlement : {
67+ status : 'settled' ,
68+ settlementAdmissible : true ,
69+ assetPackId : 'asset-pack-1' ,
70+ ledgerAnchorId : 'ledger-anchor-1' ,
71+ btcFeeReceiptId : 'btc-fee-1' ,
72+ ownershipEventId : 'ownership-1' ,
73+ readLicenseId : 'license-1' ,
74+ depositorWalletId : 'wallet-depositor' ,
75+ readerWalletId : 'wallet-reader' ,
76+ readback : completeReadback ,
77+ } ,
78+ pullRequestTarget : 'https://github.com/engineeredsoftware/ENGI/pull/42' ,
79+ } ) ;
80+
81+ expect ( unlock ) . toMatchObject ( {
82+ schema : 'bitcode.asset-pack.settlement-unlock' ,
83+ state : 'licensed_read' ,
84+ sourceAvailable : true ,
85+ settlementAdmissible : true ,
86+ deliveryAvailable : true ,
87+ assetPackId : 'asset-pack-1' ,
88+ readLicenseId : 'license-1' ,
89+ btcFeeReceiptId : 'btc-fee-1' ,
90+ missingReadbackKeys : [ ] ,
91+ } ) ;
92+
93+ const preview = applyAssetPackSettlementUnlockToPreview (
94+ {
95+ accessPolicy : { readRightState : 'pending_settlement' } ,
96+ unlock : { state : 'pending_settlement' , sourceAvailable : false } ,
97+ delivery : { pullRequestTarget : null , availableAfterSettlement : true } ,
98+ } ,
99+ unlock ,
100+ ) ;
101+
102+ expect ( preview ) . toMatchObject ( {
103+ accessPolicy : { readRightState : 'licensed_read' } ,
104+ unlock : {
105+ state : 'licensed_read' ,
106+ sourceAvailable : true ,
107+ } ,
108+ delivery : {
109+ pullRequestTarget : 'https://github.com/engineeredsoftware/ENGI/pull/42' ,
110+ } ,
111+ settlementUnlock : unlock ,
112+ } ) ;
113+ } ) ;
114+
115+ it ( 'keeps protected source withheld when any settlement readback key is missing' , ( ) => {
116+ const unlock = buildAssetPackSettlementUnlock ( {
117+ ledgerSettlement : {
118+ status : 'settled' ,
119+ settlementAdmissible : true ,
120+ assetPackId : 'asset-pack-1' ,
121+ readLicenseId : 'license-1' ,
122+ readback : {
123+ ...completeReadback ,
124+ readLicense : false ,
125+ } ,
126+ } ,
127+ pullRequestTarget : 'https://github.com/engineeredsoftware/ENGI/pull/42' ,
128+ } ) ;
129+
130+ expect ( unlock ) . toMatchObject ( {
131+ state : 'pending_settlement' ,
132+ sourceAvailable : false ,
133+ settlementAdmissible : false ,
134+ missingReadbackKeys : [ 'readLicense' ] ,
135+ } ) ;
136+ expect ( unlock . reason ) . toContain ( 'readLicense' ) ;
137+ } ) ;
138+ } ) ;
139+
47140describe ( 'calculateMeasuredBtdFromTokens' , ( ) => {
48141 it ( 'measures content amount without implying spend' , ( ) => {
49142 expect ( calculateMeasuredBtdFromTokens ( { inputTokens : 1200 , outputTokens : 50 } ) ) . toBe ( 2 ) ;
0 commit comments