zold 0.31.9 → 0.32.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/.0pdd.yml +2 -19
- data/.github/typos.toml +11 -0
- data/.github/workflows/actionlint.yml +5 -21
- data/.github/workflows/bashate.yml +25 -0
- data/.github/workflows/codecov.yml +11 -24
- data/.github/workflows/copyrights.yml +6 -21
- data/.github/workflows/hadolint.yml +14 -0
- data/.github/workflows/markdown-lint.yml +19 -0
- data/.github/workflows/pdd.yml +5 -20
- data/.github/workflows/rake.yml +8 -22
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/shellcheck.yml +19 -0
- data/.github/workflows/typos.yml +21 -0
- data/.github/workflows/xcop.yml +5 -20
- data/.github/workflows/yamllint.yml +5 -20
- data/.gitignore +9 -6
- data/.rubocop.yml +16 -20
- data/.ruby-version +1 -1
- data/.rultor.yml +6 -22
- data/Dockerfile +11 -27
- data/Gemfile +21 -33
- data/Gemfile.lock +185 -130
- data/Guardfile +0 -0
- data/INSTALL.md +80 -59
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +183 -154
- data/REUSE.toml +40 -0
- data/Rakefile +4 -38
- data/bin/zold +7 -37
- data/cucumber.yml +2 -19
- data/deploy.sh +4 -22
- data/features/cli.feature +2 -0
- data/features/gem_package.feature +2 -0
- data/features/step_definitions/steps.rb +2 -19
- data/features/support/env.rb +2 -19
- data/fixtures/merge/asserts.rb +3 -19
- data/fixtures/merge/into_no_wallet/assert.rb +2 -19
- data/fixtures/merge/legacy_negatives_stay/assert.rb +2 -19
- data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/scores.zc +1 -1
- data/fixtures/merge/missed_wallets/0123456789abcdef.z +0 -2
- data/fixtures/merge/missed_wallets/assert.rb +2 -19
- data/fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc +1 -1
- data/fixtures/merge/negative_overwriting/assert.rb +2 -19
- data/fixtures/merge/negatives_in_between/0123456789abcdef.z +0 -1
- data/fixtures/merge/negatives_in_between/assert.rb +2 -19
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc +0 -1
- data/fixtures/merge/negatives_in_between/opts +1 -1
- data/fixtures/merge/random_expenses/assert.rb +2 -19
- data/fixtures/merge/random_expenses/opts +1 -1
- data/fixtures/merge/simple_case/assert.rb +2 -19
- data/fixtures/merge/simple_case/opts +1 -1
- data/fixtures/merge/unconfirmed_income/assert.rb +2 -19
- data/fixtures/scripts/_head.sh +16 -33
- data/fixtures/scripts/calculate-scores.sh +3 -20
- data/fixtures/scripts/distribute-wallet.sh +26 -43
- data/fixtures/scripts/print-helps.sh +5 -23
- data/fixtures/scripts/pull-on-start.sh +12 -29
- data/fixtures/scripts/push-and-pull.sh +10 -27
- data/fixtures/scripts/redeploy-on-upgrade.sh +18 -34
- data/fixtures/scripts/spread-wallets.sh +24 -40
- data/lib/zold/age.rb +3 -20
- data/lib/zold/amount.rb +3 -20
- data/lib/zold/cached_wallets.rb +3 -20
- data/lib/zold/commands/alias.rb +4 -21
- data/lib/zold/commands/args.rb +4 -21
- data/lib/zold/commands/calculate.rb +5 -22
- data/lib/zold/commands/clean.rb +6 -23
- data/lib/zold/commands/create.rb +5 -22
- data/lib/zold/commands/diff.rb +5 -22
- data/lib/zold/commands/fetch.rb +6 -23
- data/lib/zold/commands/invoice.rb +5 -22
- data/lib/zold/commands/list.rb +5 -22
- data/lib/zold/commands/merge.rb +7 -24
- data/lib/zold/commands/next.rb +5 -22
- data/lib/zold/commands/node.rb +4 -21
- data/lib/zold/commands/pay.rb +6 -23
- data/lib/zold/commands/propagate.rb +5 -22
- data/lib/zold/commands/pull.rb +5 -22
- data/lib/zold/commands/push.rb +5 -22
- data/lib/zold/commands/remote.rb +7 -24
- data/lib/zold/commands/remove.rb +5 -22
- data/lib/zold/commands/routines/audit.rb +4 -21
- data/lib/zold/commands/routines/gc.rb +6 -23
- data/lib/zold/commands/routines/reconcile.rb +5 -22
- data/lib/zold/commands/routines/reconnect.rb +4 -21
- data/lib/zold/commands/routines/retire.rb +4 -21
- data/lib/zold/commands/routines/spread.rb +5 -22
- data/lib/zold/commands/routines.rb +3 -20
- data/lib/zold/commands/show.rb +5 -22
- data/lib/zold/commands/taxes.rb +5 -22
- data/lib/zold/commands/thread_badge.rb +3 -20
- data/lib/zold/copies.rb +6 -25
- data/lib/zold/dir_items.rb +3 -20
- data/lib/zold/endless.rb +5 -22
- data/lib/zold/gem.rb +3 -20
- data/lib/zold/hands.rb +6 -23
- data/lib/zold/head.rb +4 -21
- data/lib/zold/hexnum.rb +3 -20
- data/lib/zold/http.rb +3 -20
- data/lib/zold/hungry_wallets.rb +6 -23
- data/lib/zold/id.rb +3 -20
- data/lib/zold/json_page.rb +5 -22
- data/lib/zold/key.rb +3 -20
- data/lib/zold/metronome.rb +5 -22
- data/lib/zold/node/async_entrance.rb +6 -23
- data/lib/zold/node/entrance.rb +7 -24
- data/lib/zold/node/farm.rb +5 -22
- data/lib/zold/node/farmers.rb +15 -32
- data/lib/zold/node/front.rb +6 -23
- data/lib/zold/node/journaled_pipeline.rb +8 -25
- data/lib/zold/node/nodup_entrance.rb +6 -23
- data/lib/zold/node/nospam_entrance.rb +6 -23
- data/lib/zold/node/pipeline.rb +6 -23
- data/lib/zold/node/safe_entrance.rb +4 -22
- data/lib/zold/node/soft_error.rb +3 -20
- data/lib/zold/node/spread_entrance.rb +5 -22
- data/lib/zold/node/sync_entrance.rb +5 -22
- data/lib/zold/node/trace.rb +3 -20
- data/lib/zold/patch.rb +6 -23
- data/lib/zold/prefixes.rb +3 -20
- data/lib/zold/remotes.rb +5 -22
- data/lib/zold/signature.rb +3 -20
- data/lib/zold/size.rb +3 -20
- data/lib/zold/sync_wallets.rb +5 -22
- data/lib/zold/tax.rb +4 -21
- data/lib/zold/thread_pool.rb +4 -21
- data/lib/zold/tree_wallets.rb +3 -20
- data/lib/zold/txn.rb +4 -21
- data/lib/zold/txns.rb +4 -21
- data/lib/zold/upgrades.rb +4 -21
- data/lib/zold/verbose_thread.rb +5 -22
- data/lib/zold/version.rb +4 -21
- data/lib/zold/version_file.rb +4 -21
- data/lib/zold/wallet.rb +6 -23
- data/lib/zold/wallets.rb +5 -23
- data/lib/zold.rb +3 -21
- data/resources/banned-wallets.log +6 -6
- data/test/commands/routines/test_audit.rb +3 -21
- data/test/commands/routines/test_gc.rb +3 -21
- data/test/commands/routines/test_reconcile.rb +3 -21
- data/test/commands/routines/test_reconnect.rb +3 -21
- data/test/commands/routines/test_retire.rb +3 -21
- data/test/commands/test_alias.rb +2 -20
- data/test/commands/test_calculate.rb +5 -23
- data/test/commands/test_clean.rb +5 -23
- data/test/commands/test_create.rb +6 -24
- data/test/commands/test_diff.rb +4 -22
- data/test/commands/test_fetch.rb +3 -21
- data/test/commands/test_invoice.rb +3 -21
- data/test/commands/test_list.rb +3 -21
- data/test/commands/test_merge.rb +12 -35
- data/test/commands/test_node.rb +3 -21
- data/test/commands/test_pay.rb +5 -23
- data/test/commands/test_propagate.rb +6 -24
- data/test/commands/test_pull.rb +4 -22
- data/test/commands/test_push.rb +3 -21
- data/test/commands/test_remote.rb +10 -28
- data/test/commands/test_remove.rb +7 -25
- data/test/commands/test_show.rb +3 -21
- data/test/commands/test_taxes.rb +5 -23
- data/test/fake_home.rb +5 -22
- data/test/node/fake_entrance.rb +3 -20
- data/test/node/fake_node.rb +5 -22
- data/test/node/test_async_entrance.rb +3 -21
- data/test/node/test_entrance.rb +7 -25
- data/test/node/test_farm.rb +15 -33
- data/test/node/test_farmers.rb +3 -21
- data/test/node/test_front.rb +22 -42
- data/test/node/test_nodup_entrance.rb +4 -22
- data/test/node/test_nospam_entrance.rb +6 -24
- data/test/node/test_safe_entrance.rb +3 -21
- data/test/node/test_spread_entrance.rb +4 -22
- data/test/node/test_sync_entrance.rb +4 -22
- data/test/node/test_trace.rb +4 -22
- data/test/test__helper.rb +32 -31
- data/test/test_age.rb +5 -23
- data/test/test_amount.rb +15 -34
- data/test/test_cached_wallets.rb +3 -21
- data/test/test_copies.rb +10 -28
- data/test/test_dir_items.rb +4 -22
- data/test/test_gem.rb +3 -21
- data/test/test_hands.rb +3 -21
- data/test/test_hexnum.rb +3 -21
- data/test/test_http.rb +9 -27
- data/test/test_hungry_wallets.rb +6 -24
- data/test/test_id.rb +10 -28
- data/test/test_json_page.rb +3 -21
- data/test/test_key.rb +5 -23
- data/test/test_metronome.rb +6 -24
- data/test/test_patch.rb +10 -28
- data/test/test_prefixes.rb +3 -21
- data/test/test_remotes.rb +17 -35
- data/test/test_signature.rb +3 -21
- data/test/test_size.rb +3 -21
- data/test/test_sync_wallets.rb +3 -21
- data/test/test_tax.rb +6 -24
- data/test/test_thread_pool.rb +6 -24
- data/test/test_tree_wallets.rb +4 -22
- data/test/test_txn.rb +3 -21
- data/test/test_upgrades.rb +3 -21
- data/test/test_verbose_thread.rb +6 -24
- data/test/test_version.rb +2 -20
- data/test/test_wallet.rb +15 -33
- data/test/test_wallets.rb +4 -22
- data/test/test_zold.rb +7 -25
- data/test/upgrades/test_delete_banned_wallets.rb +4 -22
- data/test/upgrades/test_protocol_up.rb +3 -21
- data/upgrades/2.rb +3 -20
- data/upgrades/delete_banned_wallets.rb +3 -20
- data/upgrades/move_wallets_into_tree.rb +3 -20
- data/upgrades/protocol_up.rb +3 -20
- data/upgrades/rename_foreign_wallets.rb +3 -20
- data/views/journal.haml +25 -0
- data/views/layout.haml +25 -0
- data/views/wallet.haml +25 -0
- data/zold.gemspec +5 -21
- metadata +33 -15
- data/.simplecov +0 -36
- data/lib/zold/log.rb +0 -139
- data/test/test_log.rb +0 -49
data/test/node/test_front.rb
CHANGED
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require 'json'
|
|
25
7
|
require 'time'
|
|
26
8
|
require 'securerandom'
|
|
@@ -62,14 +44,14 @@ class FrontTest < Zold::Test
|
|
|
62
44
|
assert_equal(Zold::PROTOCOL, json['protocol'])
|
|
63
45
|
assert_equal('foo', json['network'])
|
|
64
46
|
assert_equal('zold-io/zold', json['repo'])
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
assert_predicate(json['pid'], :positive?, json)
|
|
48
|
+
assert_predicate(json['cpus'], :positive?, json)
|
|
49
|
+
refute_predicate(json['journal'], :negative?, json)
|
|
50
|
+
assert_predicate(json['memory'], :positive?, json)
|
|
51
|
+
refute_predicate(json['load'], :negative?, json)
|
|
52
|
+
assert_predicate(json['wallets'], :positive?, json)
|
|
53
|
+
assert_predicate(json['remotes'], :zero?, json)
|
|
54
|
+
assert_predicate(json['nscore'], :zero?, json)
|
|
73
55
|
end
|
|
74
56
|
end
|
|
75
57
|
|
|
@@ -182,7 +164,7 @@ class FrontTest < Zold::Test
|
|
|
182
164
|
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
|
183
165
|
response = Zold::Http.new(uri: "#{base}/wallets").get
|
|
184
166
|
assert_equal(200, response.status, response.body)
|
|
185
|
-
|
|
167
|
+
assert_includes(response.body.to_s.split("\n"), wallet.id.to_s, response.body)
|
|
186
168
|
end
|
|
187
169
|
end
|
|
188
170
|
end
|
|
@@ -203,7 +185,7 @@ class FrontTest < Zold::Test
|
|
|
203
185
|
res.status
|
|
204
186
|
end
|
|
205
187
|
end
|
|
206
|
-
|
|
188
|
+
assert_operator(threads.uniq.count, :>, 1)
|
|
207
189
|
end
|
|
208
190
|
end
|
|
209
191
|
end
|
|
@@ -255,17 +237,17 @@ class FrontTest < Zold::Test
|
|
|
255
237
|
end
|
|
256
238
|
if score.value >= 16
|
|
257
239
|
assert_equal(
|
|
258
|
-
|
|
240
|
+
'https://www.zold.io/images/logo-green.png', path,
|
|
259
241
|
"Expected #{path} for score #{score.value}"
|
|
260
242
|
)
|
|
261
243
|
elsif score.value >= 4
|
|
262
244
|
assert_equal(
|
|
263
|
-
|
|
245
|
+
'https://www.zold.io/images/logo-orange.png', path,
|
|
264
246
|
"Expected #{path} for score #{score.value}"
|
|
265
247
|
)
|
|
266
248
|
else
|
|
267
249
|
assert_equal(
|
|
268
|
-
|
|
250
|
+
'https://www.zold.io/images/logo-red.png', path,
|
|
269
251
|
"Expected #{path} for score #{score.value}"
|
|
270
252
|
)
|
|
271
253
|
end
|
|
@@ -291,12 +273,12 @@ class FrontTest < Zold::Test
|
|
|
291
273
|
end
|
|
292
274
|
all = []
|
|
293
275
|
all << times.pop(true) until times.empty?
|
|
294
|
-
fake_log.info("Average response time is #{all.
|
|
276
|
+
fake_log.info("Average response time is #{all.sum / all.count}")
|
|
295
277
|
end
|
|
296
278
|
|
|
297
279
|
# The score exposed via the HTTP header must be reduced to the value of 16.
|
|
298
280
|
# We need this in order to optimize the amount of data we transfer in each
|
|
299
|
-
# HTTP request. This value is enough to identify a
|
|
281
|
+
# HTTP request. This value is enough to identify a valuable node, and filter
|
|
300
282
|
# out those that are too weak.
|
|
301
283
|
def test_score_is_reduced
|
|
302
284
|
FakeNode.new(log: fake_log).run(opts('--threads=1', '--strength=1', '--farmer=plain')) do |port|
|
|
@@ -306,7 +288,7 @@ class FrontTest < Zold::Test
|
|
|
306
288
|
scores << Zold::Score.parse(res.headers[Zold::Http::SCORE_HEADER]).value
|
|
307
289
|
sleep(0.1)
|
|
308
290
|
end
|
|
309
|
-
|
|
291
|
+
assert_operator(scores.uniq.sort.reverse[0], :<=, Zold::Front::MIN_SCORE)
|
|
310
292
|
end
|
|
311
293
|
end
|
|
312
294
|
|
|
@@ -319,7 +301,7 @@ class FrontTest < Zold::Test
|
|
|
319
301
|
assert_equal(app.settings.protocol.to_s, response.headers[Zold::Http::PROTOCOL_HEADER])
|
|
320
302
|
assert_equal('*', response.headers['Access-Control-Allow-Origin'])
|
|
321
303
|
assert(response.headers['X-Zold-Milliseconds'])
|
|
322
|
-
|
|
304
|
+
refute_nil(response.headers[Zold::Http::SCORE_HEADER])
|
|
323
305
|
end
|
|
324
306
|
end
|
|
325
307
|
|
|
@@ -356,7 +338,7 @@ class FrontTest < Zold::Test
|
|
|
356
338
|
Zold::Http.new(uri: uri).get
|
|
357
339
|
end
|
|
358
340
|
end
|
|
359
|
-
|
|
341
|
+
assert_includes(exception.message, 'should be a 4 to 16 char long', exception.message)
|
|
360
342
|
end
|
|
361
343
|
|
|
362
344
|
def test_push_fetch_in_multiple_threads
|
|
@@ -384,10 +366,8 @@ class FrontTest < Zold::Test
|
|
|
384
366
|
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
385
367
|
uri = URI("http://localhost:#{port}/")
|
|
386
368
|
response = Zold::Http.new(uri: uri).get
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
response.body
|
|
390
|
-
)
|
|
369
|
+
hash = Zold::JsonPage.new(response.body).to_hash
|
|
370
|
+
assert_includes(hash.keys, 'checksum')
|
|
391
371
|
end
|
|
392
372
|
end
|
|
393
373
|
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative '../fake_home'
|
|
25
7
|
require_relative '../test__helper'
|
|
26
8
|
require_relative '../../lib/zold/id'
|
|
@@ -29,14 +11,14 @@ require_relative 'fake_entrance'
|
|
|
29
11
|
|
|
30
12
|
# NoDupEntrance test.
|
|
31
13
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
32
|
-
# Copyright:: Copyright (c) 2018-
|
|
14
|
+
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
33
15
|
# License:: MIT
|
|
34
16
|
class TestNoDupEntrance < Zold::Test
|
|
35
17
|
def test_ignores_dup
|
|
36
18
|
FakeHome.new(log: fake_log).run do |home|
|
|
37
19
|
wallet = home.create_wallet
|
|
38
20
|
Zold::NoDupEntrance.new(RealEntrance.new, home.wallets, log: fake_log).start do |e|
|
|
39
|
-
|
|
21
|
+
assert_empty(e.push(wallet.id, File.read(wallet.path)))
|
|
40
22
|
end
|
|
41
23
|
end
|
|
42
24
|
end
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative '../test__helper'
|
|
25
7
|
require_relative '../../lib/zold/id'
|
|
26
8
|
require_relative '../../lib/zold/node/nospam_entrance'
|
|
@@ -28,16 +10,16 @@ require_relative 'fake_entrance'
|
|
|
28
10
|
|
|
29
11
|
# NoSpamEntrance test.
|
|
30
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2018-
|
|
13
|
+
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
32
14
|
# License:: MIT
|
|
33
15
|
class TestNoSpamEntrance < Zold::Test
|
|
34
16
|
def test_ignores_spam
|
|
35
17
|
Zold::NoSpamEntrance.new(RealEntrance.new, log: fake_log).start do |e|
|
|
36
18
|
id = Zold::Id.new
|
|
37
19
|
content = 'hello'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
20
|
+
refute_empty(e.push(id, content))
|
|
21
|
+
assert_empty(e.push(id, content))
|
|
22
|
+
assert_empty(e.push(id, content))
|
|
41
23
|
end
|
|
42
24
|
end
|
|
43
25
|
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative '../fake_home'
|
|
25
7
|
require_relative '../test__helper'
|
|
26
8
|
require_relative '../../lib/zold/wallet'
|
|
@@ -32,7 +14,7 @@ require_relative 'fake_entrance'
|
|
|
32
14
|
|
|
33
15
|
# SafeEntrance test.
|
|
34
16
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-
|
|
17
|
+
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
36
18
|
# License:: MIT
|
|
37
19
|
class TestSafeEntrance < Zold::Test
|
|
38
20
|
def test_rejects_wallet_with_negative_balance
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative '../fake_home'
|
|
25
7
|
require_relative 'fake_node'
|
|
26
8
|
require_relative '../test__helper'
|
|
@@ -32,7 +14,7 @@ require_relative 'fake_entrance'
|
|
|
32
14
|
|
|
33
15
|
# SpreadEntrance test.
|
|
34
16
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-
|
|
17
|
+
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
36
18
|
# License:: MIT
|
|
37
19
|
class TestSpreadEntrance < Zold::Test
|
|
38
20
|
def test_renders_json
|
|
@@ -59,7 +41,7 @@ class TestSpreadEntrance < Zold::Test
|
|
|
59
41
|
remotes.add('localhost', port)
|
|
60
42
|
Zold::SpreadEntrance.new(FakeEntrance.new, home.wallets, remotes, 'x', log: fake_log).start do |e|
|
|
61
43
|
8.times { e.push(wallet.id, File.read(wallet.path)) }
|
|
62
|
-
|
|
44
|
+
assert_operator(e.to_json[:modified], :<, 2, "It's too big: #{e.to_json[:modified]}")
|
|
63
45
|
end
|
|
64
46
|
end
|
|
65
47
|
end
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative '../fake_home'
|
|
25
7
|
require_relative '../test__helper'
|
|
26
8
|
require_relative '../../lib/zold/node/sync_entrance'
|
|
@@ -28,13 +10,13 @@ require_relative 'fake_entrance'
|
|
|
28
10
|
|
|
29
11
|
# SyncEntrance test.
|
|
30
12
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2018-
|
|
13
|
+
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
32
14
|
# License:: MIT
|
|
33
15
|
class TestSyncEntrance < Zold::Test
|
|
34
16
|
def test_renders_json
|
|
35
17
|
FakeHome.new(log: fake_log).run do |home|
|
|
36
18
|
Zold::SyncEntrance.new(FakeEntrance.new, File.join(home.dir, 'x'), log: fake_log).start do |e|
|
|
37
|
-
|
|
19
|
+
refute_nil(e.to_json)
|
|
38
20
|
end
|
|
39
21
|
end
|
|
40
22
|
end
|
data/test/node/test_trace.rb
CHANGED
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative '../test__helper'
|
|
25
7
|
require_relative '../../lib/zold/node/trace'
|
|
26
8
|
|
|
@@ -30,7 +12,7 @@ class TraceTest < Zold::Test
|
|
|
30
12
|
trace.error('This should not be visible')
|
|
31
13
|
trace.error('How are you, друг?')
|
|
32
14
|
trace.error('Works?')
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
refute_includes(trace.to_s, 'visible')
|
|
16
|
+
assert_includes(trace.to_s, 'друг')
|
|
35
17
|
end
|
|
36
18
|
end
|
data/test/test__helper.rb
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
6
|
gem 'openssl'
|
|
24
7
|
require 'openssl'
|
|
25
|
-
require 'minitest/autorun'
|
|
26
8
|
require 'minitest/hooks/test'
|
|
27
9
|
require 'concurrent'
|
|
28
10
|
require 'timeout'
|
|
29
11
|
|
|
30
|
-
require 'minitest/fail_fast' if ENV['TEST_QUIET_LOG']
|
|
31
|
-
|
|
32
12
|
$stdout.sync = true
|
|
33
13
|
|
|
34
14
|
ENV['RACK_ENV'] = 'test'
|
|
35
|
-
|
|
36
15
|
require 'simplecov'
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
16
|
+
require 'simplecov-cobertura'
|
|
17
|
+
unless SimpleCov.running || ENV['PICKS']
|
|
18
|
+
SimpleCov.command_name('test')
|
|
19
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
|
20
|
+
[
|
|
21
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
22
|
+
SimpleCov::Formatter::CoberturaFormatter
|
|
23
|
+
]
|
|
24
|
+
)
|
|
25
|
+
SimpleCov.minimum_coverage 85
|
|
26
|
+
SimpleCov.minimum_coverage_by_file 50
|
|
27
|
+
SimpleCov.start do
|
|
28
|
+
add_filter 'test/'
|
|
29
|
+
add_filter 'vendor/'
|
|
30
|
+
add_filter 'target/'
|
|
31
|
+
track_files 'lib/**/*.rb'
|
|
32
|
+
track_files '*.rb'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
41
35
|
|
|
36
|
+
require 'minitest/autorun'
|
|
37
|
+
require 'minitest/mock'
|
|
42
38
|
require 'minitest/reporters'
|
|
39
|
+
require 'webmock/minitest'
|
|
43
40
|
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
|
41
|
+
Minitest.load :minitest_reporter
|
|
42
|
+
|
|
43
|
+
require_relative '../lib/zold/hands'
|
|
44
|
+
Zold::Hands.start
|
|
44
45
|
|
|
45
46
|
module Zold
|
|
46
47
|
class Test < Minitest::Test
|
|
@@ -49,7 +50,7 @@ module Zold
|
|
|
49
50
|
# We need this in order to make sure any test is faster than a minute. This
|
|
50
51
|
# should help spotting tests that hang out sometimes. The number of seconds
|
|
51
52
|
# to wait can be increased, but try to make it as little as possible,
|
|
52
|
-
# in order to catch problems
|
|
53
|
+
# in order to catch problems earlier.
|
|
53
54
|
def around
|
|
54
55
|
Timeout.timeout(180) do
|
|
55
56
|
Thread.current.name = 'test'
|
|
@@ -81,14 +82,14 @@ module Zold
|
|
|
81
82
|
end
|
|
82
83
|
|
|
83
84
|
def fake_log
|
|
84
|
-
|
|
85
|
-
@fake_log ||= ENV['TEST_QUIET_LOG'] ?
|
|
85
|
+
require 'loog'
|
|
86
|
+
@fake_log ||= ENV['TEST_QUIET_LOG'] == 'true' ? Loog::NULL : Loog::VERBOSE
|
|
86
87
|
end
|
|
87
88
|
|
|
88
89
|
class TestLogger
|
|
89
90
|
attr_accessor :msgs
|
|
90
91
|
|
|
91
|
-
def initialize(log =
|
|
92
|
+
def initialize(log = Loog::NULL)
|
|
92
93
|
@log = log
|
|
93
94
|
@msgs = []
|
|
94
95
|
end
|
data/test/test_age.rb
CHANGED
|
@@ -1,39 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative 'test__helper'
|
|
25
7
|
require_relative '../lib/zold/age'
|
|
26
8
|
|
|
27
9
|
# Age test.
|
|
28
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
29
|
-
# Copyright:: Copyright (c) 2018-
|
|
11
|
+
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
30
12
|
# License:: MIT
|
|
31
13
|
class TestAge < Zold::Test
|
|
32
14
|
def test_prints_age
|
|
33
15
|
assert_equal('10m', Zold::Age.new(Time.now - (10 * 60)).to_s)
|
|
34
16
|
assert_equal('5.5s', Zold::Age.new(Time.now - 5.5).to_s)
|
|
35
17
|
assert_equal('?', Zold::Age.new(nil).to_s)
|
|
36
|
-
|
|
18
|
+
refute_nil(Zold::Age.new(Time.now.utc.iso8601).to_s)
|
|
37
19
|
end
|
|
38
20
|
|
|
39
21
|
def test_prints_all_ages
|
|
@@ -49,7 +31,7 @@ class TestAge < Zold::Test
|
|
|
49
31
|
15 * 30 * 24 * 60 * 60,
|
|
50
32
|
8 * 12 * 30 * 24 * 60 * 60
|
|
51
33
|
].each do |s|
|
|
52
|
-
|
|
34
|
+
refute_nil(Zold::Age.new(Time.now - s).to_s)
|
|
53
35
|
end
|
|
54
36
|
end
|
|
55
37
|
end
|
data/test/test_amount.rb
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright (c) 2018-
|
|
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.
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
22
5
|
|
|
23
|
-
require 'minitest/autorun'
|
|
24
6
|
require_relative 'test__helper'
|
|
25
7
|
require_relative '../lib/zold/amount'
|
|
26
8
|
|
|
27
9
|
# Amount test.
|
|
28
10
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
29
|
-
# Copyright:: Copyright (c) 2018-
|
|
11
|
+
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
30
12
|
# License:: MIT
|
|
31
13
|
class TestAmount < Zold::Test
|
|
32
14
|
def test_parses_zld
|
|
33
15
|
amount = Zold::Amount.new(zld: 14.95)
|
|
34
|
-
|
|
35
|
-
amount.to_s
|
|
16
|
+
assert_includes(
|
|
17
|
+
amount.to_s, '14.95ZLD',
|
|
36
18
|
"#{amount} is not equal to '14.95ZLD'"
|
|
37
19
|
)
|
|
38
20
|
end
|
|
@@ -47,35 +29,34 @@ class TestAmount < Zold::Test
|
|
|
47
29
|
|
|
48
30
|
def test_compares_with_zero
|
|
49
31
|
amount = Zold::Amount.new(zld: 0.00001)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
32
|
+
refute_predicate(amount, :zero?)
|
|
33
|
+
assert_predicate(amount, :positive?)
|
|
34
|
+
refute_predicate(amount, :negative?)
|
|
35
|
+
refute_equal(amount, Zold::Amount::ZERO)
|
|
54
36
|
end
|
|
55
37
|
|
|
56
38
|
def test_parses_zents
|
|
57
39
|
amount = Zold::Amount.new(zents: 900_000_000)
|
|
58
|
-
|
|
59
|
-
amount.to_s
|
|
40
|
+
assert_includes(
|
|
41
|
+
amount.to_s, '0.21ZLD',
|
|
60
42
|
"#{amount} is not equal to '0.21ZLD'"
|
|
61
43
|
)
|
|
62
44
|
end
|
|
63
45
|
|
|
64
46
|
def test_compares_amounts
|
|
65
47
|
amount = Zold::Amount.new(zents: 700_000_000)
|
|
66
|
-
|
|
67
|
-
amount
|
|
68
|
-
"#{amount} is not greater than zero"
|
|
48
|
+
assert_operator(
|
|
49
|
+
amount, :>, Zold::Amount::ZERO, "#{amount} is not greater than zero"
|
|
69
50
|
)
|
|
70
51
|
end
|
|
71
52
|
|
|
72
53
|
def test_multiplies
|
|
73
54
|
amount = Zold::Amount.new(zld: 1.2)
|
|
74
|
-
|
|
55
|
+
assert_equal(Zold::Amount.new(zld: 2.4), amount * 2)
|
|
75
56
|
end
|
|
76
57
|
|
|
77
58
|
def test_divides
|
|
78
59
|
amount = Zold::Amount.new(zld: 8.2)
|
|
79
|
-
|
|
60
|
+
assert_equal(Zold::Amount.new(zld: 4.1), amount / 2)
|
|
80
61
|
end
|
|
81
62
|
end
|