Allow Moment with BE/LE hex encoding (#933)
* Allow Moment with BE/LE hex encoding * description clarification
This commit is contained in:
@@ -41,6 +41,18 @@ describe('Moment', () => {
|
||||
.startsWith('Thu Jan 01 1970') // The time depends on the timezone this test is run in
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('encodes default BE hex', () => {
|
||||
expect(
|
||||
new Moment(3).toHex()
|
||||
).toEqual('0x0000000000000003');
|
||||
});
|
||||
|
||||
it('encodes options LE hex', () => {
|
||||
expect(
|
||||
new Moment(3).toHex(true)
|
||||
).toEqual('0x0300000000000000');
|
||||
});
|
||||
});
|
||||
|
||||
describe('utils', () => {
|
||||
|
||||
@@ -83,8 +83,12 @@ export default class Moment extends Date implements Codec {
|
||||
/**
|
||||
* @description Returns a hex string representation of the value
|
||||
*/
|
||||
toHex (): string {
|
||||
return bnToHex(this.toBn(), BITLENGTH);
|
||||
toHex (isLe: boolean = false): string {
|
||||
return bnToHex(this.toBn(), {
|
||||
bitLength: BITLENGTH,
|
||||
isLe,
|
||||
isNegative: false
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user