Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tests to EnumCoder #2515

Merged
merged 11 commits into from
Jun 18, 2024
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.')
);
});
});
});
Loading