Use mergeInvitationCommits in resolveCommitReferences for correct commit merging.

Delegate input/output merging to the engine so mergesWith extensions and
transaction indices resolve correctly instead of flattening raw commits.
This commit is contained in:
2026-06-15 18:36:55 +10:00
parent d2c37fd957
commit 771968dfbb
2 changed files with 249 additions and 21 deletions

View File

@@ -123,6 +123,36 @@ const originalInvitation: XOInvitation = {
],
};
/**
* Customer input commit extended with unlocking bytecode via mergesWith (signing flow).
*/
const invitationWithSignedInput: XOInvitation = {
...originalInvitation,
commits: [
...originalInvitation.commits.slice(0, 5),
{
commitIdentifier: "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
previousCommitIdentifier: "d18b9a0caa638eaa1d0711f333e9c114",
entityIdentifier: CUSTOMER_ENTITY,
data: {
inputs: [
{
mergesWith: {
commitIdentifier: "d18b9a0caa638eaa1d0711f333e9c114",
index: 0,
},
unlockingBytecode:
"41226b2be7c2890c8bbde2f79e79640e56d866843f2e822ec51c469019d13db0",
},
],
},
signature:
"3045022001a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456789022100fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321",
expiresAtTimestamp: 1779507008000,
},
],
};
describe("resolveCommitReferences", () => {
it("flattens commits and enriches items with template metadata", () => {
const resolved = resolveCommitReferences(
@@ -237,4 +267,21 @@ describe("resolveCommitReferences", () => {
expect(resolved.outputs[1]).not.toHaveProperty("name");
expect(resolved.outputs[1]).not.toHaveProperty("outputIdentifier");
});
it("merges input extension commits via mergesWith into a single input", () => {
const resolved = resolveCommitReferences(
invitationWithSignedInput,
vendingMachineTemplate,
);
expect(resolved.inputs).toHaveLength(1);
expect(resolved.inputs[0]).toMatchObject({
entityIdentifier: CUSTOMER_ENTITY,
outpointTransactionHash:
"b1e8f77cdc60efac19f668fc5c7177ace42a46e2532f230979559c7190c3c80a",
outpointIndex: 1,
unlockingBytecode:
"41226b2be7c2890c8bbde2f79e79640e56d866843f2e822ec51c469019d13db0",
});
});
});