From bcfb5a98727353410b2d0d6c3fcc88a8e805c28b Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Thu, 13 Jun 2024 14:54:06 -0300 Subject: [PATCH 1/3] test: add validations to EnumCoder --- .changeset/rotten-walls-tickle.md | 6 ++++++ .../src/encoding/coders/EnumCoder.test.ts | 16 ++++++++++++++++ 2 files changed, 22 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 0000000000..1e83bc9f2c --- /dev/null +++ b/.changeset/rotten-walls-tickle.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/abi-coder": minor +--- + +- Added validation to ensure only one field is provided when encoding enums +- Added validation to ensure decoded data has the appropriate size \ 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 9bef674532..064f81dc15 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.') + ); + }); }); }); From 10b2e028815dfcbda76117e79f8a9d7f54385c1f Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Thu, 13 Jun 2024 16:01:38 -0300 Subject: [PATCH 2/3] change title --- .changeset/rotten-walls-tickle.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/rotten-walls-tickle.md b/.changeset/rotten-walls-tickle.md index 1e83bc9f2c..f11153f5f5 100644 --- a/.changeset/rotten-walls-tickle.md +++ b/.changeset/rotten-walls-tickle.md @@ -2,5 +2,4 @@ "@fuel-ts/abi-coder": minor --- -- Added validation to ensure only one field is provided when encoding enums -- Added validation to ensure decoded data has the appropriate size \ No newline at end of file +chore: add tests to `EnumCoder` \ No newline at end of file From f11d9c0eb7e2e0f03952e0026cfad3d7a9dfb017 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira <88039515+msensys@users.noreply.github.com> Date: Mon, 17 Jun 2024 07:44:05 -0300 Subject: [PATCH 3/3] update .changetset file Co-authored-by: Daniel Bate --- .changeset/rotten-walls-tickle.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.changeset/rotten-walls-tickle.md b/.changeset/rotten-walls-tickle.md index f11153f5f5..175790abe9 100644 --- a/.changeset/rotten-walls-tickle.md +++ b/.changeset/rotten-walls-tickle.md @@ -1,5 +1,4 @@ --- -"@fuel-ts/abi-coder": minor --- chore: add tests to `EnumCoder` \ No newline at end of file