satoshi-unit 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/satoshi.rb +6 -0
- data/satoshi-unit.gemspec +1 -1
- data/spec/satoshi_spec.rb +11 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e33e2b8e9fff83147605f66272e31bfa2df9bfd8
|
4
|
+
data.tar.gz: 339fe64084bf5733e5ef19f67c1f9d4d949af564
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41a899656d58c46fcbe7f619a3db8222bab29faa58629c1a583998d91fd48fbf7364c5f837cf1601d42db35ef63cbe5bf6e3403fddd54c48cec6f52fe1e46c66
|
7
|
+
data.tar.gz: 13250853c7bc52ba439c5b397dab7ef6600a01094dbd46131b8bc962fea15d8f5a12249849e73e9ff58120b9e4258a6ab9aadd84d1a6b097558b02df519113e0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/satoshi.rb
CHANGED
@@ -9,6 +9,7 @@ class Satoshi
|
|
9
9
|
}
|
10
10
|
|
11
11
|
class TooManyDigitsAfterDecimalPoint < Exception;end
|
12
|
+
class TooLarge < Exception;end
|
12
13
|
|
13
14
|
attr_reader :value, :from_unit, :to_unit
|
14
15
|
|
@@ -137,6 +138,11 @@ class Satoshi
|
|
137
138
|
n = n.split('.')
|
138
139
|
n[1] ||= '' # in the case where there's no decimal part
|
139
140
|
n[1] += "0"*(UNIT_DENOMINATIONS[@from_unit]-n[1].length) if n[1]
|
141
|
+
|
142
|
+
if(n.join.to_i > 21_000_000_00000000)
|
143
|
+
raise TooLarge, "Max value for Bitcoin is 21 million BTC"
|
144
|
+
end
|
145
|
+
|
140
146
|
n.join.to_i
|
141
147
|
|
142
148
|
end
|
data/satoshi-unit.gemspec
CHANGED
data/spec/satoshi_spec.rb
CHANGED
@@ -11,12 +11,12 @@ describe Satoshi do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "converts satoshi unit back to some more common denomination" do
|
14
|
-
|
14
|
+
expect(Satoshi.new(1.00).to_btc).to eq(1)
|
15
15
|
expect(Satoshi.new(1.08763).to_btc).to eq(1.08763)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
expect(Satoshi.new(1.08763).to_mbtc).to eq(1087.63)
|
17
|
+
expect(Satoshi.new(-1.08763).to_mbtc).to eq(-1087.63)
|
18
|
+
expect(Satoshi.new(0.00000001).to_i).to eq(1)
|
19
|
+
expect(Satoshi.new(0.00000001).to_mbtc).to eq(0.00001)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "converts from various source denominations" do
|
@@ -68,6 +68,12 @@ describe Satoshi do
|
|
68
68
|
expect( -> { Satoshi.new(0.00100099, from_unit: :btc).to_unit }).not_to raise_exception
|
69
69
|
expect( -> { Satoshi.new(0.123456789, from_unit: :btc) }).to raise_exception(Satoshi::TooManyDigitsAfterDecimalPoint)
|
70
70
|
expect( -> { Satoshi.new(0.12345678, from_unit: :btc).to_unit }).not_to raise_exception
|
71
|
+
expect( -> { Satoshi.new(nil, from_unit: :btc).to_unit }).not_to raise_exception
|
72
|
+
end
|
73
|
+
|
74
|
+
it "disallows to create values more than 21mil BTC" do
|
75
|
+
expect( -> { Satoshi.new(21_000_001) }).to raise_exception(Satoshi::TooLarge)
|
76
|
+
expect( -> { Satoshi.new(21_000_000) }).not_to raise_exception
|
71
77
|
end
|
72
78
|
|
73
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: satoshi-unit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Snitko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|