Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Currency ETH Addition (#2940)

Deac Karns9427086bb5e5
diff --git a/config/currencies.yml b/config/currencies.yml
index f8dca308dd..47d31786f1 100644
--- a/config/currencies.yml
+++ b/config/currencies.yml
@@ -894,6 +894,20 @@ doge:
delimiter: ","
default_format: "%u%n"
default_precision: 8
+eth:
+ name: Ethereum
+ priority: 100
+ iso_code: ETH
+ iso_numeric: ""
+ html_code: "Ξ"
+ symbol: "Ξ"
+ minor_unit: Wei
+ minor_unit_conversion: 1000000000000000000
+ smallest_denomination: 1
+ separator: "."
+ delimiter: ","
+ default_format: "%u%n"
+ default_precision: 8
jep:
name: Jersey Pound
priority: 100
diff --git a/test/lib/money/currency_test.rb b/test/lib/money/currency_test.rb
index d4fee930e3..8e4e3b21ec 100644
--- a/test/lib/money/currency_test.rb
+++ b/test/lib/money/currency_test.rb
@@ -31,4 +31,25 @@ class Money::CurrencyTest < ActiveSupport::TestCase
test "step returns the smallest value of the currency" do
assert_equal 0.01, @currency.step
end
+
+ test "ethereum uses wei native scale" do
+ eth = Money::Currency.new(:eth)
+ assert_equal "Ethereum", eth.name
+ assert_equal "ETH", eth.iso_code
+ assert_equal "Ξ", eth.symbol
+ assert_equal "Wei", eth.minor_unit
+ assert_equal 1000000000000000000, eth.minor_unit_conversion
+ assert_equal 8, eth.default_precision
+ end
+
+ test "ethereum step represents display precision" do
+ eth = Money::Currency.new(:eth)
+ assert_equal 0.00000001, eth.step
+ end
+
+ test "ethereum conversion formula: step = 10^-default_precision" do
+ eth = Money::Currency.new(:eth)
+ expected_step = 1.0 / (10 ** eth.default_precision)
+ assert_equal expected_step, eth.step
+ end
end