Skip to content

Commit

Permalink
fix: UtxoIdCoder output index to be u16 (#3064)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
danielbate and Torres-ssf authored Aug 30, 2024
1 parent 2b45e8d commit e286557
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-shrimps-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/transactions": patch
---

fix: `UtxoIdCoder` output index to be `u16`
16 changes: 15 additions & 1 deletion packages/transactions/src/coders/utxo-id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/src/coders/utxo-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
});
}
}

0 comments on commit e286557

Please sign in to comment.