Skip to content

Commit d3a12cf

Browse files
committed
fix(cip2): omit 0 qty assets from change bundles
1 parent 1c34774 commit d3a12cf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: packages/cip2/src/RoundRobinRandomImprove/change.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,13 @@ const coalesceChangeBundlesForMinCoinRequirement = (
185185
return changeBundles;
186186
}
187187

188-
let sortedBundles = orderBy(changeBundles, ({ coins }) => coins, 'desc');
188+
const noZeroQuantityAssetChangeBundles = changeBundles.map(
189+
({ coins, assets }): Cardano.Value => ({
190+
assets: assets ? new Map([...assets.entries()].filter(([_, quantity]) => quantity > 0n)) : undefined,
191+
coins
192+
})
193+
);
194+
let sortedBundles = orderBy(noZeroQuantityAssetChangeBundles, ({ coins }) => coins, 'desc');
189195
const satisfiesMinCoinRequirement = (valueQuantities: Cardano.Value) =>
190196
valueQuantities.coins >= computeMinimumCoinQuantity(valueQuantities.assets);
191197

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

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ describe('RoundRobinRandomImprove', () => {
3434
}
3535
});
3636
});
37+
it('0 token change', async () => {
38+
// Regression
39+
await testInputSelectionProperties({
40+
createOutputs: () => [TxTestUtil.createOutput({ assets: new Map([[AssetId.TSLA, 7001n]]), coins: 1000n })],
41+
createUtxo: () => [
42+
TxTestUtil.createUnspentTxOutput({ assets: new Map([[AssetId.TSLA, 7001n]]), coins: 11_999_994n })
43+
],
44+
getAlgorithm: roundRobinRandomImprove,
45+
mockConstraints: SelectionConstraints.MOCK_NO_CONSTRAINTS
46+
});
47+
});
3748
it('Selects UTxO even when implicit input covers outputs', async () => {
3849
const utxo = new Set([TxTestUtil.createUnspentTxOutput({ coins: 10_000_000n })]);
3950
const outputs = new Set([TxTestUtil.createOutput({ coins: 1_000_000n })]);

0 commit comments

Comments
 (0)