Skip to content

Commit b329971

Browse files
committed
fix(cip2): computeSelectionLimit constraint logic error
1 parent d2b2330 commit b329971

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Diff for: packages/cip2/src/selectionConstraints.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const getTxSize = (tx: CSL.Transaction) => tx.to_bytes().length;
6767
* that adjust selection based on selection limit. RRRI implementation uses this after selecting all the inputs
6868
* and throws MaximumInputCountExceeded if the constraint returns a limit higher than number of selected utxo.
6969
*
70-
* @returns {ComputeSelectionLimit} constraint that returns txSize <= maxTxSize ? utxo[].length : utxo[].length+1
70+
* @returns {ComputeSelectionLimit} constraint that returns txSize <= maxTxSize ? utxo[].length : utxo[].length-1
7171
*/
7272
export const computeSelectionLimit =
7373
(maxTxSize: ProtocolParametersRequiredByInputSelection['maxTxSize'], buildTx: BuildTx): ComputeSelectionLimit =>
@@ -77,7 +77,7 @@ export const computeSelectionLimit =
7777
if (txSize <= maxTxSize) {
7878
return selectionSkeleton.inputs.size;
7979
}
80-
return selectionSkeleton.inputs.size + 1;
80+
return selectionSkeleton.inputs.size - 1;
8181
};
8282

8383
export const defaultSelectionConstraints = ({

Diff for: packages/cip2/test/selectionConstraints.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('defaultSelectionConstraints', () => {
9090
protocolParameters
9191
});
9292
expect(await constraints.computeSelectionLimit({ inputs: new Set([1, 2]) as any } as SelectionSkeleton)).toEqual(
93-
3
93+
1
9494
);
9595
});
9696
});

0 commit comments

Comments
 (0)