zold 0.15.0 → 0.16.0
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/.gitignore +1 -0
- data/bin/zold +9 -6
- data/features/gem_package.feature +1 -1
- data/features/step_definitions/steps.rb +2 -2
- data/fixtures/merge/into-no-wallet/assert.rb +1 -1
- data/fixtures/merge/random-expenses/assert.rb +1 -1
- data/fixtures/merge/simple-case/assert.rb +1 -1
- data/lib/zold/age.rb +16 -8
- data/lib/zold/amount.rb +4 -2
- data/lib/zold/cached_wallets.rb +5 -6
- data/lib/zold/commands/clean.rb +15 -8
- data/lib/zold/commands/diff.rb +3 -3
- data/lib/zold/commands/fetch.rb +4 -4
- data/lib/zold/commands/list.rb +5 -4
- data/lib/zold/commands/merge.rb +2 -1
- data/lib/zold/commands/node.rb +14 -12
- data/lib/zold/commands/propagate.rb +2 -2
- data/lib/zold/commands/push.rb +3 -3
- data/lib/zold/commands/remove.rb +4 -1
- data/lib/zold/commands/routines/reconnect.rb +1 -0
- data/lib/zold/copies.rb +13 -14
- data/lib/zold/dir_items.rb +44 -0
- data/lib/zold/head.rb +1 -1
- data/lib/zold/key.rb +2 -2
- data/lib/zold/log.rb +2 -0
- data/lib/zold/node/async_entrance.rb +38 -28
- data/lib/zold/node/entrance.rb +4 -11
- data/lib/zold/node/farm.rb +9 -9
- data/lib/zold/node/front.rb +40 -25
- data/lib/zold/node/nodup_entrance.rb +4 -4
- data/lib/zold/node/safe_entrance.rb +2 -2
- data/lib/zold/node/spread_entrance.rb +5 -9
- data/lib/zold/node/sync_entrance.rb +2 -23
- data/lib/zold/patch.rb +2 -2
- data/lib/zold/remotes.rb +10 -6
- data/lib/zold/sync_wallets.rb +3 -22
- data/lib/zold/tree_wallets.rb +11 -6
- data/lib/zold/txns.rb +1 -1
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +14 -5
- data/lib/zold/wallets.rb +5 -4
- data/test/commands/routines/test_spread.rb +1 -1
- data/test/commands/test_alias.rb +4 -4
- data/test/commands/test_clean.rb +14 -1
- data/test/commands/test_create.rb +2 -2
- data/test/commands/test_diff.rb +5 -5
- data/test/commands/test_fetch.rb +2 -2
- data/test/commands/test_merge.rb +19 -19
- data/test/commands/test_node.rb +1 -1
- data/test/commands/test_pay.rb +7 -6
- data/test/commands/test_propagate.rb +2 -1
- data/test/commands/test_pull.rb +1 -1
- data/test/commands/test_push.rb +1 -1
- data/test/commands/test_remove.rb +57 -0
- data/test/commands/test_taxes.rb +1 -1
- data/test/fake_home.rb +11 -8
- data/test/node/fake_node.rb +2 -2
- data/test/node/test_async_entrance.rb +24 -8
- data/test/node/test_emission.rb +2 -2
- data/test/node/test_entrance.rb +8 -6
- data/test/node/test_farm.rb +1 -1
- data/test/node/test_front.rb +42 -33
- data/test/node/test_nodup_entrance.rb +2 -2
- data/test/node/test_safe_entrance.rb +5 -5
- data/test/node/test_spread_entrance.rb +3 -3
- data/test/node/test_sync_entrance.rb +1 -1
- data/test/test__helper.rb +3 -29
- data/test/test_cached_wallets.rb +1 -1
- data/test/test_copies.rb +4 -2
- data/test/test_dir_items.rb +88 -0
- data/test/test_key.rb +2 -2
- data/test/test_log.rb +38 -0
- data/test/test_patch.rb +11 -11
- data/test/test_prefixes.rb +1 -1
- data/test/test_remotes.rb +12 -6
- data/test/test_sync_wallets.rb +6 -6
- data/test/test_tax.rb +4 -4
- data/test/test_tree_wallets.rb +16 -2
- data/test/test_wallet.rb +26 -26
- data/test/test_wallets.rb +5 -2
- data/test/test_zold.rb +2 -2
- data/test/upgrades/test_protocol_up.rb +1 -1
- data/upgrades/move_wallets_into_tree.rb +1 -1
- data/upgrades/protocol_up.rb +3 -3
- data/upgrades/rename_foreign_wallets.rb +1 -1
- data/zold.gemspec +27 -25
- metadata +91 -56
data/test/node/test_emission.rb
CHANGED
@@ -29,7 +29,7 @@ require_relative '../../lib/zold/amount'
|
|
29
29
|
class EmissionTest < Minitest::Test
|
30
30
|
def test_emission
|
31
31
|
(1..10).each do |year|
|
32
|
-
FakeHome.new.run do |home|
|
32
|
+
FakeHome.new(log: test_log).run do |home|
|
33
33
|
wallet = home.create_wallet
|
34
34
|
wallet.add(
|
35
35
|
Zold::Txn.new(
|
@@ -45,7 +45,7 @@ Limit: #{Zold::Emission.new(wallet).limit}")
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_emission_passes
|
48
|
-
FakeHome.new.run do |home|
|
48
|
+
FakeHome.new(log: test_log).run do |home|
|
49
49
|
wallet = home.create_wallet(Zold::Id::ROOT)
|
50
50
|
wallet.add(
|
51
51
|
Zold::Txn.new(
|
data/test/node/test_entrance.rb
CHANGED
@@ -39,7 +39,7 @@ class TestEntrance < Minitest::Test
|
|
39
39
|
def test_pushes_wallet
|
40
40
|
sid = Zold::Id::ROOT
|
41
41
|
tid = Zold::Id.new
|
42
|
-
body = FakeHome.new.run do |home|
|
42
|
+
body = FakeHome.new(log: test_log).run do |home|
|
43
43
|
source = home.create_wallet(sid)
|
44
44
|
target = home.create_wallet(tid)
|
45
45
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
@@ -48,13 +48,15 @@ class TestEntrance < Minitest::Test
|
|
48
48
|
source.id.to_s, target.id.to_s, '19.99', 'testing'
|
49
49
|
]
|
50
50
|
)
|
51
|
-
|
51
|
+
IO.read(source.path)
|
52
52
|
end
|
53
|
-
FakeHome.new.run do |home|
|
53
|
+
FakeHome.new(log: test_log).run do |home|
|
54
54
|
source = home.create_wallet(sid)
|
55
|
-
home.create_wallet(tid)
|
55
|
+
target = home.create_wallet(tid)
|
56
56
|
e = Zold::Entrance.new(home.wallets, home.remotes, home.copies(source).root, 'x', log: test_log)
|
57
57
|
modified = e.push(source.id, body)
|
58
|
+
assert_equal(Zold::Amount.new(zld: -19.99), source.balance)
|
59
|
+
assert_equal(Zold::Amount.new(zld: 19.99), target.balance)
|
58
60
|
assert_equal(2, modified.count)
|
59
61
|
assert(modified.include?(sid))
|
60
62
|
assert(modified.include?(tid))
|
@@ -62,10 +64,10 @@ class TestEntrance < Minitest::Test
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def test_renders_json
|
65
|
-
FakeHome.new.run do |home|
|
67
|
+
FakeHome.new(log: test_log).run do |home|
|
66
68
|
wallet = home.create_wallet
|
67
69
|
e = Zold::Entrance.new(home.wallets, home.remotes, home.copies.root, 'x', log: test_log)
|
68
|
-
e.push(wallet.id,
|
70
|
+
e.push(wallet.id, IO.read(wallet.path))
|
69
71
|
assert(e.to_json[:history].include?(wallet.id.to_s))
|
70
72
|
assert(!e.to_json[:speed].negative?)
|
71
73
|
end
|
data/test/node/test_farm.rb
CHANGED
@@ -106,7 +106,7 @@ class FarmTest < Minitest::Test
|
|
106
106
|
suffixes: %w[13f7f01 b2b32b 4ade7e],
|
107
107
|
strength: 6
|
108
108
|
)
|
109
|
-
|
109
|
+
IO.write(cache, score.to_s)
|
110
110
|
farm = Zold::Farm.new('NOPREFIX4@ffffffffffffffff', cache, log: test_log)
|
111
111
|
farm.start(score.host, score.port, threads: 1, strength: score.strength) do
|
112
112
|
100.times do
|
data/test/node/test_front.rb
CHANGED
@@ -24,6 +24,7 @@ require 'minitest/autorun'
|
|
24
24
|
require 'json'
|
25
25
|
require 'time'
|
26
26
|
require 'securerandom'
|
27
|
+
require 'threads'
|
27
28
|
require_relative '../test__helper'
|
28
29
|
require_relative 'fake_node'
|
29
30
|
require_relative '../fake_home'
|
@@ -33,6 +34,10 @@ require_relative '../../lib/zold/json_page'
|
|
33
34
|
require_relative '../../lib/zold/score'
|
34
35
|
|
35
36
|
class FrontTest < Minitest::Test
|
37
|
+
def app
|
38
|
+
Zold::Front
|
39
|
+
end
|
40
|
+
|
36
41
|
def test_renders_front_json
|
37
42
|
FakeNode.new(log: test_log).run(['--no-metronome', '--network=foo', '--threads=0']) do |port|
|
38
43
|
res = Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo', score: nil).get
|
@@ -51,7 +56,7 @@ class FrontTest < Minitest::Test
|
|
51
56
|
end
|
52
57
|
|
53
58
|
def test_renders_public_pages
|
54
|
-
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
59
|
+
FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--no-metronome', '--threads=0']) do |port|
|
55
60
|
{
|
56
61
|
'200' => [
|
57
62
|
'/robots.txt',
|
@@ -66,7 +71,14 @@ class FrontTest < Minitest::Test
|
|
66
71
|
],
|
67
72
|
'404' => [
|
68
73
|
'/this-is-absent',
|
69
|
-
'/wallet/ffffeeeeddddcccc'
|
74
|
+
'/wallet/ffffeeeeddddcccc',
|
75
|
+
'/wallet/ffffeeeeddddcccc.bin',
|
76
|
+
'/wallet/ffffeeeeddddcccc.json',
|
77
|
+
'/wallet/ffffeeeeddddcccc.txt',
|
78
|
+
'/wallet/ffffeeeeddddcccc/balance',
|
79
|
+
'/wallet/ffffeeeeddddcccc/key',
|
80
|
+
'/wallet/ffffeeeeddddcccc/mtime',
|
81
|
+
'/wallet/ffffeeeeddddcccc/digest'
|
70
82
|
]
|
71
83
|
}.each do |code, paths|
|
72
84
|
paths.each do |p|
|
@@ -98,12 +110,12 @@ class FrontTest < Minitest::Test
|
|
98
110
|
end
|
99
111
|
|
100
112
|
def test_renders_wallet_pages
|
101
|
-
FakeHome.new.run do |home|
|
113
|
+
FakeHome.new(log: test_log).run do |home|
|
102
114
|
FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--standalone']) do |port|
|
103
115
|
wallet = home.create_wallet
|
104
116
|
base = "http://localhost:#{port}"
|
105
117
|
response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil)
|
106
|
-
.put(
|
118
|
+
.put(IO.read(wallet.path))
|
107
119
|
assert_equal('200', response.code, response.body)
|
108
120
|
assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
|
109
121
|
[
|
@@ -123,15 +135,15 @@ class FrontTest < Minitest::Test
|
|
123
135
|
end
|
124
136
|
|
125
137
|
def test_fetch_in_multiple_threads
|
126
|
-
FakeNode.new(log: test_log).run(['--no-metronome']) do |port|
|
127
|
-
FakeHome.new.run do |home|
|
138
|
+
FakeNode.new(log: test_log).run(['--no-metronome', '--threads=0', '--standalone']) do |port|
|
139
|
+
FakeHome.new(log: test_log).run do |home|
|
128
140
|
wallet = home.create_wallet
|
129
141
|
base = "http://localhost:#{port}"
|
130
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(
|
142
|
+
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
|
131
143
|
assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
|
132
144
|
threads = []
|
133
145
|
mutex = Mutex.new
|
134
|
-
|
146
|
+
Threads.new(6).assert(100) do
|
135
147
|
assert_equal_wait('200') do
|
136
148
|
res = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get
|
137
149
|
mutex.synchronize { threads << res.header['X-Zold-Thread'] }
|
@@ -144,18 +156,18 @@ class FrontTest < Minitest::Test
|
|
144
156
|
end
|
145
157
|
|
146
158
|
def test_pushes_twice
|
147
|
-
FakeNode.new(log: test_log).run do |port|
|
148
|
-
FakeHome.new.run do |home|
|
159
|
+
FakeNode.new(log: test_log).run(['--no-metronome', '--threads=0', '--standalone']) do |port|
|
160
|
+
FakeHome.new(log: test_log).run do |home|
|
149
161
|
wallet = home.create_wallet
|
150
162
|
base = "http://localhost:#{port}"
|
151
163
|
assert_equal(
|
152
164
|
'200',
|
153
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(
|
165
|
+
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path)).code
|
154
166
|
)
|
155
167
|
assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
|
156
168
|
3.times do
|
157
169
|
r = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil)
|
158
|
-
.put(
|
170
|
+
.put(IO.read(wallet.path))
|
159
171
|
assert_equal('304', r.code, r.body)
|
160
172
|
end
|
161
173
|
end
|
@@ -163,12 +175,12 @@ class FrontTest < Minitest::Test
|
|
163
175
|
end
|
164
176
|
|
165
177
|
def test_pushes_many_wallets
|
166
|
-
FakeNode.new(log: test_log).run do |port|
|
178
|
+
FakeNode.new(log: test_log).run(['--no-metronome', '--threads=0', '--standalone']) do |port|
|
167
179
|
base = "http://localhost:#{port}"
|
168
|
-
FakeHome.new.run do |home|
|
169
|
-
|
180
|
+
FakeHome.new(log: test_log).run do |home|
|
181
|
+
Threads.new(5).assert do
|
170
182
|
wallet = home.create_wallet
|
171
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(
|
183
|
+
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
|
172
184
|
assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
|
173
185
|
end
|
174
186
|
end
|
@@ -181,7 +193,6 @@ class FrontTest < Minitest::Test
|
|
181
193
|
'4' => 'https://www.zold.io/images/logo-orange.png',
|
182
194
|
'16' => 'https://www.zold.io/images/logo-green.png'
|
183
195
|
}.each do |num, path|
|
184
|
-
test_log.info("Calculating score #{num}...")
|
185
196
|
score = Zold::Score.new(
|
186
197
|
time: Time.now, host: 'localhost', port: 999,
|
187
198
|
invoice: 'NOPREFIX@ffffffffffffffff',
|
@@ -190,7 +201,6 @@ class FrontTest < Minitest::Test
|
|
190
201
|
num.to_i.times do
|
191
202
|
score = score.next
|
192
203
|
end
|
193
|
-
test_log.info("Score #{num} calculated.")
|
194
204
|
if score.value >= 16
|
195
205
|
assert_equal(
|
196
206
|
path, 'https://www.zold.io/images/logo-green.png',
|
@@ -225,23 +235,22 @@ class FrontTest < Minitest::Test
|
|
225
235
|
end
|
226
236
|
|
227
237
|
def test_performance
|
228
|
-
|
229
|
-
total = 50
|
238
|
+
times = Queue.new
|
230
239
|
FakeNode.new(log: test_log).run(['--threads=4', '--strength=6', '--no-metronome']) do |port|
|
231
|
-
|
240
|
+
Threads.new(10).assert(100) do
|
241
|
+
start = Time.now
|
232
242
|
Zold::Http.new(uri: URI("http://localhost:#{port}/"), score: nil).get
|
243
|
+
times << Time.now - start
|
233
244
|
end
|
234
245
|
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
def app
|
239
|
-
Zold::Front
|
246
|
+
all = []
|
247
|
+
all << times.pop(true) until times.empty?
|
248
|
+
test_log.info("Average response time is #{all.inject(&:+) / all.count}")
|
240
249
|
end
|
241
250
|
|
242
251
|
def test_headers_are_being_set_correctly
|
243
252
|
Time.stub :now, Time.at(0) do
|
244
|
-
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
253
|
+
FakeNode.new(log: test_log).run(['--no-metronome', '--threads=0', '--ignore-score-weakness']) do |port|
|
245
254
|
response = Zold::Http.new(uri: URI("http://localhost:#{port}/"), score: nil).get
|
246
255
|
assert_equal('no-cache', response.header['Cache-Control'])
|
247
256
|
assert_equal('close', response.header['Connection'])
|
@@ -273,7 +282,7 @@ class FrontTest < Minitest::Test
|
|
273
282
|
end
|
274
283
|
|
275
284
|
def test_default_alias_parameter
|
276
|
-
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
285
|
+
FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--no-metronome']) do |port|
|
277
286
|
uri = URI("http://localhost:#{port}/")
|
278
287
|
response = Zold::Http.new(uri: uri, score: nil).get
|
279
288
|
assert_match(
|
@@ -295,17 +304,17 @@ class FrontTest < Minitest::Test
|
|
295
304
|
end
|
296
305
|
|
297
306
|
def test_push_fetch_in_multiple_threads
|
298
|
-
key = Zold::Key.new(text:
|
299
|
-
FakeNode.new(log: test_log).run do |port|
|
300
|
-
FakeHome.new.run do |home|
|
307
|
+
key = Zold::Key.new(text: IO.read('fixtures/id_rsa'))
|
308
|
+
FakeNode.new(log: test_log).run(['--no-metronome', '--threads=0', '--standalone']) do |port|
|
309
|
+
FakeHome.new(log: test_log).run do |home|
|
301
310
|
wallet = home.create_wallet(Zold::Id::ROOT)
|
302
311
|
base = "http://localhost:#{port}"
|
303
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(
|
312
|
+
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
|
304
313
|
assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
|
305
314
|
cycles = 50
|
306
315
|
cycles.times do
|
307
316
|
wallet.sub(Zold::Amount.new(coins: 10), "NOPREFIX@#{Zold::Id.new}", key)
|
308
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(
|
317
|
+
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
|
309
318
|
assert_equal('200', Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code)
|
310
319
|
end
|
311
320
|
assert_equal_wait(-10 * cycles) do
|
@@ -33,10 +33,10 @@ require_relative 'fake_entrance'
|
|
33
33
|
# License:: MIT
|
34
34
|
class TestAsyncEntrance < Minitest::Test
|
35
35
|
def test_ignores_dup
|
36
|
-
FakeHome.new.run do |home|
|
36
|
+
FakeHome.new(log: test_log).run do |home|
|
37
37
|
wallet = home.create_wallet
|
38
38
|
Zold::NoDupEntrance.new(RealEntrance.new, home.wallets, log: test_log).start do |e|
|
39
|
-
assert(e.push(wallet.id,
|
39
|
+
assert(e.push(wallet.id, IO.read(wallet.path)).empty?)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -35,23 +35,23 @@ require_relative 'fake_entrance'
|
|
35
35
|
# License:: MIT
|
36
36
|
class TestSafeEntrance < Minitest::Test
|
37
37
|
def test_rejects_wallet_with_negative_balance
|
38
|
-
FakeHome.new.run do |home|
|
38
|
+
FakeHome.new(log: test_log).run do |home|
|
39
39
|
wallet = home.create_wallet
|
40
40
|
amount = Zold::Amount.new(zld: 39.99)
|
41
41
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
42
42
|
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
43
43
|
assert_raises StandardError do
|
44
|
-
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id,
|
44
|
+
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id, IO.read(wallet.path))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_rejects_wallet_with_wrong_network
|
50
|
-
FakeHome.new.run do |home|
|
51
|
-
wallet = Zold::Wallet.new(File.join(home.dir, 'wallet'))
|
50
|
+
FakeHome.new(log: test_log).run do |home|
|
51
|
+
wallet = Zold::Wallet.new(File.join(home.dir, 'wallet.z'))
|
52
52
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'), network: 'someothernetwork')
|
53
53
|
assert_raises StandardError do
|
54
|
-
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id,
|
54
|
+
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id, IO.read(wallet.path))
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -35,7 +35,7 @@ require_relative 'fake_entrance'
|
|
35
35
|
# License:: MIT
|
36
36
|
class TestSpreadEntrance < Minitest::Test
|
37
37
|
def test_renders_json
|
38
|
-
FakeHome.new.run do |home|
|
38
|
+
FakeHome.new(log: test_log).run do |home|
|
39
39
|
wallet = home.create_wallet(Zold::Id.new)
|
40
40
|
Zold::SpreadEntrance.new(
|
41
41
|
Zold::Entrance.new(home.wallets, home.remotes, home.copies(wallet).root, 'x', log: test_log),
|
@@ -47,13 +47,13 @@ class TestSpreadEntrance < Minitest::Test
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_ignores_duplicates
|
50
|
-
FakeHome.new.run do |home|
|
50
|
+
FakeHome.new(log: test_log).run do |home|
|
51
51
|
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
52
52
|
wallet = home.create_wallet
|
53
53
|
remotes = home.remotes
|
54
54
|
remotes.add('localhost', port)
|
55
55
|
Zold::SpreadEntrance.new(FakeEntrance.new, home.wallets, remotes, 'x', log: test_log).start do |e|
|
56
|
-
8.times { e.push(wallet.id,
|
56
|
+
8.times { e.push(wallet.id, IO.read(wallet.path)) }
|
57
57
|
assert(e.to_json[:modified] < 2, "It's too big: #{e.to_json[:modified]}")
|
58
58
|
end
|
59
59
|
end
|
@@ -32,7 +32,7 @@ require_relative 'fake_entrance'
|
|
32
32
|
# License:: MIT
|
33
33
|
class TestSyncEntrance < Minitest::Test
|
34
34
|
def test_renders_json
|
35
|
-
FakeHome.new.run do
|
35
|
+
FakeHome.new(log: test_log).run do
|
36
36
|
Zold::SyncEntrance.new(FakeEntrance.new, log: test_log).start do |e|
|
37
37
|
assert(!e.to_json.nil?)
|
38
38
|
end
|
data/test/test__helper.rb
CHANGED
@@ -53,40 +53,14 @@ module Minitest
|
|
53
53
|
end
|
54
54
|
sleep 1
|
55
55
|
sec = Time.now - start
|
56
|
-
|
56
|
+
require_relative '../lib/zold/age'
|
57
|
+
raise "'#{actual}' is not equal to '#{expected}' even after #{Zold::Age.new(start)} of waiting" if sec > max
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
60
|
-
def assert_in_threads(threads: Concurrent.processor_count * 8, loops: 0)
|
61
|
-
done = Concurrent::AtomicFixnum.new
|
62
|
-
cycles = Concurrent::AtomicFixnum.new
|
63
|
-
pool = Concurrent::FixedThreadPool.new(threads)
|
64
|
-
latch = Concurrent::CountDownLatch.new(1)
|
65
|
-
threads.times do |t|
|
66
|
-
pool.post do
|
67
|
-
Thread.current.name = "assert-thread-#{t}"
|
68
|
-
latch.wait(10)
|
69
|
-
loop do
|
70
|
-
Zold::VerboseThread.new(test_log).run(true) do
|
71
|
-
yield t
|
72
|
-
end
|
73
|
-
cycles.increment
|
74
|
-
break if cycles.value > loops
|
75
|
-
end
|
76
|
-
done.increment
|
77
|
-
end
|
78
|
-
end
|
79
|
-
latch.count_down
|
80
|
-
pool.shutdown
|
81
|
-
pool.kill unless pool.wait_for_termination(10)
|
82
|
-
assert_equal(threads, done.value)
|
83
|
-
end
|
84
|
-
|
85
61
|
def test_log
|
86
62
|
require_relative '../lib/zold/log'
|
87
|
-
@test_log
|
88
|
-
@test_log = Zold::Log::Quiet.new if ENV['TEST_QUIET_LOG']
|
89
|
-
Zold::Log::Sync.new(@test_log)
|
63
|
+
@test_log ||= Zold::Log::Sync.new(ENV['TEST_QUIET_LOG'] ? Zold::Log::Quiet.new : Zold::Log::Verbose.new)
|
90
64
|
end
|
91
65
|
|
92
66
|
class TestLogger
|
data/test/test_cached_wallets.rb
CHANGED
@@ -35,7 +35,7 @@ require_relative '../lib/zold/amount'
|
|
35
35
|
# License:: MIT
|
36
36
|
class TestCachedWallets < Minitest::Test
|
37
37
|
def test_adds_wallet
|
38
|
-
FakeHome.new.run do |home|
|
38
|
+
FakeHome.new(log: test_log).run do |home|
|
39
39
|
wallets = Zold::CachedWallets.new(home.wallets)
|
40
40
|
id = Zold::Id.new
|
41
41
|
first = nil
|
data/test/test_copies.rb
CHANGED
@@ -26,7 +26,9 @@ require 'time'
|
|
26
26
|
require_relative 'fake_home'
|
27
27
|
require_relative 'test__helper'
|
28
28
|
require_relative '../lib/zold/id'
|
29
|
+
require_relative '../lib/zold/age'
|
29
30
|
require_relative '../lib/zold/copies'
|
31
|
+
require_relative '../lib/zold/dir_items'
|
30
32
|
require_relative '../lib/zold/wallet'
|
31
33
|
|
32
34
|
# Copies test.
|
@@ -121,12 +123,12 @@ class TestCopies < Minitest::Test
|
|
121
123
|
|
122
124
|
def content(text)
|
123
125
|
id = Zold::Id.new('aaaabbbbccccdddd')
|
124
|
-
FakeHome.new.run do |home|
|
126
|
+
FakeHome.new(log: test_log).run do |home|
|
125
127
|
wallet = home.create_wallet(id)
|
126
128
|
amount = Zold::Amount.new(zld: 1.99)
|
127
129
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
128
130
|
wallet.sub(amount, 'NOPREFIX@0000111122223333', key, text, time: Time.parse('2018-01-01T01:01:01Z'))
|
129
|
-
|
131
|
+
IO.read(wallet.path)
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'minitest/autorun'
|
24
|
+
require 'tmpdir'
|
25
|
+
require 'threads'
|
26
|
+
require_relative 'test__helper'
|
27
|
+
require_relative '../lib/zold/age'
|
28
|
+
require_relative '../lib/zold/dir_items'
|
29
|
+
|
30
|
+
# DirItems test.
|
31
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
33
|
+
# License:: MIT
|
34
|
+
class TestDirItems < Minitest::Test
|
35
|
+
def test_intensive_write_in_threads
|
36
|
+
Dir.mktmpdir do |dir|
|
37
|
+
file = File.join(dir, 'hey.txt')
|
38
|
+
Thread.start do
|
39
|
+
loop do
|
40
|
+
Zold::DirItems.new(dir).fetch
|
41
|
+
end
|
42
|
+
end
|
43
|
+
Threads.new(100).assert do
|
44
|
+
start = Time.now
|
45
|
+
File.open(file, 'w+') do |f|
|
46
|
+
f.write('test')
|
47
|
+
end
|
48
|
+
test_log.debug("Saved in #{Zold::Age.new(start)}")
|
49
|
+
sleep 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_lists_empty_dir
|
55
|
+
Dir.mktmpdir do |dir|
|
56
|
+
assert_equal(0, Zold::DirItems.new(File.join(dir, 'a/b/c')).fetch.count)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_lists_recursively
|
61
|
+
Dir.mktmpdir do |dir|
|
62
|
+
files = ['test1.txt', 'a/b/c/text', 'd/e/f/text', 'a/b/c/zz/text.1.2.3']
|
63
|
+
files.each do |f|
|
64
|
+
path = File.join(dir, f)
|
65
|
+
FileUtils.mkdir_p(File.dirname(path))
|
66
|
+
FileUtils.touch(path)
|
67
|
+
end
|
68
|
+
found = Zold::DirItems.new(dir).fetch
|
69
|
+
assert_equal(files.count, found.count)
|
70
|
+
files.each do |f|
|
71
|
+
assert(found.include?(f), f)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_lists_non_recursively
|
77
|
+
Dir.mktmpdir do |dir|
|
78
|
+
files = ['1.txt', 'a/1.txt', 'a/b/1.txt', 'a/b/c/1.txt']
|
79
|
+
files.each do |f|
|
80
|
+
path = File.join(dir, f)
|
81
|
+
FileUtils.mkdir_p(File.dirname(path))
|
82
|
+
FileUtils.touch(path)
|
83
|
+
end
|
84
|
+
found = Zold::DirItems.new(dir).fetch(recursive: false)
|
85
|
+
assert_equal(1, found.count)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|