Skip to content

Commit

Permalink
eth/address: rename null address to zero address (#297)
Browse files Browse the repository at this point in the history
* Adds support to check for the ethereum "null address"

* Many dreams have gone to the null address to die, this provides a
  simple check for developers to opt in to avoiding that fate.

* eth/address: rename null address to zero address

---------

Co-authored-by: Matt Rasband <[email protected]>
  • Loading branch information
q9f and mattrasband authored Dec 17, 2024
1 parent 64ddfa7 commit 69226fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/eth/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Eth

# The {Eth::Address} class to handle checksummed Ethereum addresses.
class Address
NULL = "0x0000000000000000000000000000000000000000"
ZERO = "0x0000000000000000000000000000000000000000"

# Provides a special checksum error if EIP-55 is violated.
class CheckSumError < StandardError; end
Expand Down Expand Up @@ -52,11 +52,11 @@ def valid?
end
end

# Checks that the address is the null address.
#
# @return [Boolean] true if the address is the null address.
def null?
address == NULL
# Checks that the address is the zero address.
#
# @return [Boolean] true if the address is the zero address.
def zero?
address == ZERO
end

# Generate a checksummed address.
Expand Down
10 changes: 5 additions & 5 deletions spec/eth/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
end
end

describe ".null?" do
let(:null) { Address::NULL }
describe ".zero?" do
let(:zero) { Address::ZERO }
let(:addresses) do
[
"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed",
Expand All @@ -134,13 +134,13 @@
]
end

it "returns true for the null address" do
expect(Address.new(null)).to be_null
it "returns true for the zero address" do
expect(Address.new(zero)).to be_zero
end

it "returns false for a valid address" do
addresses.each do |address|
expect(Address.new(address)).not_to be_null
expect(Address.new(address)).not_to be_zero
end
end
end
Expand Down

0 comments on commit 69226fc

Please sign in to comment.