From e28655778b07fe5761adf9cea60a87e2e499c4fd Mon Sep 17 00:00:00 2001 From: Daniel Bate Date: Fri, 30 Aug 2024 13:42:55 +0100 Subject: [PATCH] fix: `UtxoIdCoder` output index to be `u16` (#3064) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: utxo id output index to be u16 * chore: changeset * chore: lint --------- Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> --- .changeset/thin-shrimps-remain.md | 5 +++++ packages/transactions/src/coders/utxo-id.test.ts | 16 +++++++++++++++- packages/transactions/src/coders/utxo-id.ts | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changeset/thin-shrimps-remain.md diff --git a/.changeset/thin-shrimps-remain.md b/.changeset/thin-shrimps-remain.md new file mode 100644 index 00000000000..a5cda006e36 --- /dev/null +++ b/.changeset/thin-shrimps-remain.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/transactions": patch +--- + +fix: `UtxoIdCoder` output index to be `u16` diff --git a/packages/transactions/src/coders/utxo-id.test.ts b/packages/transactions/src/coders/utxo-id.test.ts index 744ec43c692..a1e72ee6670 100644 --- a/packages/transactions/src/coders/utxo-id.test.ts +++ b/packages/transactions/src/coders/utxo-id.test.ts @@ -10,7 +10,7 @@ const B256 = '0xd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b * @group browser */ describe('UtxoIdCoder', () => { - it('can encode UtxoId', () => { + it('can encode UtxoId [u8 output]', () => { const utxoId: UtxoId = { transactionId: B256, outputIndex: 0, @@ -27,6 +27,20 @@ describe('UtxoIdCoder', () => { expect(offset).toEqual(40); expect(decoded).toEqual(utxoId); }); + + it('can encode UtxoId [u16 output]', () => { + const utxoId: UtxoId = { + transactionId: B256, + outputIndex: 256, + }; + + const encoded = hexlify(new UtxoIdCoder().encode(utxoId)); + + expect(encoded).toEqual( + '0xd5579c46dfcc7f18207013e65b44e4cb4e2c2298f4ac457ba8f82743f31e930b0000000000000100' + ); + }); + it('does not encode bad UtxoId', () => { const utxoId: UtxoId = { // @ts-expect-error: Values shouldn't be assignable diff --git a/packages/transactions/src/coders/utxo-id.ts b/packages/transactions/src/coders/utxo-id.ts index c6b0688e937..a967e626c7c 100644 --- a/packages/transactions/src/coders/utxo-id.ts +++ b/packages/transactions/src/coders/utxo-id.ts @@ -14,7 +14,7 @@ export class UtxoIdCoder extends StructCoder<{ constructor() { super('UtxoId', { transactionId: new B256Coder(), - outputIndex: new NumberCoder('u8', { padToWordSize: true }), + outputIndex: new NumberCoder('u16', { padToWordSize: true }), }); } }