satoshi-unit 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21ce4b46574cd86b4ae55074404fcc86531bf080
4
- data.tar.gz: 326845d9cd98aceb7089f90b4374f39352c14470
3
+ metadata.gz: e33e2b8e9fff83147605f66272e31bfa2df9bfd8
4
+ data.tar.gz: 339fe64084bf5733e5ef19f67c1f9d4d949af564
5
5
  SHA512:
6
- metadata.gz: 96a5b2b52dc6251723849f956506ac8320c3d21e6d9602c3fcba7ca449dc7afd55a6066240d27153df332067c4c5a93dc30b4f03049caade5a1af3d1f493bc60
7
- data.tar.gz: 00bf0fe857f9d729565e4832b77cf65ae622367b5675dcea9e6edcbfac5a2813b2f65c51c9ed84b7ebc45b5ea2f4e9b92d2faf04a1ea301b02dd252e9fb623b1
6
+ metadata.gz: 41a899656d58c46fcbe7f619a3db8222bab29faa58629c1a583998d91fd48fbf7364c5f837cf1601d42db35ef63cbe5bf6e3403fddd54c48cec6f52fe1e46c66
7
+ data.tar.gz: 13250853c7bc52ba439c5b397dab7ef6600a01094dbd46131b8bc962fea15d8f5a12249849e73e9ff58120b9e4258a6ab9aadd84d1a6b097558b02df519113e0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -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
@@ -6,7 +6,7 @@
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "satoshi-unit"
9
- s.version = "0.2.0"
9
+ s.version = "0.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -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
- #expect(Satoshi.new(1.00).to_btc).to eq(1)
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
- #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)
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.0
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-03-29 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler