zold 0.14.8 → 0.14.9
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 +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +0 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/appveyor.yml +8 -3
- data/features/step_definitions/steps.rb +2 -0
- data/features/support/env.rb +2 -0
- data/fixtures/merge/asserts.rb +2 -0
- data/fixtures/merge/into-no-wallet/assert.rb +2 -0
- data/fixtures/merge/random-expenses/assert.rb +2 -0
- data/fixtures/merge/simple-case/assert.rb +2 -0
- data/fixtures/scripts/_head.sh +13 -0
- data/fixtures/scripts/distribute-wallet.sh +86 -0
- data/fixtures/scripts/spread-wallets.sh +56 -0
- data/lib/zold.rb +2 -0
- data/lib/zold/amount.rb +3 -1
- data/lib/zold/atomic_file.rb +2 -0
- data/lib/zold/backtrace.rb +2 -0
- data/lib/zold/commands/alias.rb +2 -0
- data/lib/zold/commands/args.rb +2 -0
- data/lib/zold/commands/calculate.rb +5 -3
- data/lib/zold/commands/clean.rb +2 -0
- data/lib/zold/commands/create.rb +2 -0
- data/lib/zold/commands/diff.rb +2 -0
- data/lib/zold/commands/fetch.rb +7 -2
- data/lib/zold/commands/invoice.rb +2 -0
- data/lib/zold/commands/list.rb +2 -0
- data/lib/zold/commands/merge.rb +2 -0
- data/lib/zold/commands/node.rb +2 -0
- data/lib/zold/commands/pay.rb +2 -0
- data/lib/zold/commands/propagate.rb +2 -0
- data/lib/zold/commands/pull.rb +2 -0
- data/lib/zold/commands/push.rb +2 -0
- data/lib/zold/commands/remote.rb +11 -6
- data/lib/zold/commands/routines/bonuses.rb +78 -0
- data/lib/zold/commands/routines/reconnect.rb +2 -0
- data/lib/zold/commands/routines/spread.rb +2 -0
- data/lib/zold/commands/show.rb +2 -0
- data/lib/zold/commands/taxes.rb +2 -0
- data/lib/zold/copies.rb +4 -2
- data/lib/zold/hexnum.rb +2 -0
- data/lib/zold/http.rb +28 -20
- data/lib/zold/hungry_wallets.rb +2 -0
- data/lib/zold/id.rb +2 -0
- data/lib/zold/json_page.rb +2 -0
- data/lib/zold/key.rb +2 -0
- data/lib/zold/log.rb +2 -0
- data/lib/zold/metronome.rb +2 -0
- data/lib/zold/node/async_entrance.rb +3 -3
- data/lib/zold/node/emission.rb +2 -0
- data/lib/zold/node/entrance.rb +5 -2
- data/lib/zold/node/farm.rb +3 -1
- data/lib/zold/node/front.rb +4 -1
- data/lib/zold/node/safe_entrance.rb +2 -0
- data/lib/zold/node/spread_entrance.rb +2 -0
- data/lib/zold/patch.rb +2 -0
- data/lib/zold/prefixes.rb +2 -0
- data/lib/zold/remotes.rb +15 -13
- data/lib/zold/score.rb +62 -59
- data/lib/zold/signature.rb +2 -0
- data/lib/zold/tax.rb +3 -1
- data/lib/zold/txn.rb +4 -2
- data/lib/zold/type.rb +36 -0
- data/lib/zold/upgrades.rb +2 -4
- data/lib/zold/verbose_thread.rb +2 -0
- data/lib/zold/version.rb +4 -2
- data/lib/zold/version_file.rb +2 -0
- data/lib/zold/wallet.rb +4 -2
- data/lib/zold/wallets.rb +2 -0
- data/test/commands/routines/test_bonuses.rb +76 -0
- data/test/commands/routines/test_reconnect.rb +2 -0
- data/test/commands/routines/test_spread.rb +2 -0
- data/test/commands/test_alias.rb +2 -0
- data/test/commands/test_calculate.rb +2 -0
- data/test/commands/test_clean.rb +2 -0
- data/test/commands/test_create.rb +2 -0
- data/test/commands/test_diff.rb +2 -0
- data/test/commands/test_fetch.rb +2 -0
- data/test/commands/test_invoice.rb +2 -0
- data/test/commands/test_list.rb +2 -0
- data/test/commands/test_merge.rb +2 -0
- data/test/commands/test_node.rb +6 -0
- data/test/commands/test_pay.rb +2 -0
- data/test/commands/test_propagate.rb +2 -0
- data/test/commands/test_push.rb +2 -0
- data/test/commands/test_remote.rb +40 -0
- data/test/commands/test_show.rb +2 -0
- data/test/commands/test_taxes.rb +2 -0
- data/test/fake_home.rb +2 -0
- data/test/node/fake_entrance.rb +2 -0
- data/test/node/fake_node.rb +3 -1
- data/test/node/test_async_entrance.rb +2 -0
- data/test/node/test_emission.rb +2 -0
- data/test/node/test_entrance.rb +2 -0
- data/test/node/test_farm.rb +9 -7
- data/test/node/test_front.rb +15 -10
- data/test/node/test_safe_entrance.rb +2 -0
- data/test/node/test_spread_entrance.rb +2 -0
- data/test/test__helper.rb +2 -0
- data/test/test_amount.rb +2 -0
- data/test/test_atomic_file.rb +2 -0
- data/test/test_backtrace.rb +2 -0
- data/test/test_copies.rb +4 -1
- data/test/test_hexnum.rb +2 -0
- data/test/test_http.rb +5 -3
- data/test/test_id.rb +2 -0
- data/test/test_key.rb +2 -0
- data/test/test_metronome.rb +2 -0
- data/test/test_patch.rb +2 -0
- data/test/test_prefixes.rb +2 -0
- data/test/test_remotes.rb +11 -0
- data/test/test_score.rb +26 -24
- data/test/test_signature.rb +2 -0
- data/test/test_tax.rb +4 -2
- data/test/test_txn.rb +2 -0
- data/test/test_upgrades.rb +2 -0
- data/test/test_verbose_thread.rb +2 -0
- data/test/test_version.rb +2 -0
- data/test/test_wallet.rb +2 -0
- data/test/test_wallets.rb +2 -0
- data/test/test_zold.rb +2 -0
- data/test/upgrades/test_protocol_up.rb +2 -0
- data/upgrades/2.rb +2 -0
- data/upgrades/protocol_up.rb +2 -0
- data/upgrades/rename_foreign_wallets.rb +2 -0
- data/zold.gemspec +5 -1
- metadata +38 -4
data/test/commands/test_alias.rb
CHANGED
data/test/commands/test_clean.rb
CHANGED
data/test/commands/test_diff.rb
CHANGED
data/test/commands/test_fetch.rb
CHANGED
data/test/commands/test_list.rb
CHANGED
data/test/commands/test_merge.rb
CHANGED
data/test/commands/test_node.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018 Yegor Bugayenko
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -37,7 +39,11 @@ require_relative '../node/fake_node'
|
|
|
37
39
|
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
|
38
40
|
# License:: MIT
|
|
39
41
|
class TestNode < Minitest::Test
|
|
42
|
+
# @todo #306:30min This test is failing from time to time
|
|
43
|
+
# We should find a way to check that tests involved in thread concurrency
|
|
44
|
+
# are always working
|
|
40
45
|
def test_push_and_fetch
|
|
46
|
+
skip
|
|
41
47
|
FakeHome.new.run do |home|
|
|
42
48
|
FakeNode.new(log: test_log).run do |port|
|
|
43
49
|
wallets = home.wallets
|
data/test/commands/test_pay.rb
CHANGED
data/test/commands/test_push.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018 Yegor Bugayenko
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -116,4 +118,42 @@ class TestRemote < Minitest::Test
|
|
|
116
118
|
assert_equal(1, remotes.all.count)
|
|
117
119
|
end
|
|
118
120
|
end
|
|
121
|
+
|
|
122
|
+
# @todo #329:30min Verify that the nodes that are being selected are
|
|
123
|
+
# really the strongest ones. The strongest nodes are the ones with
|
|
124
|
+
# the highest score.
|
|
125
|
+
def test_select_selects_the_strongest_nodes
|
|
126
|
+
skip
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_select_respects_max_nodes_option
|
|
130
|
+
Dir.mktmpdir 'test' do |dir|
|
|
131
|
+
remotes = Zold::Remotes.new(File.join(dir, 'remotes.txt'))
|
|
132
|
+
zero = Zold::Score::ZERO
|
|
133
|
+
cmd = Zold::Remote.new(remotes: remotes, log: test_log)
|
|
134
|
+
(5000..5010).each do |port|
|
|
135
|
+
stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
|
|
136
|
+
status: 200,
|
|
137
|
+
body: {
|
|
138
|
+
version: Zold::VERSION,
|
|
139
|
+
score: zero.to_h,
|
|
140
|
+
all: [
|
|
141
|
+
{ host: 'localhost', port: port }
|
|
142
|
+
]
|
|
143
|
+
}.to_json
|
|
144
|
+
)
|
|
145
|
+
stub_request(:get, "http://localhost:#{port}/version").to_return(
|
|
146
|
+
status: 200,
|
|
147
|
+
body: {
|
|
148
|
+
version: Zold::VERSION
|
|
149
|
+
}.to_json
|
|
150
|
+
)
|
|
151
|
+
cmd.run(%W[remote add localhost #{port}])
|
|
152
|
+
end
|
|
153
|
+
assert_equal(12, remotes.all.count)
|
|
154
|
+
|
|
155
|
+
cmd.run(%w[remote select --max-nodes=5])
|
|
156
|
+
assert_equal(5, remotes.all.count)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
119
159
|
end
|
data/test/commands/test_show.rb
CHANGED
data/test/commands/test_taxes.rb
CHANGED
data/test/fake_home.rb
CHANGED
data/test/node/fake_entrance.rb
CHANGED
data/test/node/fake_node.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018 Yegor Bugayenko
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -67,7 +69,7 @@ class FakeNode
|
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
uri = "http://localhost:#{port}/"
|
|
70
|
-
while Zold::Http.new(uri).get.code == '599' && node.alive?
|
|
72
|
+
while Zold::Http.new(uri: uri, score: nil).get.code == '599' && node.alive?
|
|
71
73
|
@log.debug("Waiting for #{uri}...")
|
|
72
74
|
sleep 1
|
|
73
75
|
end
|
data/test/node/test_emission.rb
CHANGED
data/test/node/test_entrance.rb
CHANGED
data/test/node/test_farm.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018 Yegor Bugayenko
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -42,7 +44,7 @@ class FarmTest < Minitest::Test
|
|
|
42
44
|
sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
|
|
43
45
|
count = 0
|
|
44
46
|
100.times { count += farm.to_json[:best].length }
|
|
45
|
-
assert(count
|
|
47
|
+
assert(count.positive?)
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
50
|
end
|
|
@@ -63,7 +65,7 @@ class FarmTest < Minitest::Test
|
|
|
63
65
|
sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
|
|
64
66
|
score = farm.best[0]
|
|
65
67
|
assert(!score.expired?)
|
|
66
|
-
assert(score.value
|
|
68
|
+
assert(score.value.positive?)
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
end
|
|
@@ -99,8 +101,8 @@ class FarmTest < Minitest::Test
|
|
|
99
101
|
Dir.mktmpdir 'test' do |dir|
|
|
100
102
|
cache = File.join(dir, 'cache')
|
|
101
103
|
score = Zold::Score.new(
|
|
102
|
-
Time.parse('2017-07-19T21:24:51Z'),
|
|
103
|
-
'some-host', 9999, 'NOPREFIX@ffffffffffffffff', %w[13f7f01 b2b32b 4ade7e],
|
|
104
|
+
time: Time.parse('2017-07-19T21:24:51Z'),
|
|
105
|
+
host: 'some-host', port: 9999, invoice: 'NOPREFIX@ffffffffffffffff', suffixes: %w[13f7f01 b2b32b 4ade7e],
|
|
104
106
|
strength: 6
|
|
105
107
|
)
|
|
106
108
|
File.write(cache, score.to_s)
|
|
@@ -126,9 +128,9 @@ class FarmTest < Minitest::Test
|
|
|
126
128
|
'some garbage'
|
|
127
129
|
].each do |score_garbage_line|
|
|
128
130
|
valid_score = Zold::Score.new(
|
|
129
|
-
Time.parse('2017-07-19T21:24:51Z'),
|
|
130
|
-
'some-host', 9999, 'NOPREFIX@ffffffffffffffff',
|
|
131
|
-
strength: 6
|
|
131
|
+
time: Time.parse('2017-07-19T21:24:51Z'),
|
|
132
|
+
host: 'some-host', port: 9999, invoice: 'NOPREFIX@ffffffffffffffff',
|
|
133
|
+
suffixes: %w[13f7f01 b2b32b 4ade7e], strength: 6
|
|
132
134
|
)
|
|
133
135
|
File.open(file, 'w') do |f|
|
|
134
136
|
f.puts(score_garbage_line)
|
data/test/node/test_front.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018 Yegor Bugayenko
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -48,7 +50,7 @@ class FrontTest < Minitest::Test
|
|
|
48
50
|
}.each do |code, paths|
|
|
49
51
|
paths.each do |p|
|
|
50
52
|
uri = URI("http://localhost:#{port}#{p}")
|
|
51
|
-
response = Zold::Http.new(uri).get
|
|
53
|
+
response = Zold::Http.new(uri: uri, score: nil).get
|
|
52
54
|
assert_equal(
|
|
53
55
|
code, response.code,
|
|
54
56
|
"Invalid response code for #{uri}: #{response.message}"
|
|
@@ -61,9 +63,9 @@ class FrontTest < Minitest::Test
|
|
|
61
63
|
def test_updates_list_of_remotes
|
|
62
64
|
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
|
63
65
|
score = Zold::Score.new(
|
|
64
|
-
Time.now, 'localhost', port, 'NOPREFIX@ffffffffffffffff', strength: 1
|
|
66
|
+
time: Time.now, host: 'localhost', port: port, invoice: 'NOPREFIX@ffffffffffffffff', strength: 1
|
|
65
67
|
).next.next.next.next
|
|
66
|
-
response = Zold::Http.new("http://localhost:#{port}/remotes", score).get
|
|
68
|
+
response = Zold::Http.new(uri: "http://localhost:#{port}/remotes", score: score).get
|
|
67
69
|
assert_equal('200', response.code, response.body)
|
|
68
70
|
assert_equal(1, Zold::JsonPage.new(response.body).to_hash['all'].count, response.body)
|
|
69
71
|
end
|
|
@@ -78,7 +80,8 @@ class FrontTest < Minitest::Test
|
|
|
78
80
|
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
|
79
81
|
wallet = home.create_wallet
|
|
80
82
|
test_log.debug("Wallet created: #{wallet.id}")
|
|
81
|
-
response = Zold::Http.new("http://localhost:#{port}/wallet/#{wallet.id}?sync=true")
|
|
83
|
+
response = Zold::Http.new(uri: "http://localhost:#{port}/wallet/#{wallet.id}?sync=true", score: nil)
|
|
84
|
+
.put(File.read(wallet.path))
|
|
82
85
|
assert_equal('200', response.code, response.body)
|
|
83
86
|
[
|
|
84
87
|
"/wallet/#{wallet.id}",
|
|
@@ -87,7 +90,7 @@ class FrontTest < Minitest::Test
|
|
|
87
90
|
"/wallet/#{wallet.id}/key",
|
|
88
91
|
"/wallet/#{wallet.id}/mtime"
|
|
89
92
|
].each do |u|
|
|
90
|
-
res = Zold::Http.new(u).get
|
|
93
|
+
res = Zold::Http.new(uri: u, score: nil).get
|
|
91
94
|
assert_equal('200', res.code, res.body)
|
|
92
95
|
end
|
|
93
96
|
end
|
|
@@ -103,10 +106,12 @@ class FrontTest < Minitest::Test
|
|
|
103
106
|
FakeNode.new(log: test_log).run do |port|
|
|
104
107
|
FakeHome.new.run do |home|
|
|
105
108
|
wallet = home.create_wallet
|
|
106
|
-
response = Zold::Http.new("http://localhost:#{port}/wallet/#{wallet.id}?sync=true")
|
|
109
|
+
response = Zold::Http.new(uri: "http://localhost:#{port}/wallet/#{wallet.id}?sync=true", score: nil)
|
|
110
|
+
.put(File.read(wallet.path))
|
|
107
111
|
assert_equal('200', response.code, response.body)
|
|
108
112
|
3.times do
|
|
109
|
-
r = Zold::Http.new("http://localhost:#{port}/wallet/#{wallet.id}?sync=true")
|
|
113
|
+
r = Zold::Http.new(uri: "http://localhost:#{port}/wallet/#{wallet.id}?sync=true", score: nil)
|
|
114
|
+
.put(File.read(wallet.path))
|
|
110
115
|
assert_equal('304', r.code, r.body)
|
|
111
116
|
end
|
|
112
117
|
end
|
|
@@ -121,8 +126,8 @@ class FrontTest < Minitest::Test
|
|
|
121
126
|
}.each do |num, path|
|
|
122
127
|
test_log.info("Calculating score #{num}...")
|
|
123
128
|
score = Zold::Score.new(
|
|
124
|
-
Time.now, 'localhost', 999,
|
|
125
|
-
'NOPREFIX@ffffffffffffffff',
|
|
129
|
+
time: Time.now, host: 'localhost', port: 999,
|
|
130
|
+
invoice: 'NOPREFIX@ffffffffffffffff',
|
|
126
131
|
strength: 1
|
|
127
132
|
)
|
|
128
133
|
num.to_i.times do
|
|
@@ -150,7 +155,7 @@ class FrontTest < Minitest::Test
|
|
|
150
155
|
|
|
151
156
|
def test_gzip
|
|
152
157
|
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
|
153
|
-
response = Zold::Http.new(URI("http://localhost:#{port}/")).get
|
|
158
|
+
response = Zold::Http.new(uri: URI("http://localhost:#{port}/"), score: nil).get
|
|
154
159
|
assert_equal(
|
|
155
160
|
'200', response.code,
|
|
156
161
|
"Expected HTTP 200 OK: Found #{response.code}"
|
data/test/test__helper.rb
CHANGED
data/test/test_amount.rb
CHANGED
data/test/test_atomic_file.rb
CHANGED
data/test/test_backtrace.rb
CHANGED
data/test/test_copies.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018 Yegor Bugayenko
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -41,7 +43,8 @@ class TestCopies < Minitest::Test
|
|
|
41
43
|
copies.add(content('alpha'), '192.168.0.4', 80, 10)
|
|
42
44
|
copies.add(content('hello-to-delete'), '192.168.0.5', 80, 10)
|
|
43
45
|
copies.remove('192.168.0.5', 80)
|
|
44
|
-
|
|
46
|
+
copies.clean
|
|
47
|
+
assert_equal(2, copies.all.count, copies.all.map { |c| c[:name] }.join('; '))
|
|
45
48
|
assert_equal(11, copies.all.find { |c| c[:name] == '1' }[:score])
|
|
46
49
|
end
|
|
47
50
|
end
|
data/test/test_hexnum.rb
CHANGED
data/test/test_http.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018 Yegor Bugayenko
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -31,21 +33,21 @@ require_relative '../lib/zold/http'
|
|
|
31
33
|
class TestHttp < Minitest::Test
|
|
32
34
|
def test_pings_broken_uri
|
|
33
35
|
stub_request(:get, 'http://bad-host/').to_return(status: 500)
|
|
34
|
-
res = Zold::Http.new('http://bad-host/').get
|
|
36
|
+
res = Zold::Http.new(uri: 'http://bad-host/', score: nil).get
|
|
35
37
|
assert_equal('500', res.code)
|
|
36
38
|
assert_equal('', res.body)
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def test_pings_with_exception
|
|
40
42
|
stub_request(:get, 'http://exception/').to_return { raise 'Intentionally' }
|
|
41
|
-
res = Zold::Http.new('http://exception/').get
|
|
43
|
+
res = Zold::Http.new(uri: 'http://exception/', score: nil).get
|
|
42
44
|
assert_equal('599', res.code)
|
|
43
45
|
assert(res.body.include?('Intentionally'))
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
def test_pings_live_uri
|
|
47
49
|
stub_request(:get, 'http://good-host/').to_return(status: 200)
|
|
48
|
-
res = Zold::Http.new('http://good-host/').get
|
|
50
|
+
res = Zold::Http.new(uri: 'http://good-host/', score: nil).get
|
|
49
51
|
assert_equal('200', res.code)
|
|
50
52
|
end
|
|
51
53
|
end
|