-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
140 lines (116 loc) · 3.94 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'yard'
require 'rubybear'
require 'awesome_print'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.ruby_opts << if ENV['HELL_ENABLED']
'-W2'
else
'-W1'
end
end
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb']
end
task default: :test
namespace :clean do
desc 'Deletes test/fixtures/vcr_cassettes/*.yml so they can be rebuilt fresh.'
task :vcr do |t|
exec 'rm -v test/fixtures/vcr_cassettes/*.yml'
end
end
desc 'Tests the ability to broadcast live data. This task broadcasts a claim_reward_balance of 0.0000001 COINS.'
task :test_live_broadcast, [:account, :wif, :chain] do |t, args|
account_name = args[:account] || 'social'
posting_wif = args[:wif] || '5JrvPrQeBBvCRdjv29iDvkwn3EQYZ9jqfAHzrCyUvfbEbRkrYFC'
chain = args[:chain] || 'bears'
# url = 'https://testnet.bearsharesdev.com/' # use testnet
url = nil # use default
options = {chain: chain, wif: posting_wif, url: url}
tx = Rubybear::Transaction.new(options)
tx.operations << {
type: :claim_reward_balance,
account: account_name,
reward_bears: '0.000 BEARS',
reward_bsd: '0.000 BSD',
reward_coins: '0.000001 COINS'
}
response = tx.process(true)
ap response
if !!response.result
result = response.result
puts "https://bearsd.com/b/#{result[:block_num]}" if !!result[:block_num]
puts "https://bearsd.com/tx/#{result[:id]}" if !!result[:id]
end
end
desc 'Tests the ability to stream live data. defaults: chain = bears; persist = true.'
task :test_live_stream, [:chain, :persist] do |t, args|
chain = args[:chain] || 'bears'
persist = (args[:persist] || 'true') == 'true'
last_block_number = 0
# url = 'https://testnet.bearsharesdev.com/'
url = nil # use default
options = {chain: chain, persist: persist, url: url}
total_ops = 0.0
total_vops = 0.0
elapsed = 0
count = 0
Rubybear::Stream.new(options).blocks do |b, n, api|
start = Time.now.utc
if last_block_number == 0
# skip test
elsif last_block_number + 1 == n
t = b.transactions
t_size = t.size
o = t.map(&:operations)
op_size = o.map(&:size).reduce(0, :+)
total_ops += op_size
api.get_ops_in_block(n, true) do |vops, error|
if !!error
puts "Error on get_ops_in_block for block #{n}"
ap error if defined? ap
end
puts "Problem: vops is nil!" if vops.nil?
# Did we reach this point with an unhandled error that wasn't retried?
# If so, vops might be nil and we might need this error to get handled
# instead of checking for vops.nil?.
vop_size = vops.size
total_vops += vop_size
vop_ratio = if total_vops > 0
total_vops / total_ops
else
0
end
elapsed += Time.now.utc - start
count += 1
puts "#{n}: #{b.witness}; trx: #{t_size}; op: #{op_size}, vop: #{vop_size} (cumulative vop ratio: #{('%.2f' % (vop_ratio * 100))} %; average #{((elapsed / count) * 1000).to_i}ms)"
end
else
# This should not happen. If it does, there's likely a bug in Rubybear.
puts "Error, last block number was #{last_block_number}, did not expect #{n}."
end
last_block_number = n
end
end
desc 'Ruby console with rubybear already required.'
task :console do
exec "irb -r rubybear -I ./lib"
end
desc 'Build a new version of the rubybear gem.'
task :build do
exec 'gem build rubybear.gemspec'
end
desc 'Publish the current version of the rubybear gem.'
task :push do
exec "gem push rubybear-#{Rubybear::VERSION}.gem"
end
# We're not going to yank on a regular basis, but this is how it's done if you
# really want a task for that for some reason.
# desc 'Yank the current version of the rubybear gem.'
# task :yank do
# exec "gem yank rubybear -v #{Rubybear::VERSION}"
# end