@@ -602,9 +602,27 @@ describe('.toChecksumAddress()', function() {
602
602
for ( const [ chainId , addresses ] of Object . entries ( eip1191ChecksummAddresses ) ) {
603
603
for ( const addr of addresses ) {
604
604
assert . equal ( toChecksumAddress ( addr . toLowerCase ( ) , Number ( chainId ) ) , addr )
605
+ assert . equal ( toChecksumAddress ( addr . toLowerCase ( ) , Buffer . from ( [ chainId ] ) ) , addr )
606
+ assert . equal ( toChecksumAddress ( addr . toLowerCase ( ) , new BN ( chainId ) ) , addr )
607
+ assert . equal (
608
+ toChecksumAddress ( addr . toLowerCase ( ) , '0x' + Buffer . from ( [ chainId ] ) . toString ( 'hex' ) ) ,
609
+ addr
610
+ )
605
611
}
606
612
}
607
613
} )
614
+ it ( 'Should encode large chain ids greater than MAX_INTEGER correctly' , function ( ) {
615
+ const addr = '0x88021160C5C792225E4E5452585947470010289D'
616
+ const chainIDBuffer = Buffer . from ( '796f6c6f763378' , 'hex' )
617
+ assert . equal ( toChecksumAddress ( addr . toLowerCase ( ) , chainIDBuffer ) , addr )
618
+ assert . equal ( toChecksumAddress ( addr . toLowerCase ( ) , new BN ( chainIDBuffer ) ) , addr )
619
+ assert . equal (
620
+ toChecksumAddress ( addr . toLowerCase ( ) , '0x' + chainIDBuffer . toString ( 'hex' ) ) ,
621
+ addr
622
+ )
623
+ const chainIDNumber = parseInt ( chainIDBuffer . toString ( 'hex' ) , 16 )
624
+ assert . equal ( toChecksumAddress ( addr . toLowerCase ( ) , chainIDNumber ) , addr )
625
+ } )
608
626
} )
609
627
610
628
describe ( 'input format' , function ( ) {
@@ -613,6 +631,11 @@ describe('.toChecksumAddress()', function() {
613
631
toChecksumAddress ( '52908400098527886E0F7030069857D2E4169EE7' . toLowerCase ( ) )
614
632
} )
615
633
} )
634
+ it ( 'Should throw when the chainId is not hex-prefixed' , function ( ) {
635
+ assert . throws ( function ( ) {
636
+ toChecksumAddress ( '0xde709f2102306220921060314715629080e2fb77' , '1234' )
637
+ } )
638
+ } )
616
639
} )
617
640
} )
618
641
@@ -633,6 +656,12 @@ describe('.isValidChecksumAddress()', function() {
633
656
for ( const [ chainId , addresses ] of Object . entries ( eip1191ChecksummAddresses ) ) {
634
657
for ( const addr of addresses ) {
635
658
assert . equal ( isValidChecksumAddress ( addr , Number ( chainId ) ) , true )
659
+ assert . equal ( isValidChecksumAddress ( addr , Buffer . from ( [ chainId ] ) ) , true )
660
+ assert . equal ( isValidChecksumAddress ( addr , new BN ( chainId ) ) , true )
661
+ assert . equal (
662
+ isValidChecksumAddress ( addr , '0x' + Buffer . from ( [ chainId ] ) . toString ( 'hex' ) ) ,
663
+ true
664
+ )
636
665
}
637
666
}
638
667
} )
0 commit comments