This repository was archived by the owner on Jun 17, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -75,11 +75,18 @@ export class Address {
75
75
return new Address ( generateAddress2 ( from . buf , salt , initCode ) )
76
76
}
77
77
78
+ /**
79
+ * Is address equal to another.
80
+ */
81
+ equals ( address : Address ) : boolean {
82
+ return this . buf . equals ( address . buf )
83
+ }
84
+
78
85
/**
79
86
* Is address zero.
80
87
*/
81
88
isZero ( ) : boolean {
82
- return this . buf . equals ( Address . zero ( ) . buf )
89
+ return this . equals ( Address . zero ( ) )
83
90
}
84
91
85
92
/**
Original file line number Diff line number Diff line change @@ -84,4 +84,22 @@ describe('Address', () => {
84
84
addressBuf . fill ( 0 )
85
85
assert . equal ( address . toString ( ) , str )
86
86
} )
87
+
88
+ it ( 'should compare equality properly' , ( ) => {
89
+ const str = '0x2f015c60e0be116b1f0cd534704db9c92118fb6a'
90
+ const address1 = Address . fromString ( str )
91
+ const address2 = new Address ( Buffer . from ( str . slice ( 2 ) , 'hex' ) )
92
+ assert . ok ( address1 . equals ( address2 ) )
93
+ assert . ok ( address1 . buf . equals ( address2 . buf ) )
94
+
95
+ const str2 = '0xcd4EC7b66fbc029C116BA9Ffb3e59351c20B5B06'
96
+ const address3 = Address . fromString ( str2 )
97
+ assert . ok ( ! address1 . equals ( address3 ) )
98
+
99
+ const address3LowerCase = Address . fromString ( str2 . toLowerCase ( ) )
100
+ assert . ok ( address3 . equals ( address3LowerCase ) )
101
+
102
+ const address4 = Address . zero ( )
103
+ assert . ok ( ! address1 . equals ( address4 ) )
104
+ } )
87
105
} )
You can’t perform that action at this time.
0 commit comments