Skip to content

Commit c1ea23f

Browse files
Merge pull request #1306 from input-output-hk/feat/cad-5432-add-initial-plutus-script-support-js-sdk
2 parents 1056dbe + 08f0ee0 commit c1ea23f

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/tx-construction/src/input-selection/selectionConstraints.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
ProtocolParametersRequiredByInputSelection,
88
SelectionConstraints,
99
SelectionSkeleton,
10-
TokenBundleSizeExceedsLimit
10+
TokenBundleSizeExceedsLimit,
11+
sortTxIn
1112
} from '@cardano-sdk/input-selection';
1213
import { MinFeeCoefficient, MinFeeConstant, minAdaRequired, minFee } from '../fees';
1314
import { TxEvaluationResult, TxEvaluator, TxIdWithIndex } from '../tx-builder';
@@ -116,7 +117,7 @@ export const computeMinimumCost =
116117
async (selection) => {
117118
const tx = await buildTx(selection);
118119
const utxos = [...selection.inputs];
119-
const txIns = utxos.map((utxo) => utxo[0]);
120+
const txIns = utxos.map((utxo) => utxo[0]).sort(sortTxIn);
120121

121122
if (tx.witness && tx.witness.redeemers && tx.witness.redeemers.length > 0) {
122123
// before the evaluation can happen, we need to point every redeemer to its corresponding inputs.

packages/tx-construction/test/tx-builder/TxBuilderPlutusScripts.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,43 @@ describe('TxBuilder/plutusScripts', () => {
282282
expect(roundRobinRandomImprove).toHaveBeenCalled();
283283
});
284284

285+
it('can point the redeemer to the right input', async () => {
286+
const tx = await txBuilder
287+
.addInput(
288+
{
289+
index: 99,
290+
txId: 'ff21ffbaff60ff0cff8cff55ffa6ff6dff78ff78ffaeffceff36ff3fffc5ffe0' as unknown as Cardano.TransactionId
291+
},
292+
{
293+
datum: 1n,
294+
redeemer: 1n,
295+
script
296+
}
297+
)
298+
.addOutput(
299+
txBuilder
300+
.buildOutput({
301+
address: Cardano.PaymentAddress(
302+
'addr_test1qqt9c69kjqf0wsnlp7hs8xees5l6pm4yxdqa3hknqr0kfe0htmj4e5t8n885zxm4qzpfzwruqx3ey3f5q8kpkr0gt9ms8dcsz6'
303+
),
304+
value: { coins: 5_000_000_000n }
305+
})
306+
.toTxOut()
307+
)
308+
.build()
309+
.inspect();
310+
311+
expect(
312+
tx.body.inputs?.some((txIn) => txIn.txId === 'ff21ffbaff60ff0cff8cff55ffa6ff6dff78ff78ffaeffceff36ff3fffc5ffe0')
313+
).toBeTruthy();
314+
expect(tx.witness?.redeemers?.some((redeemer) => redeemer.data === 1n)).toBeTruthy();
315+
316+
const scriptInputIndex = tx.body.inputs?.findIndex(
317+
(input) => input.txId === 'ff21ffbaff60ff0cff8cff55ffa6ff6dff78ff78ffaeffceff36ff3fffc5ffe0' && input.index === 99
318+
);
319+
expect(tx.witness?.redeemers?.at(0)?.index).toEqual(scriptInputIndex);
320+
});
321+
285322
it('can set an script input for required selection with inline datum (unresolved),', async () => {
286323
const tx = await txBuilder
287324
.addInput(

0 commit comments

Comments
 (0)