Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Clean up untested methods #2

Merged
merged 4 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ethereum/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Ethereum
module Base

BYTE_ZERO = "\x00".freeze
UINT256_MAX = 2**256 - 1

autoload :Gas, 'ethereum/base/gas'
autoload :Secp256K1, 'ethereum/base/secp256k1'
Expand Down
37 changes: 13 additions & 24 deletions lib/ethereum/base/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ def decode_hex(s)
RLP::Utils.decode_hex s
end

def encode_rlp(b)
RLP.encode b
end

def decode_rlp(s)
RLP.decode s
end

def big_endian_to_int(s)
RLP::Sedes.big_endian_int.deserialize s.sub(/\A(\x00)+/, '')
end
Expand All @@ -45,16 +37,6 @@ def remove_0x_head(s)
s[0,2] == '0x' ? s[2..-1] : s
end

def parse_int_or_hex(s)
if s.is_a?(Numeric)
s
elsif s[0,2] == '0x'
big_endian_to_int decode_hex(normalize_hex_without_prefix(s))
else
s.to_i
end
end

def normalize_hex_without_prefix(s)
if s[0,2] == '0x'
(s.size % 2 == 1 ? '0' : '') + s[2..-1]
Expand All @@ -75,10 +57,6 @@ def hash160_hex(x)
encode_hex hash160(x)
end

def to_signed(i)
i > Constant::INT_MAX ? (i-Constant::TT256) : i
end

def ceil32(x)
x % 32 == 0 ? x : (x + 32 - x%32)
end
Expand All @@ -104,12 +82,18 @@ def int_to_addr(x)
end

def encode_int(n)
raise ArgumentError, "Integer invalid or out of range: #{n}" unless n.is_a?(Integer) && n >= 0 && n <= UINT_MAX
unless n.is_a?(Integer) && n >= 0 && n <= UINT256_MAX
raise ArgumentError, "Integer invalid or out of range: #{n}"
end

int_to_big_endian n
end

def decode_int(v)
raise ArgumentError, "No leading zero bytes allowed for integers" if v.size > 0 && (v[0] == Constant::BYTE_ZERO || v[0] == 0)
if v.size > 0 && (v[0] == BYTE_ZERO || v[0] == 0)
raise ArgumentError, "No leading zero bytes allowed for integers"
end

big_endian_to_int v
end

Expand Down Expand Up @@ -157,5 +141,10 @@ def coerce_addr_to_hex(x)
end
end

def lpad(x, symbol, l)
return x if x.size >= l
symbol * (l - x.size) + x
end

end
end
2 changes: 1 addition & 1 deletion lib/ethereum/base/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Ethereum
module Base

VERSION = "0.1.4"
VERSION = "0.1.5"

end
end
8 changes: 8 additions & 0 deletions test/base/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ def test_coerce_to_int
assert_equal 571329460454981322332848927582483177110542410654, coerce_to_int("d\x13L\x8F\x0E\xD5*\x13\xBD\n\x00\xFF\x9F\xC6\xDBn\b2\xE3\x9E")
end

def test_coerce_to_bytes
assert_equal "d\x13L\x8F\x0E\xD5*\x13\xBD\n\x00\xFF\x9F\xC6\xDBn\b2\xE3\x9E", coerce_to_bytes(571329460454981322332848927582483177110542410654)
end

def test_coerce_addr_to_hex
assert_equal "64134c8f0ed52a13bd0a00ff9fc6db6e0832e39e", coerce_addr_to_hex(571329460454981322332848927582483177110542410654)
end

end