zold 0.11.5 → 0.11.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fixtures/scripts/push-and-pull.sh +1 -0
- data/lib/zold/commands/fetch.rb +2 -2
- data/lib/zold/commands/node.rb +2 -1
- data/lib/zold/commands/push.rb +4 -4
- data/lib/zold/commands/remote.rb +10 -0
- data/lib/zold/http.rb +1 -1
- data/lib/zold/node/entrance.rb +3 -2
- data/lib/zold/node/farm.rb +11 -5
- data/lib/zold/node/front.rb +5 -1
- data/lib/zold/remotes.rb +1 -1
- data/lib/zold/verbose_thread.rb +2 -2
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_calculate.rb +1 -1
- data/test/commands/test_clean.rb +1 -1
- data/test/commands/test_create.rb +1 -1
- data/test/commands/test_diff.rb +2 -2
- data/test/commands/test_fetch.rb +2 -2
- data/test/commands/test_invoice.rb +1 -1
- data/test/commands/test_list.rb +1 -1
- data/test/commands/test_merge.rb +4 -4
- data/test/commands/test_node.rb +3 -3
- data/test/commands/test_pay.rb +3 -3
- data/test/commands/test_push.rb +1 -1
- data/test/commands/test_remote.rb +1 -1
- data/test/commands/test_show.rb +1 -1
- data/test/commands/test_taxes.rb +1 -1
- data/test/node/test_emission.rb +1 -1
- data/test/node/test_entrance.rb +2 -2
- data/test/node/test_farm.rb +15 -2
- data/test/node/test_front.rb +5 -4
- data/test/test__helper.rb +5 -5
- data/test/test_zold.rb +1 -1
- metadata +1 -3
- data/test/support/logs.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4b85a4409d351be25bfa99d529cb7805474c413
|
4
|
+
data.tar.gz: 17c7832d676da4213cccf791dc38a175d2a45667
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 214f26718d2dcf269e355bb574edb51c4b2d15dc6b0679ef8a721e77595751b551d4e48c3fe83d65889b612453a2a7e7cea45be8a22f063629ffa33ab663d0dc
|
7
|
+
data.tar.gz: f488b84aa410a24cf9c73e3acfebe7943378889a183fa923937856bbdb8ee27ec11e8bdd3a00cc75bbf4ad5b5cbe431abeb3ea291581161a0bff63abb3b0a0f8
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -77,7 +77,7 @@ Available options:"
|
|
77
77
|
def fetch_one(id, r, cps, opts)
|
78
78
|
start = Time.now
|
79
79
|
if opts['ignore-node'].include?(r.to_s)
|
80
|
-
@log.
|
80
|
+
@log.debug("#{r} ignored because of --ignore-node")
|
81
81
|
return false
|
82
82
|
end
|
83
83
|
res = r.http("/wallet/#{id}").get
|
@@ -92,7 +92,7 @@ Available options:"
|
|
92
92
|
File.write(f, body)
|
93
93
|
wallet = Wallet.new(f.path)
|
94
94
|
cps.add(body, score.host, score.port, score.value)
|
95
|
-
@log.info("#{r} returned #{body.length}b/#{wallet.txns.count} \
|
95
|
+
@log.info("#{r} returned #{body.length}b/#{wallet.txns.count}t \
|
96
96
|
of #{id} in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green} (#{json['version']})")
|
97
97
|
end
|
98
98
|
end
|
data/lib/zold/commands/node.rb
CHANGED
@@ -119,11 +119,12 @@ module Zold
|
|
119
119
|
)
|
120
120
|
Front.set(:farm, farm)
|
121
121
|
update = Thread.start do
|
122
|
-
VerboseThread.new(@log).run do
|
122
|
+
VerboseThread.new(@log).run(true) do
|
123
123
|
loop do
|
124
124
|
sleep(60)
|
125
125
|
require_relative 'remote'
|
126
126
|
Remote.new(remotes: remotes, log: @log, farm: farm).run(%w[remote update --reboot])
|
127
|
+
Remote.new(remotes: remotes, log: @log).run(%w[remote trim])
|
127
128
|
@log.debug('Regular update of remote nodes succeeded')
|
128
129
|
end
|
129
130
|
end
|
data/lib/zold/commands/push.rb
CHANGED
@@ -73,7 +73,7 @@ Available options:"
|
|
73
73
|
|
74
74
|
def push_one(wallet, r, opts)
|
75
75
|
if opts['ignore-node'].include?(r.to_s)
|
76
|
-
@log.
|
76
|
+
@log.debug("#{r} ignored because of --ignore-node")
|
77
77
|
return 0
|
78
78
|
end
|
79
79
|
start = Time.now
|
@@ -84,11 +84,11 @@ Available options:"
|
|
84
84
|
return 0
|
85
85
|
end
|
86
86
|
r.assert_code(200, response)
|
87
|
-
json = JSON.parse(response.body)
|
88
|
-
score = Score.parse_json(json)
|
87
|
+
json = JSON.parse(response.body)
|
88
|
+
score = Score.parse_json(json['score'])
|
89
89
|
r.assert_valid_score(score)
|
90
90
|
raise "Score is too weak #{score}" if score.strength < Score::STRENGTH
|
91
|
-
@log.info("#{r} accepted #{content.length}b/#{wallet.txns.count}
|
91
|
+
@log.info("#{r} accepted #{content.length}b/#{wallet.txns.count}t of #{wallet.id} \
|
92
92
|
in #{(Time.now - start).round(2)}s: #{Rainbow(score.value).green} (#{json['version']})")
|
93
93
|
score.value
|
94
94
|
end
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -58,6 +58,8 @@ Available commands:
|
|
58
58
|
Add a new remote node
|
59
59
|
#{Rainbow('remote remove').green} host [port]
|
60
60
|
Remove the remote node
|
61
|
+
#{Rainbow('remote trim').green}
|
62
|
+
Remote the least reliable nodes
|
61
63
|
#{Rainbow('remote update').green}
|
62
64
|
Check each registered remote node for availability
|
63
65
|
Available options:"
|
@@ -86,6 +88,8 @@ Available options:"
|
|
86
88
|
add(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
|
87
89
|
when 'remove'
|
88
90
|
remove(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
|
91
|
+
when 'trim'
|
92
|
+
trim(opts)
|
89
93
|
when 'update'
|
90
94
|
update(opts)
|
91
95
|
update(opts, false)
|
@@ -135,6 +139,12 @@ Available options:"
|
|
135
139
|
@log.info("There are #{@remotes.all.count} remote nodes in the list")
|
136
140
|
end
|
137
141
|
|
142
|
+
def trim(opts)
|
143
|
+
@remotes.all.each do |r|
|
144
|
+
remove(r[:host], r[:port], opts) if r[:errors] > 20
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
138
148
|
def update(opts, deep = true)
|
139
149
|
capacity = []
|
140
150
|
@remotes.iterate(@log, farm: @farm) do |r|
|
data/lib/zold/http.rb
CHANGED
data/lib/zold/node/entrance.rb
CHANGED
@@ -44,7 +44,7 @@ module Zold
|
|
44
44
|
@address = address
|
45
45
|
@log = log
|
46
46
|
@semaphores = Concurrent::Map.new
|
47
|
-
@pool = Concurrent::FixedThreadPool.new(16)
|
47
|
+
@pool = Concurrent::FixedThreadPool.new(16, max_queue: 64, fallback_policy: :abort)
|
48
48
|
end
|
49
49
|
|
50
50
|
def push(id, body, sync: true)
|
@@ -78,8 +78,9 @@ module Zold
|
|
78
78
|
def push_sync(id, body)
|
79
79
|
@semaphores.put_if_absent(id, Mutex.new)
|
80
80
|
@semaphores.get(id).synchronize do
|
81
|
+
start = Time.now
|
81
82
|
modified = push_unsafe(id, body)
|
82
|
-
@log.info("Accepted #{id} and modified
|
83
|
+
@log.info("Accepted #{id} in #{(Time.now - start) / 60}s and modified #{modified.join(', ')}")
|
83
84
|
modified
|
84
85
|
end
|
85
86
|
end
|
data/lib/zold/node/farm.rb
CHANGED
@@ -58,10 +58,11 @@ module Zold
|
|
58
58
|
|
59
59
|
def start(host, port, strength: 8, threads: 8)
|
60
60
|
@log.debug('Zero-threads farm won\'t score anything!') if threads.zero?
|
61
|
-
@best << Score.new(Time.now, host, port, @invoice, strength: strength)
|
62
61
|
@scores = Queue.new
|
63
|
-
|
64
|
-
|
62
|
+
h = history(threads)
|
63
|
+
h.each { |s| @scores << s }
|
64
|
+
@best << (h[0] || Score.new(Time.now, host, port, @invoice, strength: strength))
|
65
|
+
@log.info("#{@scores.size} scores pre-loaded, the best is: #{@best[0]}")
|
65
66
|
@threads = (1..threads).map do |t|
|
66
67
|
Thread.new do
|
67
68
|
VerboseThread.new(@log).run do
|
@@ -107,9 +108,14 @@ module Zold
|
|
107
108
|
File.write(@cache, (history + [score]).map(&:to_s).join("\n"))
|
108
109
|
end
|
109
110
|
|
110
|
-
def history
|
111
|
+
def history(max = 16)
|
111
112
|
if File.exist?(@cache)
|
112
|
-
File.readlines(@cache)
|
113
|
+
File.readlines(@cache)
|
114
|
+
.map { |t| Score.parse(t) }
|
115
|
+
.reject(&:expired?)
|
116
|
+
.sort_by(&:value)
|
117
|
+
.reverse
|
118
|
+
.take(max)
|
113
119
|
else
|
114
120
|
[]
|
115
121
|
end
|
data/lib/zold/node/front.rb
CHANGED
@@ -90,6 +90,10 @@ module Zold
|
|
90
90
|
'User-agent: *'
|
91
91
|
end
|
92
92
|
|
93
|
+
get '/v' do
|
94
|
+
VERSION
|
95
|
+
end
|
96
|
+
|
93
97
|
get '/favicon.ico' do
|
94
98
|
if score.value >= 16
|
95
99
|
redirect 'https://www.zold.io/images/logo-green.png'
|
@@ -108,7 +112,7 @@ module Zold
|
|
108
112
|
pid: Process.pid,
|
109
113
|
cpus: Concurrent.processor_count,
|
110
114
|
uptime: `uptime`.strip,
|
111
|
-
threads: Thread.list.select { |t| t.status == 'run' }.count,
|
115
|
+
threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
|
112
116
|
wallets: settings.wallets.all.count,
|
113
117
|
remotes: settings.remotes.all.count,
|
114
118
|
farm: settings.farm.to_json,
|
data/lib/zold/remotes.rb
CHANGED
@@ -64,9 +64,9 @@ module Zold
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def assert_code(code, response)
|
67
|
-
@log.debug("#{response.code} \"#{response.message}\" at \"#{response.body}\"")
|
68
67
|
msg = response.message
|
69
68
|
return if response.code.to_i == code
|
69
|
+
@log.debug("#{response.code} \"#{response.message}\" at \"#{response.body}\"")
|
70
70
|
raise "Unexpected HTTP code #{response.code}, instead of #{code}" if msg.empty?
|
71
71
|
raise "#{msg} (HTTP code #{response.code}, instead of #{code})"
|
72
72
|
end
|
data/lib/zold/verbose_thread.rb
CHANGED
data/lib/zold/version.rb
CHANGED
@@ -29,7 +29,7 @@ require_relative '../../lib/zold/commands/calculate'
|
|
29
29
|
# License:: MIT
|
30
30
|
class TestCalculate < Minitest::Test
|
31
31
|
def test_calculates_score
|
32
|
-
score = Zold::Calculate.new(log:
|
32
|
+
score = Zold::Calculate.new(log: test_log).run(
|
33
33
|
['score', '--strength=2', '--max=8', '--invoice=NOSUFFIX@ffffffffffffffff']
|
34
34
|
)
|
35
35
|
assert(score.valid?)
|
data/test/commands/test_clean.rb
CHANGED
@@ -36,7 +36,7 @@ class TestClean < Minitest::Test
|
|
36
36
|
copies = home.copies(wallet)
|
37
37
|
copies.add('a1', 'host-1', 80, 1, Time.now - 26 * 60 * 60)
|
38
38
|
copies.add('a2', 'host-2', 80, 2, Time.now - 26 * 60 * 60)
|
39
|
-
Zold::Clean.new(wallets: home.wallets, copies: copies.root, log:
|
39
|
+
Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean', wallet.id.to_s])
|
40
40
|
assert(copies.all.empty?)
|
41
41
|
end
|
42
42
|
end
|
@@ -32,7 +32,7 @@ require_relative '../../lib/zold/commands/create'
|
|
32
32
|
class TestCreate < Minitest::Test
|
33
33
|
def test_creates_wallet
|
34
34
|
Dir.mktmpdir 'test' do |dir|
|
35
|
-
wallet = Zold::Create.new(wallets: Zold::Wallets.new(dir), log:
|
35
|
+
wallet = Zold::Create.new(wallets: Zold::Wallets.new(dir), log: test_log).run(
|
36
36
|
['create', '--public-key=fixtures/id_rsa.pub']
|
37
37
|
)
|
38
38
|
assert wallet.balance.zero?
|
data/test/commands/test_diff.rb
CHANGED
@@ -44,13 +44,13 @@ class TestDiff < Minitest::Test
|
|
44
44
|
File.write(first.path, File.read(wallet.path))
|
45
45
|
second = home.create_wallet
|
46
46
|
File.write(second.path, File.read(wallet.path))
|
47
|
-
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log:
|
47
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
48
48
|
['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
|
49
49
|
)
|
50
50
|
copies = home.copies(wallet)
|
51
51
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
52
52
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
53
|
-
diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log:
|
53
|
+
diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
54
54
|
['diff', wallet.id.to_s]
|
55
55
|
)
|
56
56
|
assert(diff.include?('-0001;'))
|
data/test/commands/test_fetch.rb
CHANGED
@@ -59,7 +59,7 @@ class TestFetch < Minitest::Test
|
|
59
59
|
remotes.add('fake-1', 80)
|
60
60
|
remotes.add('fake-2', 80)
|
61
61
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
62
|
-
Zold::Fetch.new(wallets: wallets, copies: copies.root, remotes: remotes, log:
|
62
|
+
Zold::Fetch.new(wallets: wallets, copies: copies.root, remotes: remotes, log: test_log).run(
|
63
63
|
['fetch', '--ignore-score-weakness', id.to_s]
|
64
64
|
)
|
65
65
|
assert_equal(copies.all[0][:name], '1')
|
@@ -83,7 +83,7 @@ class TestFetch < Minitest::Test
|
|
83
83
|
remotes.add('fake-1', 80)
|
84
84
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
85
85
|
Zold::Fetch.new(
|
86
|
-
wallets: wallets, copies: copies.root, remotes: remotes, log:
|
86
|
+
wallets: wallets, copies: copies.root, remotes: remotes, log: test_log
|
87
87
|
).run(['fetch', id.to_s])
|
88
88
|
assert_equal(copies.all[0][:name], '1')
|
89
89
|
assert_equal(copies.all[0][:score], 0)
|
@@ -38,7 +38,7 @@ class TestInvoice < Minitest::Test
|
|
38
38
|
wallets = Zold::Wallets.new(dir)
|
39
39
|
source = wallets.find(id)
|
40
40
|
source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
41
|
-
invoice = Zold::Invoice.new(wallets: wallets, log:
|
41
|
+
invoice = Zold::Invoice.new(wallets: wallets, log: test_log).run(
|
42
42
|
['invoice', id.to_s, '--length=16']
|
43
43
|
)
|
44
44
|
assert_equal(33, invoice.length)
|
data/test/commands/test_list.rb
CHANGED
@@ -37,7 +37,7 @@ class TestList < Minitest::Test
|
|
37
37
|
wallets = Zold::Wallets.new(dir)
|
38
38
|
wallet = wallets.find(id)
|
39
39
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
40
|
-
Zold::List.new(wallets: wallets, log:
|
40
|
+
Zold::List.new(wallets: wallets, log: test_log).run
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/test/commands/test_merge.rb
CHANGED
@@ -45,13 +45,13 @@ class TestMerge < Minitest::Test
|
|
45
45
|
File.write(first.path, File.read(wallet.path))
|
46
46
|
second = home.create_wallet
|
47
47
|
File.write(second.path, File.read(wallet.path))
|
48
|
-
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log:
|
48
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
49
49
|
['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
|
50
50
|
)
|
51
51
|
copies = home.copies(wallet)
|
52
52
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
53
53
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
54
|
-
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log:
|
54
|
+
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
55
55
|
['merge', wallet.id.to_s]
|
56
56
|
)
|
57
57
|
assert(1, modified.count)
|
@@ -66,13 +66,13 @@ class TestMerge < Minitest::Test
|
|
66
66
|
File.write(first.path, File.read(wallet.path))
|
67
67
|
second = home.create_wallet
|
68
68
|
File.write(second.path, File.read(wallet.path))
|
69
|
-
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log:
|
69
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
70
70
|
['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
|
71
71
|
)
|
72
72
|
copies = home.copies(wallet)
|
73
73
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
74
74
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
75
|
-
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log:
|
75
|
+
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
76
76
|
['merge', wallet.id.to_s]
|
77
77
|
)
|
78
78
|
assert(1, modified.count)
|
data/test/commands/test_node.rb
CHANGED
@@ -38,7 +38,7 @@ require_relative '../node/fake_node'
|
|
38
38
|
# License:: MIT
|
39
39
|
class TestNode < Minitest::Test
|
40
40
|
def test_push_and_fetch
|
41
|
-
FakeNode.new(log:
|
41
|
+
FakeNode.new(log: test_log).run do |port|
|
42
42
|
Dir.mktmpdir 'test' do |dir|
|
43
43
|
id = Zold::Id.new
|
44
44
|
wallets = Zold::Wallets.new(dir)
|
@@ -47,10 +47,10 @@ class TestNode < Minitest::Test
|
|
47
47
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
48
48
|
remotes.clean
|
49
49
|
remotes.add('localhost', port)
|
50
|
-
Zold::Push.new(wallets: wallets, remotes: remotes, log:
|
50
|
+
Zold::Push.new(wallets: wallets, remotes: remotes, log: test_log).run(['push', '--sync'])
|
51
51
|
Zold::Fetch.new(
|
52
52
|
wallets: wallets, copies: File.join(dir, 'copies'),
|
53
|
-
remotes: remotes, log:
|
53
|
+
remotes: remotes, log: test_log
|
54
54
|
).run(['fetch'])
|
55
55
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
56
56
|
assert_equal(1, copies.all.count)
|
data/test/commands/test_pay.rb
CHANGED
@@ -37,7 +37,7 @@ class TestPay < Minitest::Test
|
|
37
37
|
source = home.create_wallet
|
38
38
|
target = home.create_wallet
|
39
39
|
amount = Zold::Amount.new(zld: 14.95)
|
40
|
-
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log:
|
40
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
41
41
|
[
|
42
42
|
'pay', '--force', '--private-key=fixtures/id_rsa',
|
43
43
|
source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
|
@@ -52,7 +52,7 @@ class TestPay < Minitest::Test
|
|
52
52
|
source = home.create_wallet(Zold::Id::ROOT)
|
53
53
|
target = home.create_wallet
|
54
54
|
amount = Zold::Amount.new(zld: 14.95)
|
55
|
-
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log:
|
55
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
56
56
|
[
|
57
57
|
'pay', '--private-key=fixtures/id_rsa',
|
58
58
|
source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
|
@@ -73,7 +73,7 @@ class TestPay < Minitest::Test
|
|
73
73
|
'NOPREFIX', Zold::Id.new, '-'
|
74
74
|
)
|
75
75
|
)
|
76
|
-
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log:
|
76
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
77
77
|
[
|
78
78
|
'pay', '--private-key=fixtures/id_rsa',
|
79
79
|
source.id.to_s, target.id.to_s, amount.to_zld, 'here is the refund'
|
data/test/commands/test_push.rb
CHANGED
@@ -38,7 +38,7 @@ class TestPush < Minitest::Test
|
|
38
38
|
FakeHome.new.run do |home|
|
39
39
|
wallet = home.create_wallet
|
40
40
|
stub_request(:put, "http://fake-1/wallet/#{wallet.id}").to_return(status: 304)
|
41
|
-
Zold::Push.new(wallets: home.wallets, remotes: home.remotes, log:
|
41
|
+
Zold::Push.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
42
42
|
['--ignore-this-stupid-option', 'push', wallet.id.to_s]
|
43
43
|
)
|
44
44
|
end
|
@@ -59,7 +59,7 @@ class TestRemote < Minitest::Test
|
|
59
59
|
stub_request(:get, 'http://localhost:999/remotes').to_return(
|
60
60
|
status: 404
|
61
61
|
)
|
62
|
-
cmd = Zold::Remote.new(remotes: remotes, log:
|
62
|
+
cmd = Zold::Remote.new(remotes: remotes, log: test_log)
|
63
63
|
cmd.run(%w[remote clean])
|
64
64
|
cmd.run(['remote', 'add', zero.host, zero.port.to_s])
|
65
65
|
cmd.run(%w[remote add localhost 2])
|
data/test/commands/test_show.rb
CHANGED
@@ -38,7 +38,7 @@ class TestShow < Minitest::Test
|
|
38
38
|
wallets = Zold::Wallets.new(dir)
|
39
39
|
wallet = wallets.find(id)
|
40
40
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
41
|
-
balance = Zold::Show.new(wallets: wallets, log:
|
41
|
+
balance = Zold::Show.new(wallets: wallets, log: test_log).run(['show', id.to_s])
|
42
42
|
assert_equal(Zold::Amount::ZERO, balance)
|
43
43
|
end
|
44
44
|
end
|
data/test/commands/test_taxes.rb
CHANGED
@@ -59,7 +59,7 @@ class TestTaxes < Minitest::Test
|
|
59
59
|
}.to_json
|
60
60
|
)
|
61
61
|
Zold::Taxes.new(
|
62
|
-
wallets: wallets, remotes: remotes, log:
|
62
|
+
wallets: wallets, remotes: remotes, log: test_log
|
63
63
|
).run(['taxes', '--private-key=fixtures/id_rsa', id.to_s])
|
64
64
|
assert_equal(Zold::Amount.new(coins: 85_856_396_247), wallet.balance)
|
65
65
|
end
|
data/test/node/test_emission.rb
CHANGED
@@ -36,7 +36,7 @@ class EmissionTest < Minitest::Test
|
|
36
36
|
'NOPREFIX', Zold::Id::ROOT, '-'
|
37
37
|
)
|
38
38
|
)
|
39
|
-
|
39
|
+
test_log.info("Year: #{year}, Quota: #{(Zold::Emission.new(wallet).quota * 100).round(2)}%, \
|
40
40
|
Limit: #{Zold::Emission.new(wallet).limit}")
|
41
41
|
end
|
42
42
|
end
|
data/test/node/test_entrance.rb
CHANGED
@@ -40,7 +40,7 @@ class TestEntrance < Minitest::Test
|
|
40
40
|
body = FakeHome.new.run do |home|
|
41
41
|
source = home.create_wallet(sid)
|
42
42
|
target = home.create_wallet(tid)
|
43
|
-
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log:
|
43
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
44
44
|
[
|
45
45
|
'pay', '--force', '--private-key=fixtures/id_rsa',
|
46
46
|
source.id.to_s, target.id.to_s, '19.99', 'testing'
|
@@ -51,7 +51,7 @@ class TestEntrance < Minitest::Test
|
|
51
51
|
FakeHome.new.run do |home|
|
52
52
|
source = home.create_wallet(sid)
|
53
53
|
home.create_wallet(tid)
|
54
|
-
modified = Zold::Entrance.new(home.wallets, home.remotes, home.copies(source).root, 'x', log:
|
54
|
+
modified = Zold::Entrance.new(home.wallets, home.remotes, home.copies(source).root, 'x', log: test_log).push(
|
55
55
|
source.id, body
|
56
56
|
)
|
57
57
|
assert_equal(2, modified.count)
|
data/test/node/test_farm.rb
CHANGED
@@ -28,7 +28,7 @@ require_relative '../../lib/zold/node/farm'
|
|
28
28
|
class FarmTest < Minitest::Test
|
29
29
|
def test_makes_best_score_in_background
|
30
30
|
Dir.mktmpdir 'test' do |dir|
|
31
|
-
farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log:
|
31
|
+
farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
|
32
32
|
farm.start('localhost', 80, threads: 4, strength: 2)
|
33
33
|
sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
|
34
34
|
assert(farm.best[0].value > 0)
|
@@ -38,7 +38,20 @@ class FarmTest < Minitest::Test
|
|
38
38
|
|
39
39
|
def test_correct_score_from_empty_farm
|
40
40
|
Dir.mktmpdir 'test' do |dir|
|
41
|
-
farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'), log:
|
41
|
+
farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'), log: test_log)
|
42
|
+
farm.start('example.com', 8080, threads: 0, strength: 1)
|
43
|
+
score = farm.best[0]
|
44
|
+
assert_equal(0, score.value)
|
45
|
+
assert_equal('example.com', score.host)
|
46
|
+
assert_equal(8080, score.port)
|
47
|
+
farm.stop
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_pre_loads_history
|
52
|
+
Dir.mktmpdir 'test' do |dir|
|
53
|
+
cache = File.join(dir, 'cache')
|
54
|
+
farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', cache, log: test_log)
|
42
55
|
farm.start('example.com', 8080, threads: 0, strength: 1)
|
43
56
|
score = farm.best[0]
|
44
57
|
assert_equal(0, score.value)
|
data/test/node/test_front.rb
CHANGED
@@ -27,12 +27,13 @@ require_relative '../../lib/zold/score'
|
|
27
27
|
|
28
28
|
class FrontTest < Minitest::Test
|
29
29
|
def test_renders_public_pages
|
30
|
-
FakeNode.new(log:
|
30
|
+
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
31
31
|
{
|
32
32
|
'200' => [
|
33
33
|
'/robots.txt',
|
34
34
|
'/',
|
35
|
-
'/remotes'
|
35
|
+
'/remotes',
|
36
|
+
'/v'
|
36
37
|
],
|
37
38
|
'404' => [
|
38
39
|
'/this-is-absent',
|
@@ -65,7 +66,7 @@ class FrontTest < Minitest::Test
|
|
65
66
|
'4' => 'https://www.zold.io/images/logo-orange.png',
|
66
67
|
'16' => 'https://www.zold.io/images/logo-green.png'
|
67
68
|
}.each do |num, path|
|
68
|
-
|
69
|
+
test_log.info("Calculating score #{num}...")
|
69
70
|
score = Zold::Score.new(
|
70
71
|
Time.now, 'localhost', 999,
|
71
72
|
'NOPREFIX@ffffffffffffffff',
|
@@ -74,7 +75,7 @@ class FrontTest < Minitest::Test
|
|
74
75
|
num.to_i.times do
|
75
76
|
score = score.next
|
76
77
|
end
|
77
|
-
|
78
|
+
test_log.info("Score #{num} calculated.")
|
78
79
|
if score.value >= 16
|
79
80
|
assert_equal(
|
80
81
|
path, 'https://www.zold.io/images/logo-green.png',
|
data/test/test__helper.rb
CHANGED
@@ -29,18 +29,18 @@ if ENV['CI'] == 'true'
|
|
29
29
|
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
30
30
|
end
|
31
31
|
|
32
|
-
require_relative '../lib/zold/log'
|
33
|
-
|
34
32
|
require 'minitest/autorun'
|
35
33
|
require_relative '../lib/zold'
|
36
34
|
|
37
35
|
gem 'openssl'
|
38
36
|
require 'openssl'
|
39
37
|
|
40
|
-
require_relative 'support/logs'
|
41
|
-
|
42
38
|
module Minitest
|
43
39
|
class Test
|
44
|
-
|
40
|
+
def test_log
|
41
|
+
require_relative '../lib/zold/log'
|
42
|
+
# @test_log = Zold::Log::Quiet.new
|
43
|
+
@test_log ||= Zold::Log::Verbose.new
|
44
|
+
end
|
45
45
|
end
|
46
46
|
end
|
data/test/test_zold.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -379,7 +379,6 @@ files:
|
|
379
379
|
- test/node/test_entrance.rb
|
380
380
|
- test/node/test_farm.rb
|
381
381
|
- test/node/test_front.rb
|
382
|
-
- test/support/logs.rb
|
383
382
|
- test/test__helper.rb
|
384
383
|
- test/test_amount.rb
|
385
384
|
- test/test_copies.rb
|
@@ -449,7 +448,6 @@ test_files:
|
|
449
448
|
- test/node/test_entrance.rb
|
450
449
|
- test/node/test_farm.rb
|
451
450
|
- test/node/test_front.rb
|
452
|
-
- test/support/logs.rb
|
453
451
|
- test/test__helper.rb
|
454
452
|
- test/test_amount.rb
|
455
453
|
- test/test_copies.rb
|