btcruby 1.1.4 → 1.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 496c31ea05b95ca3fe1971a17eea51f43a2c00b6
4
- data.tar.gz: 6a8cbbe43cd39b004f188f32c90e6c492d7f78d2
3
+ metadata.gz: a64dd3f298bb55c7d1bc660b6318771030fa6e6f
4
+ data.tar.gz: 6f9d6e72597bc798b2f025c3003d093f972a50ff
5
5
  SHA512:
6
- metadata.gz: 5de016754bc4fdec389d62e4fbce3b3f104a00eb698fb1647c02c7531223cfb41066e3c13eb0a286cb91ba59950493af8edd9c061f427c0317cc424b699b3e43
7
- data.tar.gz: 4514a56b1c78db5e1e3beaf3fc5983b964451bf4a007adeb359d2c16b05e0e4b291ecdf06917b689446f33ec22ef5bf9a36cfd6496d2bc37a955896a01606e23
6
+ metadata.gz: 38c83c30020fdc804fcd467bf20bd241709924c7b7708e8da72202c23717e9cb59b54c9916e6d5a09902b067107ebd8d4c14fa26b854495e4f1ac34693eb8ac7
7
+ data.tar.gz: 7cbd2dc8332ae5e4756d813b207f592d541ff1d878b512bb902853b9b8fb6d626f28505cd1aea90f54706871544fcde1c45c9d1ccd81927aa85f2ff39e18e9ec
@@ -2,6 +2,13 @@
2
2
  BTCRuby Release Notes
3
3
  =====================
4
4
 
5
+ 1.1.5 (August 20, 2015)
6
+ -----------------------
7
+
8
+ * Fixed namespace issues with `BTC::Opcodes`.
9
+ * All tests are running with explicit namespaces.
10
+
11
+
5
12
  1.1.4 (August 18, 2015)
6
13
  -----------------------
7
14
 
@@ -15,6 +15,7 @@ require_relative 'btcruby/big_number.rb'
15
15
  require_relative 'btcruby/base58.rb'
16
16
 
17
17
  require_relative 'btcruby/constants.rb'
18
+ require_relative 'btcruby/script/opcode.rb'
18
19
  require_relative 'btcruby/currency_formatter.rb'
19
20
  require_relative 'btcruby/network.rb'
20
21
  require_relative 'btcruby/address.rb'
@@ -35,7 +36,6 @@ require_relative 'btcruby/script/script_number.rb'
35
36
  require_relative 'btcruby/script/script_chunk.rb'
36
37
  require_relative 'btcruby/script/script.rb'
37
38
  require_relative 'btcruby/script/script_interpreter.rb'
38
- require_relative 'btcruby/script/opcode.rb'
39
39
  require_relative 'btcruby/script/signature_hashtype.rb'
40
40
  require_relative 'btcruby/script/signature_checker.rb'
41
41
  require_relative 'btcruby/script/test_signature_checker.rb'
@@ -27,6 +27,7 @@
27
27
  #
28
28
  module BTC
29
29
  class Address
30
+ include Opcodes
30
31
  @@registered_classes = []
31
32
 
32
33
  # Decodes address from a Base58Check-encoded string
@@ -1,5 +1,6 @@
1
1
  module BTC
2
2
  class AssetMarker
3
+ include Opcodes
3
4
 
4
5
  MAGIC = "\x4f\x41".freeze
5
6
  VERSION1 = "\x01\x00".freeze
@@ -201,5 +201,8 @@ module BTC
201
201
 
202
202
  # Make all opcodes available as BTC::OP_...
203
203
  include Opcodes
204
+ module Opcode
205
+ include Opcodes
206
+ end
204
207
  end
205
208
 
@@ -1,6 +1,7 @@
1
1
  module BTC
2
2
  class Script
3
-
3
+ include Opcodes
4
+
4
5
  # Serialized binary form of the script (payload)
5
6
  attr_reader :data
6
7
 
@@ -1,6 +1,7 @@
1
1
  module BTC
2
2
  # ScriptChunk represents either an opcode or a pushdata command.
3
3
  class ScriptChunk
4
+ include Opcodes
4
5
  # Raw data for this chunk.
5
6
  # 1 byte for regular opcode, 1 or more bytes for pushdata command.
6
7
  # We do not call it 'data' to avoid confusion with `pushdata` (see below).
@@ -1,47 +1,51 @@
1
1
  module BTC
2
- SCRIPT_ERR_OK = 0
3
- SCRIPT_ERR_UNKNOWN_ERROR = 1
4
- SCRIPT_ERR_EVAL_FALSE = 2
5
- SCRIPT_ERR_OP_RETURN = 3
2
+ module ScriptErrors
3
+ SCRIPT_ERR_OK = 0
4
+ SCRIPT_ERR_UNKNOWN_ERROR = 1
5
+ SCRIPT_ERR_EVAL_FALSE = 2
6
+ SCRIPT_ERR_OP_RETURN = 3
6
7
 
7
- # Max sizes
8
- SCRIPT_ERR_SCRIPT_SIZE = 4
9
- SCRIPT_ERR_PUSH_SIZE = 5
10
- SCRIPT_ERR_OP_COUNT = 6
11
- SCRIPT_ERR_STACK_SIZE = 7
12
- SCRIPT_ERR_SIG_COUNT = 8
13
- SCRIPT_ERR_PUBKEY_COUNT = 9
8
+ # Max sizes
9
+ SCRIPT_ERR_SCRIPT_SIZE = 4
10
+ SCRIPT_ERR_PUSH_SIZE = 5
11
+ SCRIPT_ERR_OP_COUNT = 6
12
+ SCRIPT_ERR_STACK_SIZE = 7
13
+ SCRIPT_ERR_SIG_COUNT = 8
14
+ SCRIPT_ERR_PUBKEY_COUNT = 9
14
15
 
15
- # Failed verify operations
16
- SCRIPT_ERR_VERIFY = 10
17
- SCRIPT_ERR_EQUALVERIFY = 11
18
- SCRIPT_ERR_CHECKMULTISIGVERIFY = 12
19
- SCRIPT_ERR_CHECKSIGVERIFY = 13
20
- SCRIPT_ERR_NUMEQUALVERIFY = 14
16
+ # Failed verify operations
17
+ SCRIPT_ERR_VERIFY = 10
18
+ SCRIPT_ERR_EQUALVERIFY = 11
19
+ SCRIPT_ERR_CHECKMULTISIGVERIFY = 12
20
+ SCRIPT_ERR_CHECKSIGVERIFY = 13
21
+ SCRIPT_ERR_NUMEQUALVERIFY = 14
21
22
 
22
- # Logical/Format/Canonical errors
23
- SCRIPT_ERR_BAD_OPCODE = 15
24
- SCRIPT_ERR_DISABLED_OPCODE = 16
25
- SCRIPT_ERR_INVALID_STACK_OPERATION = 17
26
- SCRIPT_ERR_INVALID_ALTSTACK_OPERATION = 18
27
- SCRIPT_ERR_UNBALANCED_CONDITIONAL = 19
23
+ # Logical/Format/Canonical errors
24
+ SCRIPT_ERR_BAD_OPCODE = 15
25
+ SCRIPT_ERR_DISABLED_OPCODE = 16
26
+ SCRIPT_ERR_INVALID_STACK_OPERATION = 17
27
+ SCRIPT_ERR_INVALID_ALTSTACK_OPERATION = 18
28
+ SCRIPT_ERR_UNBALANCED_CONDITIONAL = 19
28
29
 
29
- # OP_CHECKLOCKTIMEVERIFY
30
- SCRIPT_ERR_NEGATIVE_LOCKTIME = 20
31
- SCRIPT_ERR_UNSATISFIED_LOCKTIME = 21
30
+ # OP_CHECKLOCKTIMEVERIFY
31
+ SCRIPT_ERR_NEGATIVE_LOCKTIME = 20
32
+ SCRIPT_ERR_UNSATISFIED_LOCKTIME = 21
32
33
 
33
- # BIP62
34
- SCRIPT_ERR_SIG_HASHTYPE = 22
35
- SCRIPT_ERR_SIG_DER = 23
36
- SCRIPT_ERR_MINIMALDATA = 24
37
- SCRIPT_ERR_SIG_PUSHONLY = 25
38
- SCRIPT_ERR_SIG_HIGH_S = 26
39
- SCRIPT_ERR_SIG_NULLDUMMY = 27
40
- SCRIPT_ERR_PUBKEYTYPE = 28
41
- SCRIPT_ERR_CLEANSTACK = 29
34
+ # BIP62
35
+ SCRIPT_ERR_SIG_HASHTYPE = 22
36
+ SCRIPT_ERR_SIG_DER = 23
37
+ SCRIPT_ERR_MINIMALDATA = 24
38
+ SCRIPT_ERR_SIG_PUSHONLY = 25
39
+ SCRIPT_ERR_SIG_HIGH_S = 26
40
+ SCRIPT_ERR_SIG_NULLDUMMY = 27
41
+ SCRIPT_ERR_PUBKEYTYPE = 28
42
+ SCRIPT_ERR_CLEANSTACK = 29
42
43
 
43
- # softfork safeness
44
- SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS = 30
44
+ # softfork safeness
45
+ SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS = 30
46
+ end
47
+
48
+ include ScriptErrors
45
49
 
46
50
  class ScriptError
47
51
  attr_reader :code
@@ -12,6 +12,8 @@ module BTC
12
12
  # returning a bool indicating valid or not. There are no loops.
13
13
  class ScriptInterpreter
14
14
  include ScriptFlags
15
+ include ScriptErrors
16
+ include Opcodes
15
17
 
16
18
  # Flags specified for this interpreter, not including flags added by plugins.
17
19
  attr_accessor :flags
@@ -9,6 +9,8 @@ module BTC
9
9
  # - hook for handling the opcodes
10
10
  module ScriptInterpreterPlugin
11
11
  include ScriptFlags
12
+ include ScriptErrors
13
+ include Opcodes
12
14
 
13
15
  # Returns additional flags to be available to #flag? checks during script execution.
14
16
  # This way one plugin can affect evaluation of another.
@@ -14,6 +14,7 @@ module BTC
14
14
 
15
15
  # TransactionBuilder composes and optionally sings a transaction.
16
16
  class TransactionBuilder
17
+ include Opcodes
17
18
 
18
19
  # Network to validate provided addresses against.
19
20
  # Default value is `Network.default`.
@@ -1,3 +1,3 @@
1
1
  module BTC
2
- VERSION = "1.1.4".freeze
2
+ VERSION = "1.1.5".freeze
3
3
  end
@@ -32,7 +32,7 @@ describe BTC::Address do
32
32
 
33
33
  address.data.must_equal "243f1394f44554f4ce3fd68649c19adc483ce924".from_hex
34
34
 
35
- address2 = BTC::PublicKeyAddress.new(hash: "243f1394f44554f4ce3fd68649c19adc483ce924".from_hex, network: Network.testnet)
35
+ address2 = BTC::PublicKeyAddress.new(hash: "243f1394f44554f4ce3fd68649c19adc483ce924".from_hex, network: BTC::Network.testnet)
36
36
 
37
37
  address2.to_s.must_equal("mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn")
38
38
  address2.data.must_equal("243f1394f44554f4ce3fd68649c19adc483ce924".from_hex)
@@ -40,13 +40,13 @@ describe BTC::Address do
40
40
 
41
41
  it "should detect invalid pay-to-pubkey-hash address" do
42
42
  lambda { BTC::Address.parse(nil) }.must_raise ArgumentError
43
- lambda { BTC::Address.parse("") }.must_raise FormatError
44
- lambda { BTC::Address.parse("18FGfswVqxNubJbh1NW8A4t51T9x9RDVWQ") }.must_raise FormatError
45
- lambda { BTC::Address.parse("19FGfswVqxNubJbh1NW8A4t51T9x9RDvwq") }.must_raise FormatError
46
- lambda { BTC::Address.parse("19FGfswVqxNubJbh1NW8A4t51T9x9RD") }.must_raise FormatError
47
- lambda { BTC::Address.parse("mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRf") }.must_raise FormatError
48
- lambda { BTC::Address.parse("m") }.must_raise FormatError
49
- lambda { BTC::Address.parse("mipc") }.must_raise FormatError
43
+ lambda { BTC::Address.parse("") }.must_raise BTC::FormatError
44
+ lambda { BTC::Address.parse("18FGfswVqxNubJbh1NW8A4t51T9x9RDVWQ") }.must_raise BTC::FormatError
45
+ lambda { BTC::Address.parse("19FGfswVqxNubJbh1NW8A4t51T9x9RDvwq") }.must_raise BTC::FormatError
46
+ lambda { BTC::Address.parse("19FGfswVqxNubJbh1NW8A4t51T9x9RD") }.must_raise BTC::FormatError
47
+ lambda { BTC::Address.parse("mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRf") }.must_raise BTC::FormatError
48
+ lambda { BTC::Address.parse("m") }.must_raise BTC::FormatError
49
+ lambda { BTC::Address.parse("mipc") }.must_raise BTC::FormatError
50
50
  end
51
51
 
52
52
  it "should decode/encode mainnet pay-to-script-hash address" do
@@ -89,12 +89,12 @@ describe BTC::Address do
89
89
  end
90
90
 
91
91
  it "should detect invalid pay-to-script-hash address" do
92
- lambda { BTC::Address.parse("3ektnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX") }.must_raise FormatError
93
- lambda { BTC::Address.parse("3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzqX") }.must_raise FormatError
94
- lambda { BTC::Address.parse("3EktnHQD7RiAE6uzMj2ZifT9YgRrkSg") }.must_raise FormatError
95
- lambda { BTC::Address.parse("2mzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc") }.must_raise FormatError
96
- lambda { BTC::Address.parse("2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1vc") }.must_raise FormatError
97
- lambda { BTC::Address.parse("2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJ") }.must_raise FormatError
92
+ lambda { BTC::Address.parse("3ektnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX") }.must_raise BTC::FormatError
93
+ lambda { BTC::Address.parse("3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzqX") }.must_raise BTC::FormatError
94
+ lambda { BTC::Address.parse("3EktnHQD7RiAE6uzMj2ZifT9YgRrkSg") }.must_raise BTC::FormatError
95
+ lambda { BTC::Address.parse("2mzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc") }.must_raise BTC::FormatError
96
+ lambda { BTC::Address.parse("2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1vc") }.must_raise BTC::FormatError
97
+ lambda { BTC::Address.parse("2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJ") }.must_raise BTC::FormatError
98
98
  end
99
99
 
100
100
 
@@ -139,12 +139,12 @@ describe BTC::Address do
139
139
  end
140
140
 
141
141
  it "should detect invalid private key address" do
142
- lambda { BTC::Address.parse("5kJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hS") }.must_raise FormatError
143
- lambda { BTC::Address.parse("5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hs") }.must_raise FormatError
144
- lambda { BTC::Address.parse("5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZ") }.must_raise FormatError
145
- lambda { BTC::Address.parse("L3P8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJF9woSu") }.must_raise FormatError
146
- lambda { BTC::Address.parse("L3p8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJF9woSU") }.must_raise FormatError
147
- lambda { BTC::Address.parse("L3p8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJ") }.must_raise FormatError
142
+ lambda { BTC::Address.parse("5kJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hS") }.must_raise BTC::FormatError
143
+ lambda { BTC::Address.parse("5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hs") }.must_raise BTC::FormatError
144
+ lambda { BTC::Address.parse("5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZ") }.must_raise BTC::FormatError
145
+ lambda { BTC::Address.parse("L3P8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJF9woSu") }.must_raise BTC::FormatError
146
+ lambda { BTC::Address.parse("L3p8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJF9woSU") }.must_raise BTC::FormatError
147
+ lambda { BTC::Address.parse("L3p8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJ") }.must_raise BTC::FormatError
148
148
  end
149
149
 
150
150
  it "should convert strings and addresses into normalized address" do
@@ -191,8 +191,8 @@ describe BTC::Address do
191
191
  it "should detect if wrong subclass is used when parsing an address" do
192
192
  btc_addr_string = "19FGfswVqxNubJbh1NW8A4t51T9x9RDVWQ"
193
193
  asset_addr_string = "akB4NBW9UuCmHuepksob6yfZs6naHtRCPNy"
194
- btc_addr = Address.parse(btc_addr_string)
195
- asset_addr = Address.parse(asset_addr_string)
194
+ btc_addr = BTC::Address.parse(btc_addr_string)
195
+ asset_addr = BTC::Address.parse(asset_addr_string)
196
196
 
197
197
  ->{ BTC::AssetAddress.parse(btc_addr_string) }.must_raise ArgumentError
198
198
  ->{ BTC::AssetAddress.parse(btc_addr) }.must_raise ArgumentError
@@ -2,34 +2,34 @@ require_relative 'spec_helper'
2
2
  describe BTC::Base58 do
3
3
 
4
4
  def check_invalid_base58(base58_string, expected_class = BTC::FormatError)
5
- lambda { Base58.data_from_base58(base58_string) }.must_raise expected_class
5
+ lambda { BTC::Base58.data_from_base58(base58_string) }.must_raise expected_class
6
6
  end
7
7
 
8
8
  def check_invalid_base58check(base58check_string, expected_class = BTC::FormatError)
9
- lambda { Base58.data_from_base58check(base58check_string) }.must_raise expected_class
9
+ lambda { BTC::Base58.data_from_base58check(base58check_string) }.must_raise expected_class
10
10
  end
11
11
 
12
12
  def check_valid_base58(hex_string, base58_string)
13
13
  # Convert to Base58
14
- Base58.base58_from_data(BTC.from_hex(hex_string)).must_equal(base58_string)
14
+ BTC::Base58.base58_from_data(BTC.from_hex(hex_string)).must_equal(base58_string)
15
15
 
16
16
  # Convert from Base58
17
- BTC.to_hex(Base58.data_from_base58(base58_string)).must_equal(hex_string)
17
+ BTC.to_hex(BTC::Base58.data_from_base58(base58_string)).must_equal(hex_string)
18
18
  end
19
19
 
20
20
  def check_valid_base58check(hex, string)
21
21
  # Convert to Base58Check
22
- Base58.base58check_from_data(BTC.from_hex(hex)).must_equal(string)
22
+ BTC::Base58.base58check_from_data(BTC.from_hex(hex)).must_equal(string)
23
23
 
24
24
  # Convert from Base58Check
25
- BTC.to_hex(Base58.data_from_base58check(string)).must_equal(hex)
25
+ BTC.to_hex(BTC::Base58.data_from_base58check(string)).must_equal(hex)
26
26
  end
27
27
 
28
28
  describe "Base58" do
29
29
  it "should handle valid input" do
30
30
 
31
- lambda { Base58.data_from_base58(nil) }.must_raise ArgumentError
32
- lambda { Base58.base58_from_data(nil) }.must_raise ArgumentError
31
+ lambda { BTC::Base58.data_from_base58(nil) }.must_raise ArgumentError
32
+ lambda { BTC::Base58.base58_from_data(nil) }.must_raise ArgumentError
33
33
  check_valid_base58("", "")
34
34
  check_valid_base58("13", "L")
35
35
  check_valid_base58("2e", "o")
@@ -3,15 +3,15 @@ describe BTC::BlockHeader do
3
3
 
4
4
  describe "Genesis Mainnet" do
5
5
  it "should have a correct hash" do
6
- BlockHeader.genesis_mainnet.block_id.must_equal "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
7
- BlockHeader.genesis_mainnet.height.must_equal 0
6
+ BTC::BlockHeader.genesis_mainnet.block_id.must_equal "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
7
+ BTC::BlockHeader.genesis_mainnet.height.must_equal 0
8
8
  end
9
9
  end
10
10
 
11
11
  describe "Genesis Testnet" do
12
12
  it "should have a correct hash" do
13
- BlockHeader.genesis_testnet.block_id.must_equal "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
14
- BlockHeader.genesis_testnet.height.must_equal 0
13
+ BTC::BlockHeader.genesis_testnet.block_id.must_equal "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
14
+ BTC::BlockHeader.genesis_testnet.height.must_equal 0
15
15
  end
16
16
  end
17
17
 
@@ -3,15 +3,15 @@ describe BTC::Block do
3
3
 
4
4
  describe "Genesis Mainnet" do
5
5
  it "should have a correct hash" do
6
- Block.genesis_mainnet.block_id.must_equal "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
7
- Block.genesis_mainnet.height.must_equal 0
6
+ BTC::Block.genesis_mainnet.block_id.must_equal "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
7
+ BTC::Block.genesis_mainnet.height.must_equal 0
8
8
  end
9
9
  end
10
10
 
11
11
  describe "Genesis Testnet" do
12
12
  it "should have a correct hash" do
13
- Block.genesis_testnet.block_id.must_equal "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
14
- Block.genesis_testnet.height.must_equal 0
13
+ BTC::Block.genesis_testnet.block_id.must_equal "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
14
+ BTC::Block.genesis_testnet.height.must_equal 0
15
15
  end
16
16
  end
17
17
 
@@ -5,42 +5,42 @@ describe BTC::CurrencyFormatter do
5
5
  it "should support normal bitcoin formatting" do
6
6
  fm = BTC::CurrencyFormatter.btc_formatter
7
7
 
8
- fm.string_from_number(1*COIN).must_equal("1.0")
9
- fm.string_from_number(42*COIN).must_equal("42.0")
10
- fm.string_from_number(42000*COIN).must_equal("42000.0")
11
- fm.string_from_number(42000*COIN + 123).must_equal("42000.00000123")
12
- fm.string_from_number(42000*COIN + 123000).must_equal("42000.00123")
13
- fm.string_from_number(42000*COIN + 123456).must_equal("42000.00123456")
14
- fm.string_from_number(42000*COIN + COIN/2).must_equal("42000.5")
8
+ fm.string_from_number(1*BTC::COIN).must_equal("1.0")
9
+ fm.string_from_number(42*BTC::COIN).must_equal("42.0")
10
+ fm.string_from_number(42000*BTC::COIN).must_equal("42000.0")
11
+ fm.string_from_number(42000*BTC::COIN + 123).must_equal("42000.00000123")
12
+ fm.string_from_number(42000*BTC::COIN + 123000).must_equal("42000.00123")
13
+ fm.string_from_number(42000*BTC::COIN + 123456).must_equal("42000.00123456")
14
+ fm.string_from_number(42000*BTC::COIN + BTC::COIN/2).must_equal("42000.5")
15
15
 
16
- fm.number_from_string("1").must_equal 1*COIN
17
- fm.number_from_string("1.").must_equal 1*COIN
18
- fm.number_from_string("1.0").must_equal 1*COIN
19
- fm.number_from_string("42").must_equal 42*COIN
20
- fm.number_from_string("42.123").must_equal 42*COIN + 12300000
21
- fm.number_from_string("42.12345678").must_equal 42*COIN + 12345678
22
- fm.number_from_string("42.10000000").must_equal 42*COIN + 10000000
23
- fm.number_from_string("42.10000").must_equal 42*COIN + 10000000
16
+ fm.number_from_string("1").must_equal 1*BTC::COIN
17
+ fm.number_from_string("1.").must_equal 1*BTC::COIN
18
+ fm.number_from_string("1.0").must_equal 1*BTC::COIN
19
+ fm.number_from_string("42").must_equal 42*BTC::COIN
20
+ fm.number_from_string("42.123").must_equal 42*BTC::COIN + 12300000
21
+ fm.number_from_string("42.12345678").must_equal 42*BTC::COIN + 12345678
22
+ fm.number_from_string("42.10000000").must_equal 42*BTC::COIN + 10000000
23
+ fm.number_from_string("42.10000").must_equal 42*BTC::COIN + 10000000
24
24
  end
25
25
 
26
26
  it "should support long bitcoin formatting" do
27
27
  fm = BTC::CurrencyFormatter.btc_long_formatter
28
28
 
29
- fm.string_from_number(1*COIN).must_equal("1.00000000")
30
- fm.string_from_number(42*COIN).must_equal("42.00000000")
31
- fm.string_from_number(42000*COIN).must_equal("42000.00000000")
32
- fm.string_from_number(42000*COIN + 123).must_equal("42000.00000123")
33
- fm.string_from_number(42000*COIN + 123000).must_equal("42000.00123000")
34
- fm.string_from_number(42000*COIN + 123456).must_equal("42000.00123456")
35
- fm.string_from_number(42000*COIN + COIN/2).must_equal("42000.50000000")
29
+ fm.string_from_number(1*BTC::COIN).must_equal("1.00000000")
30
+ fm.string_from_number(42*BTC::COIN).must_equal("42.00000000")
31
+ fm.string_from_number(42000*BTC::COIN).must_equal("42000.00000000")
32
+ fm.string_from_number(42000*BTC::COIN + 123).must_equal("42000.00000123")
33
+ fm.string_from_number(42000*BTC::COIN + 123000).must_equal("42000.00123000")
34
+ fm.string_from_number(42000*BTC::COIN + 123456).must_equal("42000.00123456")
35
+ fm.string_from_number(42000*BTC::COIN + BTC::COIN/2).must_equal("42000.50000000")
36
36
 
37
- fm.number_from_string("1").must_equal 1*COIN
38
- fm.number_from_string("1.").must_equal 1*COIN
39
- fm.number_from_string("1.0").must_equal 1*COIN
40
- fm.number_from_string("42").must_equal 42*COIN
41
- fm.number_from_string("42.123").must_equal 42*COIN + 12300000
42
- fm.number_from_string("42.12345678").must_equal 42*COIN + 12345678
43
- fm.number_from_string("42.10000000").must_equal 42*COIN + 10000000
44
- fm.number_from_string("42.10000").must_equal 42*COIN + 10000000
37
+ fm.number_from_string("1").must_equal 1*BTC::COIN
38
+ fm.number_from_string("1.").must_equal 1*BTC::COIN
39
+ fm.number_from_string("1.0").must_equal 1*BTC::COIN
40
+ fm.number_from_string("42").must_equal 42*BTC::COIN
41
+ fm.number_from_string("42.123").must_equal 42*BTC::COIN + 12300000
42
+ fm.number_from_string("42.12345678").must_equal 42*BTC::COIN + 12345678
43
+ fm.number_from_string("42.10000000").must_equal 42*BTC::COIN + 10000000
44
+ fm.number_from_string("42.10000").must_equal 42*BTC::COIN + 10000000
45
45
  end
46
46
  end