* #6707

* Fix default values for address input (#6701)

* #6702

* Remove .only
This commit is contained in:
Jaco Greeff
2017-10-11 20:34:25 +02:00
committed by Arkadiy Paronyan
parent d097956ede
commit 9afd1006ed
6 changed files with 90 additions and 32 deletions

View File

@@ -75,7 +75,13 @@ export function bytesToAscii (bytes) {
}
export function asciiToHex (string) {
return '0x' + string.split('').map((s) => s.charCodeAt(0).toString(16)).join('');
let result = '0x';
for (let i = 0; i < string.length; ++i) {
result += ('0' + string.charCodeAt(i).toString(16)).substr(-2);
}
return result;
}
export function padRight (input, length) {

View File

@@ -68,6 +68,14 @@ describe('api/util/format', () => {
it('correctly converts a non-empty string', () => {
expect(asciiToHex('abc')).to.equal('0x616263');
});
it('correctly converts where charCode < 0x10', () => {
expect(
asciiToHex(
[32, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0].map((v) => String.fromCharCode(v)).join('')
)
).to.equal('0x20100f0e0d0c0b0a09080706050403020100');
});
});
describe('hexToAscii', () => {