Skip to content

Commit e85871e

Browse files
Merge pull request #1117 from input-output-hk/feat/lw-9901-transactionBody-serializes-incorrectly-if-no-inputs
fix(core): transaction body can now serializes bodies with no inputs correctly
2 parents 50e9558 + 13800d6 commit e85871e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/core/src/Serialization/TransactionBody/TransactionBody.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ export class TransactionBody {
990990
let mapSize = 0;
991991

992992
if (this.#inputs !== undefined && this.#inputs.length > 0) ++mapSize;
993-
if (this.#outputs !== undefined && this.#inputs.length > 0) ++mapSize;
993+
if (this.#outputs !== undefined && this.#outputs.length > 0) ++mapSize;
994994
if (this.#fee !== undefined) ++mapSize;
995995
if (this.#ttl !== undefined) ++mapSize;
996996
if (this.#certs !== undefined && this.#certs.length > 0) ++mapSize;

packages/core/test/Serialization/TransactionBody/TransactionBody.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ export const core: Cardano.TxBody = {
6565
]
6666
};
6767

68+
export const noInputsCore: Cardano.TxBody = {
69+
certificates: [
70+
{
71+
__typename: Cardano.CertificateType.PoolRetirement,
72+
epoch: Cardano.EpochNo(500),
73+
poolId: Cardano.PoolId('pool1y6chk7x7fup4ms9leesdr57r4qy9cwxuee0msan72x976a6u0nc')
74+
}
75+
],
76+
fee: 10n,
77+
inputs: [],
78+
outputs: [txOut]
79+
};
80+
81+
export const noInputsCbor = HexBlob(
82+
'a30181825839009493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc820aa3581c2a286ad895d091f2b3d168a6091ad2627d30a72761a5bc36eef00740a14014581c659f2917fb63f12b33667463ee575eeac1845bbc736b9c0bbc40ba82a14454534c411832581c7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373a240182846504154415445181e020a04818304581c26b17b78de4f035dc0bfce60d1d3c3a8085c38dcce5fb8767e518bed1901f4'
83+
);
84+
6885
export const conwayCore: Cardano.TxBody = {
6986
...core,
7087
donation: 1000n,
@@ -239,4 +256,12 @@ describe('TransactionBody', () => {
239256

240257
expect(withdrawals).toEqual(expectedWithdrawals);
241258
});
259+
260+
it('can encode transaction bodies with 0 inputs correctly', () => {
261+
const bodyFromCbor = TransactionBody.fromCbor(noInputsCbor);
262+
const bodyFromCore = TransactionBody.fromCore(noInputsCore);
263+
264+
expect(bodyFromCbor.toCore()).toEqual(noInputsCore);
265+
expect(bodyFromCore.toCbor()).toEqual(noInputsCbor);
266+
});
242267
});

0 commit comments

Comments
 (0)