Skip to content

Commit

Permalink
chore: add tests to EnumCoder (#2515)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Bate <djbate23@gmail.com>
Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>
Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
  • Loading branch information
4 people committed Jun 18, 2024
1 parent 90e8cba commit 20f8c89
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 20f8c89

Please sign in to comment.