From 20f8c89799243604caf8e0115c97f636ebce4c50 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira <88039515+msensys@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:18:11 -0300 Subject: [PATCH] chore: add tests to `EnumCoder` (#2515) Co-authored-by: Daniel Bate Co-authored-by: Peter Smith Co-authored-by: Chad Nehemiah --- .changeset/rotten-walls-tickle.md | 4 ++++ .../src/encoding/coders/EnumCoder.test.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 .changeset/rotten-walls-tickle.md diff --git a/.changeset/rotten-walls-tickle.md b/.changeset/rotten-walls-tickle.md new file mode 100644 index 00000000000..175790abe95 --- /dev/null +++ b/.changeset/rotten-walls-tickle.md @@ -0,0 +1,4 @@ +--- +--- + +chore: add tests to `EnumCoder` \ No newline at end of file diff --git a/packages/abi-coder/src/encoding/coders/EnumCoder.test.ts b/packages/abi-coder/src/encoding/coders/EnumCoder.test.ts index 9bef6745323..064f81dc15f 100644 --- a/packages/abi-coder/src/encoding/coders/EnumCoder.test.ts +++ b/packages/abi-coder/src/encoding/coders/EnumCoder.test.ts @@ -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', () => { @@ -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.') + ); + }); }); });