Add UInt .isMax() (#1791)

* Add UInt .isMax()

* Filter lockedBlance by max
This commit is contained in:
Jaco Greeff
2020-02-01 21:20:48 +01:00
committed by GitHub
parent 438c830366
commit 7221a3637c
4 changed files with 27 additions and 2 deletions
+9
View File
@@ -111,6 +111,15 @@ export default abstract class AbstractInt extends BN implements Codec {
);
}
/**
* @description True if this value is the max of the type
*/
public isMax (): boolean {
const u8a = this.toU8a().filter((byte): boolean => byte === 0xff);
return u8a.length === (this._bitLength / 8);
}
/**
* @description Returns the BN representation of the number. (Compatibility)
*/
+13
View File
@@ -70,4 +70,17 @@ describe('UInt', (): void => {
expect(test.eq('0x3039')).toBe(true);
});
});
describe('isMax()', (): void => {
it('is false where not full', (): void => {
expect(new UInt(registry, '0x1234', 32).isMax()).toEqual(false);
expect(new UInt(registry, '0xffffff', 32).isMax()).toEqual(false);
expect(new UInt(registry, '0x12345678', 32).isMax()).toEqual(false);
expect(new UInt(registry, '0xfffffff0', 32).isMax()).toEqual(false);
});
it('is true when full', (): void => {
expect(new UInt(registry, '0xffffffff', 32).isMax()).toEqual(true);
});
});
});