Skip to content

Commit f106a78

Browse files
authored
chore: now bn accepts null (#523)
1 parent fa83fcd commit f106a78

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.changeset/brown-teachers-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fuel-ts/math": patch
3+
---
4+
5+
now `bn` accepts `null`

packages/math/src/bn.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,16 @@ describe('Math - BN', () => {
281281
expect(() => bn(over).toHex(4)).toThrow();
282282
});
283283

284-
it('should create bn with number or undefined', () => {
285-
const inputs: { numb: number; str: string; undef?: string } = {
284+
it('should create bn with number or undefined or null', () => {
285+
const inputs: { numb: number; str: string; undef?: string; nil: null } = {
286286
numb: 2,
287287
str: '5',
288+
nil: null,
288289
};
289290

290291
expect(bn().toNumber()).toEqual(0);
291292
expect(bn(inputs?.undef).toNumber()).toEqual(0);
293+
expect(bn(inputs?.nil).toNumber()).toEqual(0);
292294
expect(bn(inputs?.numb).toNumber()).toEqual(2);
293295
expect(bn(inputs?.str).toNumber()).toEqual(5);
294296
});

packages/math/src/bn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface BNHiddenTypes {
4141
type BNInputOverridesKeys = keyof BNInputOverrides;
4242

4343
export class BN extends BnJs implements BNInputOverrides, BNHiddenTypes, BNHelper, BNOverrides {
44-
constructor(value?: BNInput, base?: number | 'hex', endian?: BnJs.Endianness) {
44+
constructor(value?: BNInput | null, base?: number | 'hex', endian?: BnJs.Endianness) {
4545
if (BN.isBN(value)) {
4646
super(value.toArray(), base, endian);
4747
return;
@@ -251,7 +251,7 @@ export class BN extends BnJs implements BNInputOverrides, BNHiddenTypes, BNHelpe
251251
}
252252

253253
// functional shortcut to create BN
254-
export const bn = (value?: BNInput, base?: number | 'hex', endian?: BnJs.Endianness) =>
254+
export const bn = (value?: BNInput | null, base?: number | 'hex', endian?: BnJs.Endianness) =>
255255
new BN(value, base, endian);
256256

257257
bn.parseUnits = (value: string, units: number = DECIMAL_UNITS): BN => {

0 commit comments

Comments
 (0)