Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
fix: remove unused method hexToUint8Reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLaw committed Aug 10, 2021
1 parent 8552ee9 commit 83fd5e7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
15 changes: 0 additions & 15 deletions catapult-sdk/src/utils/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,6 @@ const convert = {

return (input & 0xFFFFFFFF) >>> 0;
},

/** Reversed convertion hex string to a uint8 array.
* @param {string} input A hex encoded string.
* @returns {Uint8Array} A uint8 array corresponding to the input.
*/
hexToUint8Reverse: input => {
if (0 !== input.length % 2)
throw Error(`hex string has unexpected size '${input.length}'`);

const output = new Uint8Array(input.length / 2);
for (let i = 0; i < input.length; i += 2)
output[(output.length - 1) - (i / 2)] = convert.toByte(input[i], input[i + 1]);

return output;
}
};

module.exports = convert;
39 changes: 0 additions & 39 deletions catapult-sdk/test/utils/convert_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,43 +436,4 @@ describe('convert', () => {
});
});
});

describe('hexToUint8Reverse', () => {
it('can parse empty hex string into array', () => {
// Act:
const actual = convert.hexToUint8Reverse('');

// Assert:
const expected = Uint8Array.of();
expect(actual).to.deep.equal(expected);
});

it('can parse valid hex string into array', () => {
// Act:
const actual = convert.hexToUint8Reverse('026ee415fc15');

// Assert:
const expected = Uint8Array.of(0x15, 0xFC, 0x15, 0xE4, 0x6E, 0x02);
expect(actual).to.deep.equal(expected);
});

it('can parse valid hex string containing all valid hex characters into array', () => {
// Act:
const actual = convert.hexToUint8Reverse('abcdef0123456789ABCDEF');

// Assert:
const expected = Uint8Array.of(0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB);
expect(actual).to.deep.equal(expected);
});

it('cannot parse hex string with invalid characters into array', () => {
// Assert:
expect(() => { convert.hexToUint8Reverse('abcdef012345G789ABCDEF'); }).to.throw('unrecognized hex char');
});

it('cannot parse hex string with invalid size into array', () => {
// Assert:
expect(() => { convert.hexToUint8Reverse('abcdef012345G789ABCDE'); }).to.throw('hex string has unexpected size');
});
});
});

0 comments on commit 83fd5e7

Please sign in to comment.