zold 0.31.7 → 0.31.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.0pdd.yml +20 -0
- data/.github/workflows/actionlint.yml +41 -0
- data/.github/workflows/codecov.yml +23 -4
- data/.github/workflows/copyrights.yml +30 -0
- data/.github/workflows/pdd.yml +26 -3
- data/.github/workflows/rake.yml +24 -2
- data/.github/workflows/xcop.yml +21 -2
- data/.github/workflows/yamllint.yml +34 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +22 -1
- data/.ruby-version +1 -1
- data/.rultor.yml +35 -5
- data/.simplecov +1 -1
- data/Dockerfile +29 -3
- data/Gemfile +10 -10
- data/Gemfile.lock +340 -0
- data/LICENSE.txt +1 -1
- data/Rakefile +9 -12
- data/bin/zold +1 -1
- data/cucumber.yml +20 -0
- data/deploy.sh +20 -0
- data/features/step_definitions/steps.rb +1 -1
- data/features/support/env.rb +1 -1
- data/fixtures/merge/asserts.rb +1 -1
- data/fixtures/merge/into_no_wallet/assert.rb +1 -1
- data/fixtures/merge/legacy_negatives_stay/assert.rb +1 -1
- data/fixtures/merge/missed_wallets/assert.rb +1 -1
- data/fixtures/merge/negative_overwriting/assert.rb +1 -1
- data/fixtures/merge/negatives_in_between/assert.rb +1 -1
- data/fixtures/merge/random_expenses/assert.rb +1 -1
- data/fixtures/merge/simple_case/assert.rb +1 -1
- data/fixtures/merge/unconfirmed_income/assert.rb +1 -1
- data/fixtures/scripts/_head.sh +21 -1
- data/fixtures/scripts/calculate-scores.sh +19 -0
- data/fixtures/scripts/distribute-wallet.sh +19 -0
- data/fixtures/scripts/print-helps.sh +19 -0
- data/fixtures/scripts/pull-on-start.sh +19 -0
- data/fixtures/scripts/push-and-pull.sh +19 -0
- data/fixtures/scripts/redeploy-on-upgrade.sh +19 -0
- data/fixtures/scripts/spread-wallets.sh +19 -0
- data/lib/zold/age.rb +2 -2
- data/lib/zold/amount.rb +2 -2
- data/lib/zold/cached_wallets.rb +3 -3
- data/lib/zold/commands/alias.rb +20 -0
- data/lib/zold/commands/args.rb +2 -2
- data/lib/zold/commands/calculate.rb +2 -2
- data/lib/zold/commands/clean.rb +2 -2
- data/lib/zold/commands/create.rb +3 -2
- data/lib/zold/commands/diff.rb +2 -2
- data/lib/zold/commands/fetch.rb +2 -2
- data/lib/zold/commands/invoice.rb +2 -2
- data/lib/zold/commands/list.rb +2 -2
- data/lib/zold/commands/merge.rb +2 -2
- data/lib/zold/commands/next.rb +2 -2
- data/lib/zold/commands/node.rb +2 -2
- data/lib/zold/commands/pay.rb +2 -2
- data/lib/zold/commands/propagate.rb +2 -2
- data/lib/zold/commands/pull.rb +2 -2
- data/lib/zold/commands/push.rb +2 -2
- data/lib/zold/commands/remote.rb +2 -2
- data/lib/zold/commands/remove.rb +2 -2
- data/lib/zold/commands/routines/audit.rb +2 -2
- data/lib/zold/commands/routines/gc.rb +2 -2
- data/lib/zold/commands/routines/reconcile.rb +2 -2
- data/lib/zold/commands/routines/reconnect.rb +2 -2
- data/lib/zold/commands/routines/retire.rb +2 -2
- data/lib/zold/commands/routines/spread.rb +2 -2
- data/lib/zold/commands/routines.rb +2 -2
- data/lib/zold/commands/show.rb +2 -2
- data/lib/zold/commands/taxes.rb +2 -2
- data/lib/zold/commands/thread_badge.rb +3 -3
- data/lib/zold/copies.rb +2 -2
- data/lib/zold/dir_items.rb +2 -2
- data/lib/zold/endless.rb +2 -2
- data/lib/zold/gem.rb +2 -2
- data/lib/zold/hands.rb +2 -2
- data/lib/zold/head.rb +3 -3
- data/lib/zold/hexnum.rb +2 -2
- data/lib/zold/http.rb +3 -3
- data/lib/zold/hungry_wallets.rb +2 -2
- data/lib/zold/id.rb +4 -3
- data/lib/zold/json_page.rb +2 -2
- data/lib/zold/key.rb +2 -2
- data/lib/zold/log.rb +2 -2
- data/lib/zold/metronome.rb +2 -2
- data/lib/zold/node/async_entrance.rb +2 -2
- data/lib/zold/node/entrance.rb +2 -2
- data/lib/zold/node/farm.rb +2 -2
- data/lib/zold/node/farmers.rb +2 -2
- data/lib/zold/node/front.rb +3 -3
- data/lib/zold/node/journaled_pipeline.rb +2 -2
- data/lib/zold/node/nodup_entrance.rb +2 -2
- data/lib/zold/node/nospam_entrance.rb +2 -2
- data/lib/zold/node/pipeline.rb +2 -2
- data/lib/zold/node/safe_entrance.rb +2 -2
- data/lib/zold/node/soft_error.rb +2 -2
- data/lib/zold/node/spread_entrance.rb +2 -2
- data/lib/zold/node/sync_entrance.rb +2 -2
- data/lib/zold/node/trace.rb +2 -2
- data/lib/zold/patch.rb +2 -2
- data/lib/zold/prefixes.rb +2 -2
- data/lib/zold/remotes.rb +2 -2
- data/lib/zold/signature.rb +2 -2
- data/lib/zold/size.rb +2 -2
- data/lib/zold/sync_wallets.rb +2 -2
- data/lib/zold/tax.rb +2 -2
- data/lib/zold/thread_pool.rb +2 -2
- data/lib/zold/tree_wallets.rb +2 -2
- data/lib/zold/txn.rb +2 -2
- data/lib/zold/txns.rb +3 -3
- data/lib/zold/upgrades.rb +1 -1
- data/lib/zold/verbose_thread.rb +2 -2
- data/lib/zold/version.rb +3 -3
- data/lib/zold/version_file.rb +1 -1
- data/lib/zold/wallet.rb +2 -2
- data/lib/zold/wallets.rb +2 -2
- data/lib/zold.rb +2 -2
- data/test/commands/routines/test_audit.rb +4 -4
- data/test/commands/routines/test_gc.rb +8 -8
- data/test/commands/routines/test_reconcile.rb +4 -4
- data/test/commands/routines/test_reconnect.rb +3 -3
- data/test/commands/routines/test_retire.rb +3 -3
- data/test/commands/test_alias.rb +26 -6
- data/test/commands/test_calculate.rb +3 -3
- data/test/commands/test_clean.rb +10 -10
- data/test/commands/test_create.rb +3 -3
- data/test/commands/test_diff.rb +5 -5
- data/test/commands/test_fetch.rb +9 -9
- data/test/commands/test_invoice.rb +3 -3
- data/test/commands/test_list.rb +3 -3
- data/test/commands/test_merge.rb +12 -12
- data/test/commands/test_node.rb +6 -6
- data/test/commands/test_pay.rb +19 -19
- data/test/commands/test_propagate.rb +5 -5
- data/test/commands/test_pull.rb +6 -6
- data/test/commands/test_push.rb +9 -9
- data/test/commands/test_remote.rb +11 -11
- data/test/commands/test_remove.rb +10 -10
- data/test/commands/test_show.rb +3 -3
- data/test/commands/test_taxes.rb +4 -4
- data/test/fake_home.rb +2 -2
- data/test/node/fake_entrance.rb +2 -2
- data/test/node/fake_node.rb +57 -40
- data/test/node/test_async_entrance.rb +10 -10
- data/test/node/test_entrance.rb +8 -8
- data/test/node/test_farm.rb +11 -11
- data/test/node/test_farmers.rb +5 -5
- data/test/node/test_front.rb +29 -28
- data/test/node/test_nodup_entrance.rb +4 -4
- data/test/node/test_nospam_entrance.rb +3 -3
- data/test/node/test_safe_entrance.rb +4 -4
- data/test/node/test_spread_entrance.rb +8 -8
- data/test/node/test_sync_entrance.rb +4 -4
- data/test/node/test_trace.rb +2 -2
- data/test/test__helper.rb +4 -4
- data/test/test_age.rb +2 -2
- data/test/test_amount.rb +2 -2
- data/test/test_cached_wallets.rb +2 -2
- data/test/test_copies.rb +12 -12
- data/test/test_dir_items.rb +4 -4
- data/test/test_gem.rb +20 -0
- data/test/test_hands.rb +2 -2
- data/test/test_hexnum.rb +2 -2
- data/test/test_http.rb +8 -8
- data/test/test_hungry_wallets.rb +11 -11
- data/test/test_id.rb +11 -2
- data/test/test_json_page.rb +2 -2
- data/test/test_key.rb +2 -2
- data/test/test_log.rb +5 -5
- data/test/test_metronome.rb +6 -6
- data/test/test_patch.rb +14 -14
- data/test/test_prefixes.rb +3 -3
- data/test/test_remotes.rb +9 -9
- data/test/test_signature.rb +2 -2
- data/test/test_size.rb +2 -2
- data/test/test_sync_wallets.rb +3 -3
- data/test/test_tax.rb +9 -9
- data/test/test_thread_pool.rb +8 -8
- data/test/test_tree_wallets.rb +2 -2
- data/test/test_txn.rb +2 -2
- data/test/test_upgrades.rb +2 -2
- data/test/test_verbose_thread.rb +2 -2
- data/test/test_version.rb +20 -0
- data/test/test_wallet.rb +22 -22
- data/test/test_wallets.rb +5 -5
- data/test/test_zold.rb +5 -5
- data/test/upgrades/test_delete_banned_wallets.rb +4 -4
- data/test/upgrades/test_protocol_up.rb +4 -4
- data/upgrades/2.rb +1 -1
- data/upgrades/delete_banned_wallets.rb +1 -1
- data/upgrades/move_wallets_into_tree.rb +1 -1
- data/upgrades/protocol_up.rb +1 -1
- data/upgrades/rename_foreign_wallets.rb +1 -1
- data/zold.gemspec +23 -23
- metadata +7 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,11 +28,11 @@ require_relative 'fake_entrance'
|
|
28
28
|
|
29
29
|
# NoSpamEntrance test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2018
|
31
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
32
32
|
# License:: MIT
|
33
33
|
class TestNoSpamEntrance < Zold::Test
|
34
34
|
def test_ignores_spam
|
35
|
-
Zold::NoSpamEntrance.new(RealEntrance.new, log:
|
35
|
+
Zold::NoSpamEntrance.new(RealEntrance.new, log: fake_log).start do |e|
|
36
36
|
id = Zold::Id.new
|
37
37
|
content = 'hello'
|
38
38
|
assert(!e.push(id, content).empty?)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -32,11 +32,11 @@ require_relative 'fake_entrance'
|
|
32
32
|
|
33
33
|
# SafeEntrance test.
|
34
34
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
35
|
-
# Copyright:: Copyright (c) 2018
|
35
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
36
36
|
# License:: MIT
|
37
37
|
class TestSafeEntrance < Zold::Test
|
38
38
|
def test_rejects_wallet_with_negative_balance
|
39
|
-
FakeHome.new(log:
|
39
|
+
FakeHome.new(log: fake_log).run do |home|
|
40
40
|
wallet = home.create_wallet
|
41
41
|
amount = Zold::Amount.new(zld: 39.99)
|
42
42
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
@@ -48,7 +48,7 @@ class TestSafeEntrance < Zold::Test
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_rejects_wallet_with_wrong_network
|
51
|
-
FakeHome.new(log:
|
51
|
+
FakeHome.new(log: fake_log).run do |home|
|
52
52
|
wallet = Zold::Wallet.new(File.join(home.dir, 'wallet.z'))
|
53
53
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'), network: 'someothernetwork')
|
54
54
|
assert_raises StandardError do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -32,19 +32,19 @@ require_relative 'fake_entrance'
|
|
32
32
|
|
33
33
|
# SpreadEntrance test.
|
34
34
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
35
|
-
# Copyright:: Copyright (c) 2018
|
35
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
36
36
|
# License:: MIT
|
37
37
|
class TestSpreadEntrance < Zold::Test
|
38
38
|
def test_renders_json
|
39
|
-
FakeHome.new(log:
|
39
|
+
FakeHome.new(log: fake_log).run do |home|
|
40
40
|
wallet = home.create_wallet(Zold::Id.new)
|
41
41
|
Zold::SpreadEntrance.new(
|
42
42
|
Zold::Entrance.new(
|
43
43
|
home.wallets,
|
44
44
|
Zold::Pipeline.new(home.remotes, home.copies(wallet).root, 'x'),
|
45
|
-
log:
|
45
|
+
log: fake_log
|
46
46
|
),
|
47
|
-
home.wallets, home.remotes, 'x', log:
|
47
|
+
home.wallets, home.remotes, 'x', log: fake_log
|
48
48
|
).start do |e|
|
49
49
|
assert_equal(0, e.to_json[:modified])
|
50
50
|
end
|
@@ -52,12 +52,12 @@ class TestSpreadEntrance < Zold::Test
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_ignores_duplicates
|
55
|
-
FakeHome.new(log:
|
56
|
-
FakeNode.new(log:
|
55
|
+
FakeHome.new(log: fake_log).run do |home|
|
56
|
+
FakeNode.new(log: fake_log).run(['--ignore-score-weakness']) do |port|
|
57
57
|
wallet = home.create_wallet
|
58
58
|
remotes = home.remotes
|
59
59
|
remotes.add('localhost', port)
|
60
|
-
Zold::SpreadEntrance.new(FakeEntrance.new, home.wallets, remotes, 'x', log:
|
60
|
+
Zold::SpreadEntrance.new(FakeEntrance.new, home.wallets, remotes, 'x', log: fake_log).start do |e|
|
61
61
|
8.times { e.push(wallet.id, File.read(wallet.path)) }
|
62
62
|
assert(e.to_json[:modified] < 2, "It's too big: #{e.to_json[:modified]}")
|
63
63
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,12 +28,12 @@ require_relative 'fake_entrance'
|
|
28
28
|
|
29
29
|
# SyncEntrance test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2018
|
31
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
32
32
|
# License:: MIT
|
33
33
|
class TestSyncEntrance < Zold::Test
|
34
34
|
def test_renders_json
|
35
|
-
FakeHome.new(log:
|
36
|
-
Zold::SyncEntrance.new(FakeEntrance.new, File.join(home.dir, 'x'), log:
|
35
|
+
FakeHome.new(log: fake_log).run do |home|
|
36
|
+
Zold::SyncEntrance.new(FakeEntrance.new, File.join(home.dir, 'x'), log: fake_log).start do |e|
|
37
37
|
assert(!e.to_json.nil?)
|
38
38
|
end
|
39
39
|
end
|
data/test/node/test_trace.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,7 +26,7 @@ require_relative '../../lib/zold/node/trace'
|
|
26
26
|
|
27
27
|
class TraceTest < Zold::Test
|
28
28
|
def test_records_log_lines
|
29
|
-
trace = Zold::Trace.new(
|
29
|
+
trace = Zold::Trace.new(fake_log, 2)
|
30
30
|
trace.error('This should not be visible')
|
31
31
|
trace.error('How are you, друг?')
|
32
32
|
trace.error('Works?')
|
data/test/test__helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -71,7 +71,7 @@ module Zold
|
|
71
71
|
break
|
72
72
|
end
|
73
73
|
rescue StandardError => e
|
74
|
-
|
74
|
+
fake_log.debug(e.message)
|
75
75
|
end
|
76
76
|
sleep 1
|
77
77
|
sec = Time.now - start
|
@@ -80,9 +80,9 @@ module Zold
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
83
|
+
def fake_log
|
84
84
|
require_relative '../lib/zold/log'
|
85
|
-
@
|
85
|
+
@fake_log ||= ENV['TEST_QUIET_LOG'] ? Zold::Log::NULL : Zold::Log::VERBOSE
|
86
86
|
end
|
87
87
|
|
88
88
|
class TestLogger
|
data/test/test_age.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,7 +26,7 @@ require_relative '../lib/zold/age'
|
|
26
26
|
|
27
27
|
# Age test.
|
28
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2018
|
29
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
30
30
|
# License:: MIT
|
31
31
|
class TestAge < Zold::Test
|
32
32
|
def test_prints_age
|
data/test/test_amount.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,7 +26,7 @@ require_relative '../lib/zold/amount'
|
|
26
26
|
|
27
27
|
# Amount test.
|
28
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2018
|
29
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
30
30
|
# License:: MIT
|
31
31
|
class TestAmount < Zold::Test
|
32
32
|
def test_parses_zld
|
data/test/test_cached_wallets.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -32,7 +32,7 @@ require_relative '../lib/zold/amount'
|
|
32
32
|
|
33
33
|
# CachedWallets test.
|
34
34
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
35
|
-
# Copyright:: Copyright (c) 2018
|
35
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
36
36
|
# License:: MIT
|
37
37
|
class TestCachedWallets < Zold::Test
|
38
38
|
def test_adds_wallet
|
data/test/test_copies.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -33,12 +33,12 @@ require_relative '../lib/zold/wallet'
|
|
33
33
|
|
34
34
|
# Copies test.
|
35
35
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
36
|
-
# Copyright:: Copyright (c) 2018
|
36
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
37
37
|
# License:: MIT
|
38
38
|
class TestCopies < Zold::Test
|
39
39
|
def test_adds_and_removes_copies
|
40
40
|
Dir.mktmpdir do |dir|
|
41
|
-
copies = Zold::Copies.new(File.join(dir, 'my/a/copies'), log:
|
41
|
+
copies = Zold::Copies.new(File.join(dir, 'my/a/copies'), log: fake_log)
|
42
42
|
copies.add(content('alpha'), '192.168.0.1', 80, 1)
|
43
43
|
copies.add(content('beta'), '192.168.0.2', 80, 3)
|
44
44
|
copies.add(content('beta'), '192.168.0.3', 80, 7)
|
@@ -53,14 +53,14 @@ class TestCopies < Zold::Test
|
|
53
53
|
|
54
54
|
def test_lists_empty_dir
|
55
55
|
Dir.mktmpdir do |dir|
|
56
|
-
copies = Zold::Copies.new(File.join(dir, 'xxx'), log:
|
56
|
+
copies = Zold::Copies.new(File.join(dir, 'xxx'), log: fake_log)
|
57
57
|
assert(copies.all.empty?, "#{copies.all.count} is not zero")
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_overwrites_host
|
62
62
|
Dir.mktmpdir do |dir|
|
63
|
-
copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log:
|
63
|
+
copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log)
|
64
64
|
host = 'b1.zold.io'
|
65
65
|
copies.add(content('z1'), host, 80, 5)
|
66
66
|
copies.add(content('z1'), host, 80, 6)
|
@@ -72,7 +72,7 @@ class TestCopies < Zold::Test
|
|
72
72
|
|
73
73
|
def test_master_first
|
74
74
|
Dir.mktmpdir do |dir|
|
75
|
-
copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log:
|
75
|
+
copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log)
|
76
76
|
copies.add(content('z1'), 'edge-1', 80, 100, master: false)
|
77
77
|
copies.add(content('z2'), 'master', 80, 1, master: true)
|
78
78
|
copies.add(content('z1'), 'edge-2', 80, 50, master: false)
|
@@ -83,7 +83,7 @@ class TestCopies < Zold::Test
|
|
83
83
|
|
84
84
|
def test_cleans_copies
|
85
85
|
Dir.mktmpdir do |dir|
|
86
|
-
copies = Zold::Copies.new(dir, log:
|
86
|
+
copies = Zold::Copies.new(dir, log: fake_log)
|
87
87
|
copies.add(content('h1'), 'zold.io', 4096, 10, time: Time.now - (25 * 60 * 60))
|
88
88
|
copies.add(content('h1'), 'zold.io', 4097, 20, time: Time.now - (26 * 60 * 60))
|
89
89
|
assert(File.exist?(File.join(dir, "1#{Zold::Copies::EXT}")))
|
@@ -95,7 +95,7 @@ class TestCopies < Zold::Test
|
|
95
95
|
|
96
96
|
def test_cleans_broken_copies
|
97
97
|
Dir.mktmpdir do |dir|
|
98
|
-
copies = Zold::Copies.new(dir, log:
|
98
|
+
copies = Zold::Copies.new(dir, log: fake_log)
|
99
99
|
copies.add('broken wallet content', 'zold.io', 4096, 10, time: Time.now)
|
100
100
|
copies.clean
|
101
101
|
assert(copies.all.empty?, "#{copies.all.count} is not empty")
|
@@ -104,7 +104,7 @@ class TestCopies < Zold::Test
|
|
104
104
|
|
105
105
|
def test_ignores_garbage
|
106
106
|
Dir.mktmpdir do |dir|
|
107
|
-
copies = Zold::Copies.new(dir, log:
|
107
|
+
copies = Zold::Copies.new(dir, log: fake_log)
|
108
108
|
copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (25 * 60 * 60))
|
109
109
|
FileUtils.mkdir(File.join(dir, '55'))
|
110
110
|
assert_equal(1, copies.all.count)
|
@@ -113,7 +113,7 @@ class TestCopies < Zold::Test
|
|
113
113
|
|
114
114
|
def test_sorts_them_by_score
|
115
115
|
Dir.mktmpdir do |dir|
|
116
|
-
copies = Zold::Copies.new(dir, log:
|
116
|
+
copies = Zold::Copies.new(dir, log: fake_log)
|
117
117
|
copies.add(content('content-1'), '1.zold.io', 80, 1)
|
118
118
|
copies.add(content('content-2'), '2.zold.io', 80, 2)
|
119
119
|
copies.add(content('content-3'), '3.zold.io', 80, 50)
|
@@ -124,7 +124,7 @@ class TestCopies < Zold::Test
|
|
124
124
|
|
125
125
|
def test_ignores_too_old_scores
|
126
126
|
Dir.mktmpdir do |dir|
|
127
|
-
copies = Zold::Copies.new(dir, log:
|
127
|
+
copies = Zold::Copies.new(dir, log: fake_log)
|
128
128
|
copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (1000 * 60 * 60))
|
129
129
|
assert_equal(0, copies.all[0][:score])
|
130
130
|
end
|
@@ -134,7 +134,7 @@ class TestCopies < Zold::Test
|
|
134
134
|
|
135
135
|
def content(text)
|
136
136
|
id = Zold::Id.new('aaaabbbbccccdddd')
|
137
|
-
FakeHome.new(log:
|
137
|
+
FakeHome.new(log: fake_log).run do |home|
|
138
138
|
wallet = home.create_wallet(id)
|
139
139
|
amount = Zold::Amount.new(zld: 1.99)
|
140
140
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
data/test/test_dir_items.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -30,21 +30,21 @@ require_relative '../lib/zold/dir_items'
|
|
30
30
|
|
31
31
|
# DirItems test.
|
32
32
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
33
|
-
# Copyright:: Copyright (c) 2018
|
33
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
34
34
|
# License:: MIT
|
35
35
|
class TestDirItems < Zold::Test
|
36
36
|
def test_intensive_write_in_threads
|
37
37
|
Dir.mktmpdir do |dir|
|
38
38
|
file = File.join(dir, 'hey.txt')
|
39
39
|
back = Thread.start do
|
40
|
-
Zold::Endless.new('test-diritems', log:
|
40
|
+
Zold::Endless.new('test-diritems', log: fake_log).run do
|
41
41
|
Zold::DirItems.new(dir).fetch
|
42
42
|
end
|
43
43
|
end
|
44
44
|
Threads.new(100).assert do
|
45
45
|
start = Time.now
|
46
46
|
File.write(file, 'test')
|
47
|
-
|
47
|
+
fake_log.info("Saved in #{Zold::Age.new(start)}")
|
48
48
|
sleep 1
|
49
49
|
end
|
50
50
|
back.kill
|
data/test/test_gem.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
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
|
+
|
3
23
|
require_relative '../lib/zold/gem'
|
4
24
|
require 'webmock/minitest'
|
5
25
|
require 'minitest/autorun'
|
data/test/test_hands.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -27,7 +27,7 @@ require_relative '../lib/zold/hands'
|
|
27
27
|
|
28
28
|
# Hands test.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2018
|
30
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
31
31
|
# License:: MIT
|
32
32
|
class TestHands < Zold::Test
|
33
33
|
def test_runs_in_many_threads
|
data/test/test_hexnum.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -25,7 +25,7 @@ require_relative '../lib/zold/hexnum'
|
|
25
25
|
|
26
26
|
# Hexnum test.
|
27
27
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
-
# Copyright:: Copyright (c) 2018
|
28
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
29
29
|
# License:: MIT
|
30
30
|
class TestHexnum < Zold::Test
|
31
31
|
def test_prints_and_parses
|
data/test/test_http.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -32,7 +32,7 @@ require_relative '../lib/zold/verbose_thread'
|
|
32
32
|
|
33
33
|
# Http test.
|
34
34
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
35
|
-
# Copyright:: Copyright (c) 2018
|
35
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
36
36
|
# License:: MIT
|
37
37
|
class TestHttp < Zold::Test
|
38
38
|
def test_pings_broken_uri
|
@@ -76,7 +76,7 @@ class TestHttp < Zold::Test
|
|
76
76
|
WebMock.allow_net_connect!
|
77
77
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
78
78
|
thread = Thread.start do
|
79
|
-
Zold::VerboseThread.new(
|
79
|
+
Zold::VerboseThread.new(fake_log).run do
|
80
80
|
server = TCPServer.new(port)
|
81
81
|
server.accept
|
82
82
|
sleep 400
|
@@ -95,7 +95,7 @@ class TestHttp < Zold::Test
|
|
95
95
|
WebMock.allow_net_connect!
|
96
96
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
97
97
|
thread = Thread.start do
|
98
|
-
Zold::VerboseThread.new(
|
98
|
+
Zold::VerboseThread.new(fake_log).run do
|
99
99
|
server = TCPServer.new(port)
|
100
100
|
client = server.accept
|
101
101
|
client.puts("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\n")
|
@@ -118,14 +118,14 @@ class TestHttp < Zold::Test
|
|
118
118
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
119
119
|
latch = Concurrent::CountDownLatch.new(1)
|
120
120
|
thread = Thread.start do
|
121
|
-
Zold::VerboseThread.new(
|
121
|
+
Zold::VerboseThread.new(fake_log).run do
|
122
122
|
server = TCPServer.new('127.0.0.1', port)
|
123
123
|
latch.count_down
|
124
124
|
socket = server.accept
|
125
125
|
loop do
|
126
126
|
line = socket.gets
|
127
127
|
break if line.eql?("\r\n")
|
128
|
-
|
128
|
+
fake_log.info(line.inspect)
|
129
129
|
body += line
|
130
130
|
end
|
131
131
|
socket.print("HTTP/1.1 200 OK\r\n")
|
@@ -163,7 +163,7 @@ class TestHttp < Zold::Test
|
|
163
163
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
164
164
|
latch = Concurrent::CountDownLatch.new(1)
|
165
165
|
thread = Thread.start do
|
166
|
-
Zold::VerboseThread.new(
|
166
|
+
Zold::VerboseThread.new(fake_log).run do
|
167
167
|
server = TCPServer.new(port)
|
168
168
|
latch.count_down
|
169
169
|
socket = server.accept
|
@@ -204,7 +204,7 @@ class TestHttp < Zold::Test
|
|
204
204
|
content = "how are you\nmy friend" * 1000
|
205
205
|
latch = Concurrent::CountDownLatch.new(1)
|
206
206
|
thread = Thread.start do
|
207
|
-
Zold::VerboseThread.new(
|
207
|
+
Zold::VerboseThread.new(fake_log).run do
|
208
208
|
server = TCPServer.new(port)
|
209
209
|
latch.count_down
|
210
210
|
socket = server.accept
|
data/test/test_hungry_wallets.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -31,19 +31,19 @@ require_relative '../lib/zold/hungry_wallets'
|
|
31
31
|
|
32
32
|
# HungryWallets test.
|
33
33
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
34
|
-
# Copyright:: Copyright (c) 2018
|
34
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
35
35
|
# License:: MIT
|
36
36
|
class TestHungryWallets < Zold::Test
|
37
37
|
def test_pulls_wallet
|
38
|
-
FakeHome.new(log:
|
38
|
+
FakeHome.new(log: fake_log).run do |home|
|
39
39
|
id = Zold::Id.new
|
40
40
|
get = stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 404)
|
41
41
|
remotes = home.remotes
|
42
42
|
remotes.add('localhost', 4096)
|
43
|
-
pool = Zold::ThreadPool.new('test', log:
|
43
|
+
pool = Zold::ThreadPool.new('test', log: fake_log)
|
44
44
|
wallets = Zold::HungryWallets.new(
|
45
45
|
home.wallets, remotes, File.join(home.dir, 'copies'),
|
46
|
-
pool, log:
|
46
|
+
pool, log: fake_log
|
47
47
|
)
|
48
48
|
wallets.acq(id) { |w| assert(!w.exists?) }
|
49
49
|
pool.join(2)
|
@@ -52,15 +52,15 @@ class TestHungryWallets < Zold::Test
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_doesnt_pull_twice_if_not_found
|
55
|
-
FakeHome.new(log:
|
55
|
+
FakeHome.new(log: fake_log).run do |home|
|
56
56
|
id = Zold::Id.new
|
57
57
|
get = stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 404)
|
58
58
|
remotes = home.remotes
|
59
59
|
remotes.add('localhost', 4096)
|
60
|
-
pool = Zold::ThreadPool.new('test', log:
|
60
|
+
pool = Zold::ThreadPool.new('test', log: fake_log)
|
61
61
|
wallets = Zold::HungryWallets.new(
|
62
62
|
home.wallets, remotes, File.join(home.dir, 'copies'),
|
63
|
-
pool, log:
|
63
|
+
pool, log: fake_log
|
64
64
|
)
|
65
65
|
3.times do
|
66
66
|
wallets.acq(id) { |w| assert(!w.exists?) }
|
@@ -72,15 +72,15 @@ class TestHungryWallets < Zold::Test
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_doesnt_pull_wallet_if_exists
|
75
|
-
FakeHome.new(log:
|
76
|
-
pool = Zold::ThreadPool.new('test', log:
|
75
|
+
FakeHome.new(log: fake_log).run do |home|
|
76
|
+
pool = Zold::ThreadPool.new('test', log: fake_log)
|
77
77
|
remotes = home.remotes
|
78
78
|
remotes.add('localhost', 4096)
|
79
79
|
wallet = home.create_wallet
|
80
80
|
get = stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return(status: 200)
|
81
81
|
wallets = Zold::HungryWallets.new(
|
82
82
|
home.wallets, remotes, File.join(home.dir, 'copies'),
|
83
|
-
pool, log:
|
83
|
+
pool, log: fake_log
|
84
84
|
)
|
85
85
|
wallets.acq(wallet.id) { |w| assert(w.exists?) }
|
86
86
|
pool.join(2)
|
data/test/test_id.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -27,7 +27,7 @@ require_relative '../lib/zold/id'
|
|
27
27
|
|
28
28
|
# ID test.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2018
|
30
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
31
31
|
# License:: MIT
|
32
32
|
class TestId < Zold::Test
|
33
33
|
def test_generates_new_id
|
@@ -37,6 +37,15 @@ class TestId < Zold::Test
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_generates_different_ids
|
41
|
+
before = ''
|
42
|
+
500.times do
|
43
|
+
id = Zold::Id.new
|
44
|
+
assert id.to_s != before.to_s
|
45
|
+
before = id
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
40
49
|
def test_list_of_banned_ids_is_not_empty
|
41
50
|
assert(!Zold::Id::BANNED.empty?)
|
42
51
|
end
|
data/test/test_json_page.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,7 +26,7 @@ require_relative '../lib/zold/json_page'
|
|
26
26
|
|
27
27
|
# JsonPage test.
|
28
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2018
|
29
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
30
30
|
# License:: MIT
|
31
31
|
class TestJsonPage < Zold::Test
|
32
32
|
def test_parses_json_page
|
data/test/test_key.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +28,7 @@ require_relative '../lib/zold/key'
|
|
28
28
|
|
29
29
|
# Key test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2018
|
31
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
32
32
|
# License:: MIT
|
33
33
|
class TestKey < Zold::Test
|
34
34
|
def test_reads_public_rsa
|
data/test/test_log.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2024 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -27,14 +27,14 @@ require_relative '../lib/zold/log'
|
|
27
27
|
|
28
28
|
# Log test.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2018
|
30
|
+
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
31
31
|
# License:: MIT
|
32
32
|
class TestLog < Zold::Test
|
33
33
|
def test_prints_from_many_threads
|
34
34
|
Threads.new(20).assert do
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
fake_log.debug("This is debug\nand it is multi\nline")
|
36
|
+
fake_log.info('This is info')
|
37
|
+
fake_log.error('This is error')
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|