@@ -377,28 +377,33 @@ describe('generateAddress2: EIP-1014 testdata examples', function() {
377
377
378
378
describe ( 'isPrecompiled' , function ( ) {
379
379
it ( 'should return true' , function ( ) {
380
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000001 ' ) , true )
381
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000002 ' ) , true )
382
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000003 ' ) , true )
383
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000004 ' ) , true )
384
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000005 ' ) , true )
385
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000006 ' ) , true )
386
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000007 ' ) , true )
387
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000008 ' ) , true )
380
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000001 ' ) , true )
381
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000002 ' ) , true )
382
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000003 ' ) , true )
383
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000004 ' ) , true )
384
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000005 ' ) , true )
385
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000006 ' ) , true )
386
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000007 ' ) , true )
387
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000008 ' ) , true )
388
388
assert . equal (
389
389
isPrecompiled ( Buffer . from ( '0000000000000000000000000000000000000001' , 'hex' ) ) ,
390
390
true ,
391
391
)
392
392
} )
393
393
it ( 'should return false' , function ( ) {
394
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000000 ' ) , false )
395
- assert . equal ( isPrecompiled ( '0000000000000000000000000000000000000009 ' ) , false )
396
- assert . equal ( isPrecompiled ( '1000000000000000000000000000000000000000 ' ) , false )
394
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000000 ' ) , false )
395
+ assert . equal ( isPrecompiled ( '0x0000000000000000000000000000000000000009 ' ) , false )
396
+ assert . equal ( isPrecompiled ( '0x1000000000000000000000000000000000000000 ' ) , false )
397
397
assert . equal (
398
398
isPrecompiled ( Buffer . from ( '0000000000000000000000000000000000000000' , 'hex' ) ) ,
399
399
false ,
400
400
)
401
401
} )
402
+ it ( 'should throw when address is string and not hex-prefixed' , function ( ) {
403
+ assert . throws ( function ( ) {
404
+ isPrecompiled ( '0000000000000000000000000000000000000001' )
405
+ } )
406
+ } )
402
407
} )
403
408
404
409
const eip55ChecksumAddresses = [
@@ -473,6 +478,14 @@ describe('.toChecksumAddress()', function() {
473
478
}
474
479
} )
475
480
} )
481
+
482
+ describe ( 'input format' , function ( ) {
483
+ it ( 'Should throw when the address is not hex-prefixed' , function ( ) {
484
+ assert . throws ( function ( ) {
485
+ toChecksumAddress ( '52908400098527886E0F7030069857D2E4169EE7' . toLowerCase ( ) )
486
+ } )
487
+ } )
488
+ } )
476
489
} )
477
490
478
491
describe ( '.isValidChecksumAddress()' , function ( ) {
@@ -513,6 +526,14 @@ describe('.isValidChecksumAddress()', function() {
513
526
}
514
527
} )
515
528
} )
529
+
530
+ describe ( 'input format' , function ( ) {
531
+ it ( 'Should throw when the address is not hex-prefixed' , function ( ) {
532
+ assert . throws ( function ( ) {
533
+ isValidChecksumAddress ( '2f015c60e0be116b1f0cd534704db9c92118fb6a' )
534
+ } )
535
+ } )
536
+ } )
516
537
} )
517
538
518
539
describe ( '.isValidAddress()' , function ( ) {
@@ -521,10 +542,27 @@ describe('.isValidAddress()', function() {
521
542
assert . equal ( isValidAddress ( '0x52908400098527886E0F7030069857D2E4169EE7' ) , true )
522
543
} )
523
544
it ( 'should return false' , function ( ) {
524
- assert . equal ( isValidAddress ( '2f015c60e0be116b1f0cd534704db9c92118fb6a' ) , false )
525
545
assert . equal ( isValidAddress ( '0x2f015c60e0be116b1f0cd534704db9c92118fb6' ) , false )
526
546
assert . equal ( isValidAddress ( '0x2f015c60e0be116b1f0cd534704db9c92118fb6aa' ) , false )
527
- assert . equal ( isValidAddress ( '0X52908400098527886E0F7030069857D2E4169EE7' ) , false )
528
- assert . equal ( isValidAddress ( 'x2f015c60e0be116b1f0cd534704db9c92118fb6a' ) , false )
547
+ } )
548
+ it ( 'should throw when input is not hex prefixed' , function ( ) {
549
+ assert . throws ( function ( ) {
550
+ isValidAddress ( '2f015c60e0be116b1f0cd534704db9c92118fb6a' )
551
+ } )
552
+ assert . throws ( function ( ) {
553
+ isValidAddress ( 'x2f015c60e0be116b1f0cd534704db9c92118fb6a' )
554
+ } )
555
+ assert . throws ( function ( ) {
556
+ isValidAddress ( '0X52908400098527886E0F7030069857D2E4169EE7' )
557
+ } )
558
+ } )
559
+ it ( 'error message should have correct format' , function ( ) {
560
+ const input = '2f015c60e0be116b1f0cd534704db9c92118fb6a'
561
+ try {
562
+ isValidAddress ( '2f015c60e0be116b1f0cd534704db9c92118fb6a' )
563
+ } catch ( err ) {
564
+ assert ( err . message . includes ( 'only supports 0x-prefixed hex strings' ) )
565
+ assert ( err . message . includes ( input ) )
566
+ }
529
567
} )
530
568
} )
0 commit comments