blockchain 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,97 @@
1
+ require 'blockchain'
2
+ require_relative '../lib/blockchain/blockexplorer'
3
+ require 'test/unit'
4
+
5
+ class TestBlockExplorer < Test::Unit::TestCase
6
+
7
+ def test_get_block_bad_hash_api_exception
8
+ assert_raise( Blockchain::Client::APIException ) { Blockchain::BlockExplorer.new.get_block_by_hash("a") }
9
+ end
10
+
11
+ def test_get_block_correct_hash_no_exception
12
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_block_by_hash("0000000000000000019336c7ada4df81cfa3fb22e1851b3964cf65e3da1afe27") end
13
+ end
14
+
15
+ def test_get_tx_bad_has_api_exception
16
+ assert_raise( Blockchain::Client::APIException ) { Blockchain::BlockExplorer.new.get_tx_by_hash("a") }
17
+ end
18
+
19
+ def test_get_tx_correct_hash_no_exception
20
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_tx_by_hash("4ff162eceb4392a38f269aab1ee1df567ae06875042b3ab6b53bd334c2e9e888") end
21
+ end
22
+
23
+ def test_get_block_height_bad_argument_exception
24
+ assert_raise do Blockchain::BlockExplorer.new.get_block_height(-1) end
25
+ end
26
+
27
+ def test_get_block_height_correct_argument_no_exception
28
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_block_height(1000) end
29
+ end
30
+
31
+ def test_get_address_by_hash160_bad_hash_api_exception
32
+ assert_raise Blockchain::Client::APIException do Blockchain::BlockExplorer.new.get_address_by_hash160("buns") end
33
+ end
34
+
35
+ def test_get_address_by_hash160_correct_hash_no_exception
36
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_address_by_hash160("1d6fdd6a2002594cfd6aad36ba635a303a23d795") end
37
+ end
38
+
39
+ def test_get_address_base58_bad_hash_api_exception
40
+ assert_raise Blockchain::Client::APIException do Blockchain::BlockExplorer.new.get_address_by_base58("buns") end
41
+ end
42
+
43
+ def test_get_address_base58_correct_hash_no_exception
44
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_address_by_base58("13gec5DMEG3eW4CcEqLB2fBLPwZUwJqeC9") end
45
+ end
46
+
47
+ def test_get_xpub_bad_xpub_api_exception
48
+ assert_raise Blockchain::Client::APIException do Blockchain::BlockExplorer.new.get_xpub('buns') end
49
+ end
50
+
51
+ def test_get_xpub_correct_xpub_no_exception
52
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_xpub("xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn") end
53
+ end
54
+
55
+ def test_get_xpub_correct_xpub_not_nil
56
+ assert_not_nil Blockchain::BlockExplorer.new.get_xpub("xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn").address
57
+ end
58
+
59
+ def test_get_multi_address_bad_address_api_exception
60
+ assert_raise Blockchain::Client::APIException do Blockchain::BlockExplorer.new.get_multi_address(['buns']) end
61
+ end
62
+
63
+ def test_get_multi_address_correct_address_no_excpetion
64
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_multi_address(['13gec5DMEG3eW4CcEqLB2fBLPwZUwJqeC9',
65
+ 'xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn']) end
66
+ end
67
+
68
+ def test_get_unspent_outputs_bad_address_api_exception
69
+ assert_raise Blockchain::Client::APIException do Blockchain::BlockExplorer.new.get_unspent_outputs(['buns']) end
70
+ end
71
+
72
+ def test_get_unspent_outputs_correct_address_no_excpetion
73
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_unspent_outputs(['13gec5DMEG3eW4CcEqLB2fBLPwZUwJqeC9',
74
+ 'xpub6CmZamQcHw2TPtbGmJNEvRgfhLwitarvzFn3fBYEEkFTqztus7W7CNbf48Kxuj1bRRBmZPzQocB6qar9ay6buVkQk73ftKE1z4tt9cPHWRn']) end
75
+ end
76
+
77
+ def test_get_latest_block_not_nil
78
+ assert_not_nil Blockchain::BlockExplorer.new.get_latest_block
79
+ end
80
+
81
+ def test_get_unconfirmed_tx_not_nil
82
+ assert_not_nil Blockchain::BlockExplorer.new.get_unconfirmed_tx
83
+ end
84
+
85
+ def test_get_blocks_bad_time_api_exception
86
+ assert_raise Blockchain::Client::APIException do Blockchain::BlockExplorer.new.get_blocks(time = -1) end
87
+ end
88
+
89
+ def test_get_blocks_bad_poolname_api_exception
90
+ assert_raise Blockchain::Client::APIException do Blockchain::BlockExplorer.new.get_blocks(pool_name = 'wombat') end
91
+ end
92
+
93
+ def test_get_blocks_correct_params_no_exception
94
+ assert_nothing_raised do Blockchain::BlockExplorer.new.get_blocks(1493052735, 'BTCC Pool') end
95
+ end
96
+
97
+ end
@@ -0,0 +1,31 @@
1
+ require 'Blockchain'
2
+ require_relative '../lib/blockchain/exchangerates'
3
+ require 'test/unit'
4
+
5
+ class TestExchangeRates < Test::Unit::TestCase
6
+
7
+ def test_get_ticker_not_nil
8
+ assert_not_nil Blockchain::ExchangeRateExplorer.new.get_ticker
9
+ end
10
+
11
+ def test_to_btc_invalid_ccy_api_exception
12
+ assert_raise Blockchain::Client::APIException do Blockchain::ExchangeRateExplorer.new.to_btc('mau', 300) end
13
+ end
14
+
15
+ def test_to_btc_invalid_value_api_exception
16
+ assert_raise Blockchain::Client::APIException do Blockchain::ExchangeRateExplorer.new.to_btc('USD', 'aaa') end
17
+ end
18
+
19
+ def test_to_btc_valid_args_no_exception
20
+ assert_nothing_raised do Blockchain::ExchangeRateExplorer.new.to_btc('USD', 500) end
21
+ end
22
+
23
+ def test_from_btc_invalid_value_api_exception
24
+ assert_raise Blockchain::Client::APIException do Blockchain::ExchangeRateExplorer.new.from_btc('GBP', 'cook') end
25
+ end
26
+
27
+ def test_from_btc_valid_args_no_exception
28
+ assert_nothing_raised do Blockchain::ExchangeRateExplorer.new.from_btc('GBP', 100000000) end
29
+ end
30
+
31
+ end
@@ -0,0 +1,11 @@
1
+ require 'Blockchain'
2
+ require_relative '../lib/blockchain/pushtx'
3
+ require 'test/unit'
4
+
5
+ class TestPushTx < Test::Unit::TestCase
6
+
7
+ def test_push_tx_nil_param_api_exception
8
+ assert_raise Blockchain::Client::APIException do Blockchain::PushTx.new.pushtx(nil) end
9
+ end
10
+
11
+ end
@@ -0,0 +1,35 @@
1
+ require 'Blockchain'
2
+ require_relative '../lib/blockchain/statistics'
3
+ require 'test/unit'
4
+
5
+ class TestStatistics < Test::Unit::TestCase
6
+
7
+ def test_get_stats_not_nil
8
+ assert_not_nil Blockchain::StatisticsExplorer.new.get_statistics
9
+ end
10
+
11
+ def test_get_chart_wrong_name_api_exception
12
+ assert_raise Blockchain::Client::APIException do Blockchain::StatisticsExplorer.new.get_chart('bomba') end
13
+ end
14
+
15
+ def test_get_chart_invalid_timespan_api_exception
16
+ assert_raise Blockchain::Client::APIException do Blockchain::StatisticsExplorer.new.get_chart('transactions-per-second', 'dongledays') end
17
+ end
18
+
19
+ def test_get_chart_invalid_rolling_avg_api_exception
20
+ assert_raise Blockchain::Client::APIException do Blockchain::StatisticsExplorer.new.get_chart('transactions-per-second', rolling_average = 'dongledays') end
21
+ end
22
+
23
+ def test_get_chart_valid_params_no_exception
24
+ assert_nothing_raised do Blockchain::StatisticsExplorer.new.get_chart('transactions-per-second', '5weeks', '8hours') end
25
+ end
26
+
27
+ def test_get_pools_invalid_timespan_argument_error
28
+ assert_raise ArgumentError do Blockchain::StatisticsExplorer.new.get_pools(11) end
29
+ end
30
+
31
+ def test_get_pools_valid_params_no_exception
32
+ assert_nothing_raised do Blockchain::StatisticsExplorer.new.get_pools end
33
+ end
34
+
35
+ end
@@ -0,0 +1,44 @@
1
+ require 'blockchain'
2
+ require_relative '../lib/blockchain/wallet'
3
+ require_relative '../lib/blockchain/createwallet'
4
+ require 'test/unit'
5
+
6
+ # Local waller service must be running for carrying out these tests
7
+
8
+ class TestWallet < Test::Unit::TestCase
9
+
10
+ def test_get_balance_not_nil
11
+ assert_nothing_raised do Blockchain::Wallet.new('773d4edb-bffe-4790-8712-8d232ce04b0c', 'Password1!', 'http://localhost:3000/', 'Password2!').get_balance end
12
+ end
13
+
14
+ def test_list_addresses_not_nil
15
+ assert_not_nil Blockchain::Wallet.new('773d4edb-bffe-4790-8712-8d232ce04b0c', 'Password1!', 'http://localhost:3000/', 'Password2!').list_addresses
16
+ end
17
+
18
+ def test_get_address_invalid_address_api_exception
19
+ assert_raise Blockchain::Client::APIException do puts Blockchain::Wallet.new('773d4edb-bffe-4790-8712-8d232ce04b0c', 'Password1!', 'http://localhost:3000/', 'Password2!').get_address('booboo').address end
20
+ end
21
+
22
+ def test_get_address_valid_address_no_exception
23
+ wallet = Blockchain::Wallet.new('773d4edb-bffe-4790-8712-8d232ce04b0c', 'Password1!', 'http://localhost:3000/', 'Password2!')
24
+ addr = wallet.list_addresses[1]
25
+ assert_nothing_raised Blockchain::Client::APIException do wallet.get_address(addr.address) end
26
+ end
27
+
28
+ def test_new_address_no_exception
29
+ assert_nothing_raised do Blockchain::Wallet.new('773d4edb-bffe-4790-8712-8d232ce04b0c', 'Password1!', 'http://localhost:3000/', 'Password2!').new_address end
30
+ end
31
+
32
+ def test_archive_address_no_exception
33
+ wallet = Blockchain::Wallet.new('773d4edb-bffe-4790-8712-8d232ce04b0c', 'Password1!', 'http://localhost:3000/', 'Password2!')
34
+ addr = wallet.list_addresses[1]
35
+ assert_nothing_raised do wallet.archive_address(addr.address) end
36
+ end
37
+
38
+ def test_unarchive_address_no_exception
39
+ wallet = Blockchain::Wallet.new('773d4edb-bffe-4790-8712-8d232ce04b0c', 'Password1!', 'http://localhost:3000/', 'Password2!')
40
+ addr = wallet.list_addresses[1]
41
+ assert_nothing_raised do wallet.unarchive_address(addr.address) end
42
+ end
43
+
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blockchain
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blockchain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.4'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.4'
55
41
  description: Blockchain API library (Ruby, v1)
56
42
  email:
57
43
  - support@blockchain.zendesk.com
@@ -74,14 +60,19 @@ files:
74
60
  - docs/wallet.md
75
61
  - lib/blockchain.rb
76
62
  - lib/blockchain/blockexplorer.rb
63
+ - lib/blockchain/client.rb
77
64
  - lib/blockchain/createwallet.rb
78
65
  - lib/blockchain/exchangerates.rb
79
66
  - lib/blockchain/pushtx.rb
80
67
  - lib/blockchain/receive.rb
81
68
  - lib/blockchain/statistics.rb
82
- - lib/blockchain/util.rb
83
69
  - lib/blockchain/version.rb
84
70
  - lib/blockchain/wallet.rb
71
+ - test/test_block.rb
72
+ - test/test_exchangerates.rb
73
+ - test/test_pushtx.rb
74
+ - test/test_statistics.rb
75
+ - test/test_wallet.rb
85
76
  homepage: https://github.com/blockchain/api-v1-client-ruby
86
77
  licenses:
87
78
  - MIT
@@ -106,4 +97,9 @@ rubygems_version: 2.5.1
106
97
  signing_key:
107
98
  specification_version: 4
108
99
  summary: Blockchain API library (Ruby, v1)
109
- test_files: []
100
+ test_files:
101
+ - test/test_block.rb
102
+ - test/test_exchangerates.rb
103
+ - test/test_pushtx.rb
104
+ - test/test_statistics.rb
105
+ - test/test_wallet.rb
@@ -1,35 +0,0 @@
1
- require 'net/http'
2
-
3
- module Blockchain
4
-
5
- class APIException < StandardError
6
- end
7
-
8
- BASE_URL = 'https://blockchain.info/'
9
- TIMEOUT_SECONDS = 10
10
-
11
- def self.call_api(resource, method: 'get', data: nil, base_url: nil)
12
- base_url ||= BASE_URL
13
- url = URI.parse(base_url + resource)
14
- http = Net::HTTP.new(url.host, url.port)
15
- http.use_ssl = base_url.start_with? 'https://'
16
- http.read_timeout = TIMEOUT_SECONDS
17
-
18
- request = nil
19
- if method == 'get'
20
- url.query = data.nil? ? nil : URI.encode_www_form(data)
21
- request = Net::HTTP::Get.new(url.request_uri)
22
- elsif method == 'post'
23
- request = Net::HTTP::Post.new(url.request_uri)
24
- request.content_type = 'application/x-www-form-urlencoded'
25
- if data != nil then request.set_form_data(data) else {} end
26
- end
27
-
28
- response = http.request(request)
29
- if response.code != '200'
30
- raise APIException, response.body
31
- end
32
- return response.body
33
- end
34
-
35
- end