Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
q9f authored Dec 17, 2024
2 parents 6169463 + 69226fc commit ea6f498
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
gem install yard
yard doc
- name: Deploy GH Pages
uses: JamesIves/github-pages-deploy-action@v4.6.1
uses: JamesIves/github-pages-deploy-action@v4.7.1
with:
branch: gh-pages
folder: doc/
2 changes: 1 addition & 1 deletion .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
env:
INFURA_TOKEN: ${{ secrets.INFURA_TOKEN }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
8 changes: 8 additions & 0 deletions lib/eth/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Eth

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

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

# 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.
#
# @return [String] prefixed hexstring representing an checksummed address.
Expand Down
24 changes: 22 additions & 2 deletions spec/eth/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
subject(:bob) { Address.new "0x7291d3cd257053bac810ee2c55fd7c154bd455af" }

it "generates functional addresses" do

# generates a functional key for alice of type Address
expect(alice).to be_an_instance_of Address
expect(bob).to be_an_instance_of Address
Expand All @@ -18,7 +17,6 @@
end

it "prefixes an unprefixed address" do

# ensure both addresses contains the 0x prefix
# alice's address was initialized without 0x
expect(alice.address).to start_with "0x"
Expand Down Expand Up @@ -125,6 +123,28 @@
end
end

describe ".zero?" do
let(:zero) { Address::ZERO }
let(:addresses) do
[
"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed",
"0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359",
"0xdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb",
"0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb",
]
end

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_zero
end
end
end

describe ".checksummed" do
let(:addresses) do
[
Expand Down

0 comments on commit ea6f498

Please sign in to comment.