Skip to content

Commit

Permalink
chore: improving error message
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 committed Dec 30, 2024
1 parent 8faf42d commit eb24fc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions packages/abi-coder/src/encoding/coders/BigNumberCoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ describe('BigNumberCoder', () => {
expect(data).toEqual(expected);
});

it('should throw an error when encoding [number more than max safe integer]', () => {
it('should throw an error when encoding [number more than max safe integer]', async () => {
const coder = new BigNumberCoder('u64');
const value: number = Number.MAX_SAFE_INTEGER + 1;

expect(() => coder.encode(value)).toThrow(
new FuelError(ErrorCode.ENCODE_ERROR, 'Invalid u64 type - number value is too large.')
await expectToThrowFuelError(

Check failure on line 40 in packages/abi-coder/src/encoding/coders/BigNumberCoder.test.ts

View workflow job for this annotation

GitHub Actions / browser

packages/abi-coder/src/encoding/coders/BigNumberCoder.test.ts > BigNumberCoder > should throw an error when encoding [number more than max safe integer]

AssertionError: expected 'Invalid u64 type - number value is to…' to deeply equal 'Invalid u64 type - too large. Number …' Expected: "Invalid u64 type - too large. Number can only safely handle up to 53 bits." Received: "Invalid u64 type - number value is too large. Number can only safely handle up to 53 bits." ❯ packages/abi-coder/src/encoding/coders/BigNumberCoder.test.ts:40:4
() => coder.encode(value),
new FuelError(
ErrorCode.ENCODE_ERROR,
'Invalid u64 type - too large. Number can only safely handle up to 53 bits.'
)
);
});

Expand All @@ -52,12 +56,16 @@ describe('BigNumberCoder', () => {
expect(data).toEqual(expected);
});

it('should throw an error when encoding [number more than max safe integer]', () => {
it('should throw an error when encoding [number more than max safe integer]', async () => {
const coder = new BigNumberCoder('u64');
const value: number = 76472027892439376;

expect(() => coder.encode(value)).toThrow(
new FuelError(ErrorCode.ENCODE_ERROR, 'Invalid u64 type - too large. Number can only safely handle up to 53 bits').
await expectToThrowFuelError(

Check failure on line 63 in packages/abi-coder/src/encoding/coders/BigNumberCoder.test.ts

View workflow job for this annotation

GitHub Actions / browser

packages/abi-coder/src/encoding/coders/BigNumberCoder.test.ts > BigNumberCoder > should throw an error when encoding [number more than max safe integer]

AssertionError: expected 'Invalid u64 type - number value is to…' to deeply equal 'Invalid u64 type - too large. Number …' Expected: "Invalid u64 type - too large. Number can only safely handle up to 53 bits." Received: "Invalid u64 type - number value is too large. Number can only safely handle up to 53 bits." ❯ packages/abi-coder/src/encoding/coders/BigNumberCoder.test.ts:63:4
() => coder.encode(value),
new FuelError(
ErrorCode.ENCODE_ERROR,
'Invalid u64 type - too large. Number can only safely handle up to 53 bits.'
)
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/abi-coder/src/encoding/coders/BigNumberCoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class BigNumberCoder extends Coder<BNInput, BN> {
if (typeof value === 'number' && value > Number.MAX_SAFE_INTEGER) {
throw new FuelError(
ErrorCode.ENCODE_ERROR,
`Invalid ${this.type} type - number value is too large.`
`Invalid ${this.type} type - number value is too large. Number can only safely handle up to 53 bits.`
);
}

Expand Down

0 comments on commit eb24fc1

Please sign in to comment.