From 69226fc1b0393a55bf41b7dc83d37db785f57e52 Mon Sep 17 00:00:00 2001 From: Afri <58883403+q9f@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:45:20 +0100 Subject: [PATCH] eth/address: rename null address to zero address (#297) * 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 <2184696+mattrasband@users.noreply.github.com> --- lib/eth/address.rb | 12 ++++++------ spec/eth/address_spec.rb | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/eth/address.rb b/lib/eth/address.rb index 4a05d17e..7faf15cd 100644 --- a/lib/eth/address.rb +++ b/lib/eth/address.rb @@ -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 @@ -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. diff --git a/spec/eth/address_spec.rb b/spec/eth/address_spec.rb index 38cc9b1d..aff03923 100644 --- a/spec/eth/address_spec.rb +++ b/spec/eth/address_spec.rb @@ -123,8 +123,8 @@ end end - describe ".null?" do - let(:null) { Address::NULL } + describe ".zero?" do + let(:zero) { Address::ZERO } let(:addresses) do [ "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", @@ -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