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

Commit 93c43f7

Browse files
committed
add Address.equals(address: Address)
1 parent dd2882d commit 93c43f7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/address.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,18 @@ export class Address {
7575
return new Address(generateAddress2(from.buf, salt, initCode))
7676
}
7777

78+
/**
79+
* Is address equal to another.
80+
*/
81+
equals(address: Address): boolean {
82+
return this.buf.equals(address.buf)
83+
}
84+
7885
/**
7986
* Is address zero.
8087
*/
8188
isZero(): boolean {
82-
return this.buf.equals(Address.zero().buf)
89+
return this.equals(Address.zero())
8390
}
8491

8592
/**

test/address.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,22 @@ describe('Address', () => {
8484
addressBuf.fill(0)
8585
assert.equal(address.toString(), str)
8686
})
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+
})
87105
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy