Skip to content

Commit

Permalink
Merge branch 'master' into changeset-release/master
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbate authored Jun 18, 2024
2 parents 0cc665e + 20f8c89 commit 67274c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changeset/rotten-walls-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: add tests to `EnumCoder`
16 changes: 16 additions & 0 deletions packages/abi-coder/src/encoding/coders/EnumCoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ describe('EnumCoder', () => {
new FuelError(ErrorCode.INVALID_DECODE_VALUE, `Invalid case 'c'. Valid cases: 'a', 'b'.`)
);
});

it('should throw an error when multiple fields are provided', async () => {
await expectToThrowFuelError(
() => coder.encode({ a: 'test', b: 'test' } as never),
new FuelError(ErrorCode.INVALID_DECODE_VALUE, 'Only one field must be provided.')
);
});
});

describe('decode', () => {
Expand Down Expand Up @@ -122,5 +129,14 @@ describe('EnumCoder', () => {
new FuelError(ErrorCode.DECODE_ERROR, 'Invalid enum data size.')
);
});

it('throws when decoding data that is too short', async () => {
const input = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 1]);

await expectToThrowFuelError(
() => coder.decode(input, 0),
new FuelError(ErrorCode.DECODE_ERROR, 'Invalid enum data size.')
);
});
});
});

0 comments on commit 67274c6

Please sign in to comment.