Add UInt .isMax() (#1791)
* Add UInt .isMax() * Filter lockedBlance by max
This commit is contained in:
@@ -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)
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user