Skip to content

Commit

Permalink
test: add missing test coverage to boolean coder throw conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbate committed May 2, 2023
1 parent 2d91413 commit 04acf65
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/abi-coder/src/coders/boolean.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as mathMod from '@fuel-ts/math';

import BooleanCoder from './boolean';

jest.mock('@fuel-ts/math', () => ({
__esModule: true,
...jest.requireActual('@fuel-ts/math'),
}));

describe('BooleanCoder', () => {
const TRUE_DECODED = true;
const TRUE_ENCODED = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 1]);
Expand Down Expand Up @@ -40,6 +47,26 @@ describe('BooleanCoder', () => {
expect(actualLength).toBe(expectedLength);
});

it('should throw an error when encoding an invalid boolean value', () => {
const toBytesSpy = jest
.spyOn(mathMod, 'toBytes')
.mockReturnValueOnce(new Uint8Array([0, 0, 0, 0, 0, 0, 0, 1]));

expect(() => {
coder.encode(TRUE_DECODED);
}).toThrow('Invalid bool');
});

it('should throw an error when input to encode cannot be converted to bytes', () => {
const toBytesSpy = jest.spyOn(mathMod, 'toBytes').mockImplementationOnce(() => {
throw new Error();
});

expect(() => {
coder.encode(TRUE_DECODED);
}).toThrow('Invalid bool');
});

it('should throw an error when decoding an invalid boolean value', () => {
const invalidInput = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 2]);

Expand Down

0 comments on commit 04acf65

Please sign in to comment.