radiator 0.4.5 → 0.4.8.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +11 -11
  4. data/Rakefile +50 -20
  5. data/lib/radiator.rb +3 -1
  6. data/lib/radiator/api.rb +105 -14
  7. data/lib/radiator/bridge.rb +34 -0
  8. data/lib/radiator/chain_config.rb +9 -2
  9. data/lib/radiator/database_api.rb +1 -1
  10. data/lib/radiator/follow_api.rb +1 -1
  11. data/lib/radiator/market_history_api.rb +1 -1
  12. data/lib/radiator/operation.rb +3 -2
  13. data/lib/radiator/operation_types.rb +43 -27
  14. data/lib/radiator/ssc/base_steem_smart_contract_rpc.rb +52 -10
  15. data/lib/radiator/ssc/blockchain.rb +10 -0
  16. data/lib/radiator/ssc/contracts.rb +17 -0
  17. data/lib/radiator/stream.rb +15 -6
  18. data/lib/radiator/transaction.rb +41 -1
  19. data/lib/radiator/type/amount.rb +26 -50
  20. data/lib/radiator/type/beneficiaries.rb +8 -1
  21. data/lib/radiator/type/price.rb +2 -2
  22. data/lib/radiator/version.rb +1 -1
  23. data/radiator.gemspec +15 -13
  24. data/test/fixtures/empty.json +1 -0
  25. data/test/fixtures/error.json +29 -0
  26. data/test/fixtures/follow_api_get_followers.json +1 -0
  27. data/test/fixtures/get_account.json +165 -0
  28. data/test/fixtures/get_account_count.json +1 -0
  29. data/test/fixtures/get_account_references.json +1 -0
  30. data/test/fixtures/get_block.json +193 -0
  31. data/test/fixtures/get_dynamic_global_properties.json +32 -0
  32. data/test/fixtures/get_feed_history.json +684 -0
  33. data/test/fixtures/get_hardfork_version.json +1 -0
  34. data/test/fixtures/get_key_references.json +14 -0
  35. data/test/fixtures/get_stats_for_time.json +57 -0
  36. data/test/fixtures/get_vesting_delegation.json +936 -0
  37. data/test/fixtures/golos_get_dynamic_global_properties.json +32 -0
  38. data/test/fixtures/market_history_api_get_market_history_buckets.json +1 -0
  39. data/test/fixtures/market_history_api_get_order_book.json +109 -0
  40. data/test/fixtures/market_history_api_get_recent_trades.json +55 -0
  41. data/test/fixtures/market_history_api_get_ticker.json +11 -0
  42. data/test/fixtures/market_history_api_get_volume.json +1 -0
  43. data/test/fixtures/null.json +1 -0
  44. data/test/fixtures/vcr_cassettes/account_by_key_api_all_methods.yml +631 -0
  45. data/test/fixtures/vcr_cassettes/account_by_key_api_jsonrpc.yml +52 -0
  46. data/test/fixtures/vcr_cassettes/all_methods.yml +18155 -0
  47. data/test/fixtures/vcr_cassettes/api_all_methods.yml +13419 -0
  48. data/test/fixtures/vcr_cassettes/base_per_debt.yml +5408 -0
  49. data/test/fixtures/vcr_cassettes/base_per_mvest.yml +4351 -0
  50. data/test/fixtures/vcr_cassettes/block_time.yml +3687 -0
  51. data/test/fixtures/vcr_cassettes/broadcast_transaction.yml +1186 -0
  52. data/test/fixtures/vcr_cassettes/condenser_all_all_methods.yml +13462 -0
  53. data/test/fixtures/vcr_cassettes/condenser_api_jsonrpc.yml +51 -0
  54. data/test/fixtures/vcr_cassettes/expiration_initialize.yml +3997 -0
  55. data/test/fixtures/vcr_cassettes/find_account.yml +4004 -0
  56. data/test/fixtures/vcr_cassettes/find_block.yml +3946 -0
  57. data/test/fixtures/vcr_cassettes/find_comment.yml +12457 -0
  58. data/test/fixtures/vcr_cassettes/follow_api_jsonrpc.yml +52 -0
  59. data/test/fixtures/vcr_cassettes/get_account_count.yml +627 -0
  60. data/test/fixtures/vcr_cassettes/get_account_references.yml +663 -0
  61. data/test/fixtures/vcr_cassettes/get_accounts.yml +735 -0
  62. data/test/fixtures/vcr_cassettes/get_accounts_no_argument.yml +663 -0
  63. data/test/fixtures/vcr_cassettes/get_dynamic_global_properties.yml +721 -0
  64. data/test/fixtures/vcr_cassettes/get_feed_history.yml +1201 -0
  65. data/test/fixtures/vcr_cassettes/get_hardfork_version.yml +629 -0
  66. data/test/fixtures/vcr_cassettes/get_key_references.yml +1091 -0
  67. data/test/fixtures/vcr_cassettes/get_market_history.yml +1147 -0
  68. data/test/fixtures/vcr_cassettes/get_market_history_buckets.yml +1147 -0
  69. data/test/fixtures/vcr_cassettes/get_order_book.yml +1195 -0
  70. data/test/fixtures/vcr_cassettes/get_recent_trades.yml +1147 -0
  71. data/test/fixtures/vcr_cassettes/get_ticker.yml +1151 -0
  72. data/test/fixtures/vcr_cassettes/get_trade_history.yml +1153 -0
  73. data/test/fixtures/vcr_cassettes/get_vesting_delegations.yml +575 -0
  74. data/test/fixtures/vcr_cassettes/get_volume.yml +1155 -0
  75. data/test/fixtures/vcr_cassettes/get_witness_by_account.yml +627 -0
  76. data/test/fixtures/vcr_cassettes/look_up_witnesses.yml +575 -0
  77. data/test/fixtures/vcr_cassettes/market_history_api_all_methods.yml +4373 -0
  78. data/test/fixtures/vcr_cassettes/network_broadcast_api_all_methods.yml +1288 -0
  79. data/test/fixtures/vcr_cassettes/properties.yml +3992 -0
  80. data/test/fixtures/vcr_cassettes/recover_transaction.yml +1211 -0
  81. data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info.yml +92 -0
  82. data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info_invalid.yml +90 -0
  83. data/test/fixtures/vcr_cassettes/ssc_blockchain_latest_block_info.yml +91 -0
  84. data/test/fixtures/vcr_cassettes/ssc_blockchain_transaction_info.yml +92 -0
  85. data/test/fixtures/vcr_cassettes/ssc_contracts_contract.yml +366 -0
  86. data/test/fixtures/vcr_cassettes/ssc_contracts_find.yml +91 -0
  87. data/test/fixtures/vcr_cassettes/ssc_contracts_find_one.yml +89 -0
  88. data/test/fixtures/vcr_cassettes/stream_jsonrpc.yml +9175 -0
  89. data/test/fixtures/vcr_cassettes/transaction_expiration_initialize_nil.yml +3743 -0
  90. data/test/fixtures/vcr_cassettes/transaction_jsonrpc.yml +151 -0
  91. data/test/fixtures/vcr_cassettes/unknown_chain_id.yml +3869 -0
  92. data/test/fixtures/vcr_cassettes/valid_chains.yml +3427 -0
  93. data/test/radiator/account_by_key_api_test.rb +46 -0
  94. data/test/radiator/api_test.rb +135 -0
  95. data/test/radiator/chain_stats_api_test.rb +49 -0
  96. data/test/radiator/chain_test.rb +153 -0
  97. data/test/radiator/condenser_api_test.rb +48 -0
  98. data/test/radiator/follow_api_test.rb +48 -0
  99. data/test/radiator/market_history_api_test.rb +100 -0
  100. data/test/radiator/network_broadcast_api_test.rb +48 -0
  101. data/test/radiator/operation_test.rb +117 -0
  102. data/test/radiator/ssc/blockchain_test.rb +58 -0
  103. data/test/radiator/ssc/contracts_test.rb +65 -0
  104. data/test/radiator/stream_test.rb +48 -0
  105. data/test/radiator/tag_api_test.rb +40 -0
  106. data/test/radiator/transaction_test.rb +755 -0
  107. data/test/test_helper.rb +66 -0
  108. metadata +190 -80
  109. data/.codeclimate.yml +0 -19
  110. data/.gitignore +0 -52
  111. data/.travis.yml +0 -23
  112. data/gource.sh +0 -8
  113. data/images/Anthony Martin.png +0 -0
  114. data/images/Marvin Hofmann.jpg +0 -0
  115. data/images/Marvin Hofmann.png +0 -0
  116. data/lib/steem.rb +0 -17
@@ -0,0 +1,100 @@
1
+ require 'test_helper'
2
+
3
+ module Radiator
4
+ class MarketHistoryApiTest < Radiator::Test
5
+ def setup
6
+ vcr_cassette('market_history_api_jsonrpc') do
7
+ @api = Radiator::MarketHistoryApi.new(chain_options)
8
+ end
9
+ end
10
+
11
+ def test_method_missing
12
+ assert_raises NoMethodError do
13
+ @api.bogus
14
+ end
15
+ end
16
+
17
+ def test_all_respond_to
18
+ vcr_cassette('market_history_api_all_respond_to') do
19
+ @api.method_names.each do |key|
20
+ assert @api.respond_to?(key), "expect rpc respond to #{key}"
21
+ end
22
+ end
23
+ end
24
+
25
+ def test_all_methods
26
+ vcr_cassette('market_history_api_all_methods') do
27
+ @api.method_names.each do |key|
28
+ begin
29
+ assert @api.send key
30
+ rescue Steem::ArgumentError => e
31
+ # next
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def test_get_market_history
38
+ vcr_cassette('get_market_history') do
39
+ @api.get_market_history(nil, nil, nil) do |history|
40
+ assert_equal Hashie::Mash, history.class, history.inspect
41
+ assert_equal history.buckets, []
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_get_market_history_buckets
47
+ vcr_cassette('get_market_history_buckets') do
48
+ @api.get_market_history_buckets do |buckets|
49
+ assert_equal Hashie::Mash, buckets.class, buckets.inspect
50
+ assert buckets
51
+ end
52
+ end
53
+ end
54
+
55
+ def test_get_order_book
56
+ vcr_cassette('get_order_book') do
57
+ @api.get_order_book(limit: 10) do |order_book|
58
+ assert_equal Hashie::Mash, order_book.class, order_book.inspect
59
+ assert order_book
60
+ end
61
+ end
62
+ end
63
+
64
+ def test_get_recent_trades
65
+ vcr_cassette('get_recent_trades') do
66
+ @api.get_recent_trades(limit: 10) do |trades|
67
+ assert_equal Hashie::Mash, trades.class, trades.inspect
68
+ assert trades.trades
69
+ end
70
+ end
71
+ end
72
+
73
+ def test_get_ticker
74
+ vcr_cassette('get_ticker') do
75
+ @api.get_ticker do |ticker|
76
+ assert_equal Hashie::Mash, ticker.class, ticker.inspect
77
+ assert ticker
78
+ end
79
+ end
80
+ end
81
+
82
+ def test_get_trade_history
83
+ vcr_cassette('get_trade_history') do
84
+ @api.get_trade_history(nil, nil, nil) do |history|
85
+ assert_equal Hashie::Mash, history.class, history.inspect
86
+ assert_equal history.trades, []
87
+ end
88
+ end
89
+ end
90
+
91
+ def test_get_volume
92
+ vcr_cassette('get_volume') do
93
+ @api.get_volume do |volume|
94
+ assert_equal Hashie::Mash, volume.class, volume.inspect
95
+ assert volume
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ module Radiator
4
+ class NetworkBroadcastApiTest < Radiator::Test
5
+ def setup
6
+ vcr_cassette('network_broadcast_api_jsonrpc') do
7
+ @api = Radiator::NetworkBroadcastApi.new(chain_options)
8
+ @silent_api = Radiator::NetworkBroadcastApi.new(chain_options.merge(logger: LOGGER))
9
+ end
10
+ end
11
+
12
+ def test_method_missing
13
+ assert_raises NoMethodError do
14
+ @api.bogus
15
+ end
16
+ end
17
+
18
+ def test_all_respond_to
19
+ vcr_cassette('network_broadcast_api_all_respond_to') do
20
+ @api.method_names.each do |key|
21
+ assert @api.respond_to?(key), "expect rpc respond to #{key}"
22
+ end
23
+ end
24
+ end
25
+
26
+ def test_all_methods
27
+ vcr_cassette('network_broadcast_api_all_methods') do
28
+ @silent_api.method_names.each do |key|
29
+ begin
30
+ assert @silent_api.send key
31
+ rescue Steem::ArgumentError => e
32
+ # next
33
+ rescue Steem::RemoteNodeError => e
34
+ # next
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def test_broadcast_transaction
41
+ vcr_cassette('broadcast_transaction') do
42
+ assert_raises Steem::RemoteNodeError do
43
+ @silent_api.broadcast_transaction
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,117 @@
1
+ require 'test_helper'
2
+
3
+ module Radiator
4
+ class OperationTest < Radiator::Test
5
+ def test_unsupported_operation_type
6
+ assert_raises OperationError, 'expect operation type not to be supported' do
7
+ Radiator::Operation.new
8
+ end
9
+ end
10
+
11
+ def test_unsupported_param_type
12
+ operation = Radiator::Operation.new(type: :vote, voter: 0.0)
13
+
14
+ assert_raises OperationError, 'expect operation type not to be supported' do
15
+ operation.to_bytes
16
+ end
17
+ end
18
+
19
+ def test_supported_string
20
+ operation = Radiator::Operation.new(type: :vote, voter: 'inertia')
21
+
22
+ assert_equal "\x00\ainertia", operation.to_bytes
23
+ end
24
+
25
+ def test_supported_fixnum
26
+ operation = Radiator::Operation.new(type: :vote, weight: 10000)
27
+
28
+ assert_equal "\x00\x10'", operation.to_bytes
29
+ end
30
+
31
+ def test_supported_true_class
32
+ operation = Radiator::Operation.new(type: :comment_options, allow_votes: true)
33
+
34
+ assert_equal "\x13\x01", operation.to_bytes
35
+ end
36
+
37
+ def test_supported_false_class
38
+ operation = Radiator::Operation.new(type: :comment_options, allow_votes: false)
39
+
40
+ expected_bytes = "\x13\x00"
41
+ expected_bytes = expected_bytes.force_encoding('ASCII-8BIT')
42
+
43
+ assert_equal expected_bytes, operation.to_bytes
44
+ end
45
+
46
+ def test_supported_empty_array_class
47
+ operation = Radiator::Operation.new(type: :comment_options, extensions: [])
48
+
49
+ expected_bytes = "\x13\x00"
50
+ expected_bytes = expected_bytes.force_encoding('ASCII-8BIT')
51
+
52
+ assert_equal expected_bytes, operation.to_bytes
53
+ end
54
+
55
+ def test_supported_complex_array_class
56
+ extensions = [[0,{"beneficiaries":[{"account":"inertia","weight":500}]}]]
57
+ operation = Radiator::Operation.new(type: :comment_options, extensions: extensions)
58
+
59
+ expected_bytes = "\x13\x01\x02\x00\x00\x01\rbeneficiaries\x01\x02\aaccount\ainertia\x06weight\xF4\x01"
60
+ expected_bytes = expected_bytes.force_encoding('ASCII-8BIT')
61
+
62
+ assert_equal expected_bytes, operation.to_bytes
63
+ end
64
+
65
+ def test_supported_nil_class
66
+ operation = Radiator::Operation.new(type: :comment, json_metadata: nil)
67
+
68
+ assert_equal "\x01", operation.to_bytes
69
+ end
70
+
71
+ def test_supported_array
72
+ operation = Radiator::Operation.new(type: :custom_json, required_auths: [])
73
+
74
+ assert_equal "\x12\x00", operation.to_bytes
75
+ end
76
+
77
+ def test_operation_payload
78
+ operation = Radiator::Operation.new(
79
+ chain: :hive,
80
+ type: :comment_options,
81
+ author: 'xeroc',
82
+ permlink: 'piston',
83
+ max_accepted_payout: '1000000.000 HBD',
84
+ percent_steem_dollars: 10000,
85
+ # allow_replies: true,
86
+ allow_votes: true,
87
+ allow_curation_rewards: true,
88
+ extensions: Radiator::Type::Beneficiaries.new('good-karma' => 2000, 'null' => 5000)
89
+ )
90
+
91
+ # Note, we still expect `SBD` in bytes from seralization.
92
+ expected_bytes = "\x13\x05xeroc\x06piston\x00\xCA\x9A;\x00\x00\x00\x00\x03SBD\x00\x00\x00\x00\x10'\x01\x01\x01\x00\x02\ngood-karma\xD0\a\x04null\x88\x13"
93
+ expected_bytes = expected_bytes.force_encoding('ASCII-8BIT')
94
+
95
+ assert_equal expected_bytes, operation.to_bytes
96
+
97
+ expected_payload = [:comment_options, {
98
+ author: 'xeroc',
99
+ permlink: 'piston',
100
+ max_accepted_payout: Hive::Type::Amount.new('1000000.000 HBD'),
101
+ percent_steem_dollars: 10000,
102
+ allow_votes: true,
103
+ allow_curation_rewards: true,
104
+ extensions: [[0, {beneficiaries: [{
105
+ account: 'good-karma',
106
+ weight: 2000
107
+ }, {
108
+ account: 'null',
109
+ weight: 5000
110
+ }]}]]
111
+ }]
112
+
113
+ assert_equal expected_payload[0], operation.payload[0]
114
+ assert_equal expected_payload[1].keys, operation.payload[1].keys
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ module Radiator
4
+ module SSC
5
+ class BlockchainTest < Radiator::Test
6
+ def setup
7
+ @rpc = Radiator::SSC::Blockchain.new
8
+ end
9
+
10
+ def teardown
11
+ @rpc.shutdown
12
+ end
13
+
14
+ def test_latest_block_info
15
+ vcr_cassette('ssc_blockchain_latest_block_info') do
16
+ assert @rpc.latest_block_info
17
+ end
18
+ end
19
+
20
+ def test_block_info
21
+ vcr_cassette('ssc_blockchain_block_info') do
22
+ block_num = 1
23
+ block_info = @rpc.block_info(block_num)
24
+ assert block_info
25
+ assert_equal block_num, block_info.blockNumber
26
+ end
27
+ end
28
+
29
+ def test_block_info_invalid
30
+ vcr_cassette('ssc_blockchain_block_info_invalid') do
31
+ assert_raises Radiator::ApiError do
32
+ @rpc.block_info('WRONG')
33
+ end
34
+ end
35
+ end
36
+
37
+ def test_transaction_info
38
+ vcr_cassette('ssc_blockchain_transaction_info') do
39
+ trx_id = 'df846ffdbd87f3fae2a60993dae9d16d44c814e3'
40
+ transaction_info = @rpc.transaction_info(trx_id)
41
+ assert transaction_info
42
+ assert_equal trx_id, transaction_info.transactionId
43
+ end
44
+ end
45
+
46
+ def test_no_persist_transaction_info
47
+ rpc = Radiator::SSC::Blockchain.new(persist: false)
48
+
49
+ vcr_cassette('ssc_blockchain_transaction_info') do
50
+ trx_id = 'df846ffdbd87f3fae2a60993dae9d16d44c814e3'
51
+ transaction_info = rpc.transaction_info(trx_id)
52
+ assert transaction_info
53
+ assert_equal trx_id, transaction_info.transactionId
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+
3
+ module Radiator
4
+ module SSC
5
+ class ContractsTest < Radiator::Test
6
+ def setup
7
+ @rpc = Radiator::SSC::Contracts.new
8
+ end
9
+
10
+ def test_contract
11
+ vcr_cassette('ssc_contracts_contract') do
12
+ assert @rpc.contract('tokens')
13
+ end
14
+ end
15
+
16
+ def test_find_one
17
+ vcr_cassette('ssc_contracts_find_one') do
18
+ params = {
19
+ contract: 'tokens',
20
+ table: 'balances',
21
+ query: {
22
+ symbol: 'STINGY',
23
+ account: 'inertia'
24
+ }
25
+ }
26
+ result = @rpc.find_one(params)
27
+ assert result
28
+ assert_equal 36.92931281, result.balance.to_f
29
+ end
30
+ end
31
+
32
+ def test_find
33
+ vcr_cassette('ssc_contracts_find') do
34
+ params = {
35
+ contract: 'tokens',
36
+ table: 'balances',
37
+ query: {
38
+ symbol: 'STINGY'
39
+ }
40
+ }
41
+ result = @rpc.find(params)
42
+ assert result
43
+ assert_equal 33, result.size
44
+ end
45
+ end
46
+
47
+ def test_no_persist_find
48
+ rpc = Radiator::SSC::Contracts.new(persist: false)
49
+
50
+ vcr_cassette('ssc_contracts_find') do
51
+ params = {
52
+ contract: 'tokens',
53
+ table: 'balances',
54
+ query: {
55
+ symbol: 'STINGY'
56
+ }
57
+ }
58
+ result = rpc.find(params)
59
+ assert result
60
+ assert_equal 33, result.size
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ module Radiator
4
+ class StreamTest < Radiator::Test
5
+ def setup
6
+ vcr_cassette('stream_jsonrpc') do
7
+ @api = Radiator::Stream.new
8
+ end
9
+ end
10
+
11
+ def test_method_missing
12
+ assert_raises NoMethodError do
13
+ @api.bogus
14
+ end
15
+ end
16
+
17
+ def test_all_respond_to
18
+ vcr_cassette('stream_all_respond_to') do
19
+ @api.method_names.each do |key|
20
+ assert @api.respond_to?(key), "expect rpc respond to #{key}"
21
+ end
22
+ end
23
+ end
24
+
25
+ def test_all_methods
26
+ vcr_cassette('stream_all_methods') do
27
+ skip "cannot execute an asynchronous request in tests"
28
+
29
+ @api.method_names.each do |key|
30
+ begin
31
+ assert @api.send key
32
+ rescue Steem::ArgumentError => e
33
+ # next
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def test_get_operations
40
+ skip "cannot execute an asynchronous request in tests"
41
+
42
+ vcr_cassette('get_operations') do
43
+ @api.operations
44
+ assert_equal Hashie::Mash, response.class, response.inspect
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ module Radiator
4
+ class TagApiTest < Radiator::Test
5
+ def setup
6
+ vcr_cassette('tag_api_jsonrpc') do
7
+ @api = Radiator::TagApi.new(chain_options)
8
+ end
9
+ end
10
+
11
+ def test_method_missing
12
+ assert_raises NoMethodError do
13
+ @api.bogus
14
+ end
15
+ end
16
+
17
+ def test_all_respond_to
18
+ vcr_cassette('tag_api_all_respond_to') do
19
+ @api.method_names.each do |key|
20
+ assert @api.respond_to?(key), "expect rpc respond to #{key}"
21
+ end
22
+ end
23
+ end
24
+
25
+ def test_all_methods
26
+ vcr_cassette('tag_api_all_methods') do
27
+ skip
28
+ vcr_cassette('all_methods') do
29
+ @api.method_names.each do |key|
30
+ begin
31
+ assert @api.send key
32
+ rescue Steem::ArgumentError => e
33
+ # next
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end