Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.

Commit f719cf6

Browse files
committed
Update toBuffer tests
1 parent 9d91f70 commit f719cf6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,9 @@ describe('toBuffer', function () {
484484
// Array
485485
assert.deepEqual(ethUtils.toBuffer([]), Buffer.allocUnsafe(0))
486486
// String
487-
assert.deepEqual(ethUtils.toBuffer('11'), Buffer.from([49, 49]))
488487
assert.deepEqual(ethUtils.toBuffer('0x11'), Buffer.from([17]))
489-
assert.deepEqual(ethUtils.toBuffer('1234').toString('hex'), '31323334')
490488
assert.deepEqual(ethUtils.toBuffer('0x1234').toString('hex'), '1234')
489+
assert.deepEqual(ethUtils.toBuffer('0x'), Buffer.from([]))
491490
// Number
492491
assert.deepEqual(ethUtils.toBuffer(1), Buffer.from([1]))
493492
// null
@@ -504,6 +503,12 @@ describe('toBuffer', function () {
504503
ethUtils.toBuffer({ test: 1 })
505504
})
506505
})
506+
507+
it('should fail with non 0x-prefixed hex strings', function() {
508+
assert.throws(() => ethUtils.toBuffer('11'))
509+
assert.throws(() => ethUtils.toBuffer(''))
510+
assert.throws(() => ethUtils.toBuffer('0xR'))
511+
})
507512
})
508513

509514
describe('baToJSON', function () {

0 commit comments

Comments
 (0)