zold 0.31.10 → 0.32.1
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/Dockerfile +11 -27
- data/Gemfile +21 -33
- data/Gemfile.lock +181 -126
- 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/deploy.sh +4 -22
- 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/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 +6 -22
- metadata +26 -174
- data/.0pdd.yml +0 -29
- data/.gitattributes +0 -9
- data/.github/workflows/actionlint.yml +0 -41
- data/.github/workflows/codecov.yml +0 -40
- data/.github/workflows/copyrights.yml +0 -30
- data/.github/workflows/pdd.yml +0 -34
- data/.github/workflows/rake.yml +0 -45
- data/.github/workflows/xcop.yml +0 -30
- data/.github/workflows/yamllint.yml +0 -34
- data/.gitignore +0 -12
- data/.pdd +0 -7
- data/.rubocop.yml +0 -70
- data/.ruby-version +0 -1
- data/.rultor.yml +0 -57
- data/.simplecov +0 -36
- data/cucumber.yml +0 -23
- data/features/cli.feature +0 -16
- data/features/gem_package.feature +0 -26
- data/features/step_definitions/steps.rb +0 -84
- data/features/support/env.rb +0 -26
- data/fixtures/448b451bc62e8e16.z +0 -1005
- data/fixtures/id_rsa +0 -51
- data/fixtures/id_rsa-2 +0 -51
- data/fixtures/id_rsa-2.pub +0 -1
- data/fixtures/id_rsa.pub +0 -1
- data/fixtures/keys/1.pub +0 -1
- data/fixtures/keys/2 +0 -51
- data/fixtures/keys/2.pub +0 -1
- data/fixtures/merge/asserts.rb +0 -36
- data/fixtures/merge/id_rsa +0 -51
- data/fixtures/merge/id_rsa.pub +0 -1
- data/fixtures/merge/into_no_wallet/assert.rb +0 -25
- data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/into_no_wallet/opts +0 -1
- data/fixtures/merge/legacy_negatives_stay/0123456789abcdef.z +0 -6
- data/fixtures/merge/legacy_negatives_stay/assert.rb +0 -25
- data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/legacy_negatives_stay/opts +0 -2
- data/fixtures/merge/missed_wallets/0000000000000000.z +0 -6
- data/fixtures/merge/missed_wallets/0123456789abcdef.z +0 -6
- data/fixtures/merge/missed_wallets/assert.rb +0 -25
- data/fixtures/merge/missed_wallets/copies/0123456789abcdef/1.zc +0 -8
- data/fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/missed_wallets/opts +0 -3
- data/fixtures/merge/negative_overwriting/0123456789abcdef.z +0 -6
- data/fixtures/merge/negative_overwriting/146b852f2d9ad984.z +0 -6
- data/fixtures/merge/negative_overwriting/assert.rb +0 -25
- data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/negative_overwriting/opts +0 -2
- data/fixtures/merge/negatives_in_between/0000000000000000.z +0 -6
- data/fixtures/merge/negatives_in_between/0123456789abcdef.z +0 -5
- data/fixtures/merge/negatives_in_between/assert.rb +0 -25
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc +0 -7
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/3.zc +0 -6
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/scores.zc +0 -3
- data/fixtures/merge/negatives_in_between/opts +0 -1
- data/fixtures/merge/random_expenses/0000000000000000.z +0 -6
- data/fixtures/merge/random_expenses/0123456789abcdef.z +0 -6
- data/fixtures/merge/random_expenses/assert.rb +0 -25
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/1.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/2.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/3.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/4.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/5.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/scores.zc +0 -5
- data/fixtures/merge/random_expenses/opts +0 -1
- data/fixtures/merge/simple_case/0000000000000000.z +0 -6
- data/fixtures/merge/simple_case/0123456789abcdef.z +0 -4
- data/fixtures/merge/simple_case/assert.rb +0 -25
- data/fixtures/merge/simple_case/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/simple_case/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/simple_case/opts +0 -1
- data/fixtures/merge/unconfirmed_income/0123456789abcdef.z +0 -4
- data/fixtures/merge/unconfirmed_income/assert.rb +0 -25
- data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/unconfirmed_income/opts +0 -3
- data/fixtures/scripts/_head.sh +0 -89
- data/fixtures/scripts/calculate-scores.sh +0 -22
- data/fixtures/scripts/distribute-wallet.sh +0 -105
- data/fixtures/scripts/print-helps.sh +0 -27
- data/fixtures/scripts/pull-on-start.sh +0 -52
- data/fixtures/scripts/push-and-pull.sh +0 -63
- data/fixtures/scripts/redeploy-on-upgrade.sh +0 -56
- data/fixtures/scripts/spread-wallets.sh +0 -72
- data/lib/zold/log.rb +0 -139
- data/renovate.json +0 -6
- data/test/commands/routines/test_audit.rb +0 -41
- data/test/commands/routines/test_gc.rb +0 -70
- data/test/commands/routines/test_reconcile.rb +0 -51
- data/test/commands/routines/test_reconnect.rb +0 -46
- data/test/commands/routines/test_retire.rb +0 -40
- data/test/commands/test_alias.rb +0 -76
- data/test/commands/test_calculate.rb +0 -40
- data/test/commands/test_clean.rb +0 -73
- data/test/commands/test_create.rb +0 -50
- data/test/commands/test_diff.rb +0 -61
- data/test/commands/test_fetch.rb +0 -162
- data/test/commands/test_invoice.rb +0 -50
- data/test/commands/test_list.rb +0 -47
- data/test/commands/test_merge.rb +0 -129
- data/test/commands/test_node.rb +0 -68
- data/test/commands/test_pay.rb +0 -221
- data/test/commands/test_propagate.rb +0 -51
- data/test/commands/test_pull.rb +0 -70
- data/test/commands/test_push.rb +0 -93
- data/test/commands/test_remote.rb +0 -265
- data/test/commands/test_remove.rb +0 -66
- data/test/commands/test_show.rb +0 -48
- data/test/commands/test_taxes.rb +0 -76
- data/test/fake_home.rb +0 -104
- data/test/node/fake_entrance.rb +0 -43
- data/test/node/fake_node.rb +0 -105
- data/test/node/test_async_entrance.rb +0 -103
- data/test/node/test_entrance.rb +0 -82
- data/test/node/test_farm.rb +0 -177
- data/test/node/test_farmers.rb +0 -76
- data/test/node/test_front.rb +0 -399
- data/test/node/test_nodup_entrance.rb +0 -49
- data/test/node/test_nospam_entrance.rb +0 -49
- data/test/node/test_safe_entrance.rb +0 -59
- data/test/node/test_spread_entrance.rb +0 -67
- data/test/node/test_sync_entrance.rb +0 -41
- data/test/node/test_trace.rb +0 -36
- data/test/test__helper.rb +0 -112
- data/test/test_age.rb +0 -55
- data/test/test_amount.rb +0 -81
- data/test/test_cached_wallets.rb +0 -73
- data/test/test_copies.rb +0 -145
- data/test/test_dir_items.rb +0 -90
- data/test/test_gem.rb +0 -41
- data/test/test_hands.rb +0 -69
- data/test/test_hexnum.rb +0 -36
- data/test/test_http.rb +0 -225
- data/test/test_hungry_wallets.rb +0 -90
- data/test/test_id.rb +0 -79
- data/test/test_json_page.rb +0 -47
- data/test/test_key.rb +0 -99
- data/test/test_log.rb +0 -49
- data/test/test_metronome.rb +0 -89
- data/test/test_patch.rb +0 -178
- data/test/test_prefixes.rb +0 -49
- data/test/test_remotes.rb +0 -319
- data/test/test_signature.rb +0 -49
- data/test/test_size.rb +0 -39
- data/test/test_sync_wallets.rb +0 -57
- data/test/test_tax.rb +0 -171
- data/test/test_thread_pool.rb +0 -89
- data/test/test_tree_wallets.rb +0 -83
- data/test/test_txn.rb +0 -89
- data/test/test_upgrades.rb +0 -99
- data/test/test_verbose_thread.rb +0 -55
- data/test/test_version.rb +0 -35
- data/test/test_wallet.rb +0 -318
- data/test/test_wallets.rb +0 -85
- data/test/test_zold.rb +0 -99
- data/test/upgrades/test_delete_banned_wallets.rb +0 -47
- data/test/upgrades/test_protocol_up.rb +0 -42
data/test/node/test_trace.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require_relative '../test__helper'
|
|
25
|
-
require_relative '../../lib/zold/node/trace'
|
|
26
|
-
|
|
27
|
-
class TraceTest < Zold::Test
|
|
28
|
-
def test_records_log_lines
|
|
29
|
-
trace = Zold::Trace.new(fake_log, 2)
|
|
30
|
-
trace.error('This should not be visible')
|
|
31
|
-
trace.error('How are you, друг?')
|
|
32
|
-
trace.error('Works?')
|
|
33
|
-
assert(!trace.to_s.include?('visible'))
|
|
34
|
-
assert(trace.to_s.include?('друг'))
|
|
35
|
-
end
|
|
36
|
-
end
|
data/test/test__helper.rb
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
23
|
-
gem 'openssl'
|
|
24
|
-
require 'openssl'
|
|
25
|
-
require 'minitest/autorun'
|
|
26
|
-
require 'minitest/hooks/test'
|
|
27
|
-
require 'concurrent'
|
|
28
|
-
require 'timeout'
|
|
29
|
-
|
|
30
|
-
require 'minitest/fail_fast' if ENV['TEST_QUIET_LOG']
|
|
31
|
-
|
|
32
|
-
$stdout.sync = true
|
|
33
|
-
|
|
34
|
-
ENV['RACK_ENV'] = 'test'
|
|
35
|
-
|
|
36
|
-
require 'simplecov'
|
|
37
|
-
SimpleCov.start
|
|
38
|
-
|
|
39
|
-
require_relative '../lib/zold/hands'
|
|
40
|
-
Zold::Hands.start
|
|
41
|
-
|
|
42
|
-
require 'minitest/reporters'
|
|
43
|
-
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
|
44
|
-
|
|
45
|
-
module Zold
|
|
46
|
-
class Test < Minitest::Test
|
|
47
|
-
include Minitest::Hooks
|
|
48
|
-
|
|
49
|
-
# We need this in order to make sure any test is faster than a minute. This
|
|
50
|
-
# should help spotting tests that hang out sometimes. The number of seconds
|
|
51
|
-
# to wait can be increased, but try to make it as little as possible,
|
|
52
|
-
# in order to catch problems ealier.
|
|
53
|
-
def around
|
|
54
|
-
Timeout.timeout(180) do
|
|
55
|
-
Thread.current.name = 'test'
|
|
56
|
-
super
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def assert_wait(max: 30, &block)
|
|
61
|
-
assert_equal_wait(true, max: max, &block)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def assert_equal_wait(expected, max: 30)
|
|
65
|
-
start = Time.now
|
|
66
|
-
loop do
|
|
67
|
-
begin
|
|
68
|
-
actual = yield
|
|
69
|
-
if expected == actual
|
|
70
|
-
assert_equal(expected, actual)
|
|
71
|
-
break
|
|
72
|
-
end
|
|
73
|
-
rescue StandardError => e
|
|
74
|
-
fake_log.debug(e.message)
|
|
75
|
-
end
|
|
76
|
-
sleep 1
|
|
77
|
-
sec = Time.now - start
|
|
78
|
-
require_relative '../lib/zold/age'
|
|
79
|
-
raise "'#{actual}' is not equal to '#{expected}' even after #{Zold::Age.new(start)} of waiting" if sec > max
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def fake_log
|
|
84
|
-
require_relative '../lib/zold/log'
|
|
85
|
-
@fake_log ||= ENV['TEST_QUIET_LOG'] ? Zold::Log::NULL : Zold::Log::VERBOSE
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
class TestLogger
|
|
89
|
-
attr_accessor :msgs
|
|
90
|
-
|
|
91
|
-
def initialize(log = Zold::Log::NULL)
|
|
92
|
-
@log = log
|
|
93
|
-
@msgs = []
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def info(msg)
|
|
97
|
-
@log.info(msg)
|
|
98
|
-
@msgs << msg
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def debug(msg)
|
|
102
|
-
@log.debug(msg)
|
|
103
|
-
@msgs << msg
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def error(msg)
|
|
107
|
-
@log.error(msg)
|
|
108
|
-
@msgs << msg
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
data/test/test_age.rb
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require_relative 'test__helper'
|
|
25
|
-
require_relative '../lib/zold/age'
|
|
26
|
-
|
|
27
|
-
# Age test.
|
|
28
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
29
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
30
|
-
# License:: MIT
|
|
31
|
-
class TestAge < Zold::Test
|
|
32
|
-
def test_prints_age
|
|
33
|
-
assert_equal('10m', Zold::Age.new(Time.now - (10 * 60)).to_s)
|
|
34
|
-
assert_equal('5.5s', Zold::Age.new(Time.now - 5.5).to_s)
|
|
35
|
-
assert_equal('?', Zold::Age.new(nil).to_s)
|
|
36
|
-
assert(!Zold::Age.new(Time.now.utc.iso8601).to_s.nil?)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_prints_all_ages
|
|
40
|
-
[
|
|
41
|
-
0,
|
|
42
|
-
1,
|
|
43
|
-
63,
|
|
44
|
-
63 * 60,
|
|
45
|
-
27 * 60 * 60,
|
|
46
|
-
13 * 24 * 60 * 60,
|
|
47
|
-
30 * 24 * 60 * 60,
|
|
48
|
-
5 * 30 * 24 * 60 * 60,
|
|
49
|
-
15 * 30 * 24 * 60 * 60,
|
|
50
|
-
8 * 12 * 30 * 24 * 60 * 60
|
|
51
|
-
].each do |s|
|
|
52
|
-
assert(!Zold::Age.new(Time.now - s).to_s.nil?)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
data/test/test_amount.rb
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require_relative 'test__helper'
|
|
25
|
-
require_relative '../lib/zold/amount'
|
|
26
|
-
|
|
27
|
-
# Amount test.
|
|
28
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
29
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
30
|
-
# License:: MIT
|
|
31
|
-
class TestAmount < Zold::Test
|
|
32
|
-
def test_parses_zld
|
|
33
|
-
amount = Zold::Amount.new(zld: 14.95)
|
|
34
|
-
assert(
|
|
35
|
-
amount.to_s.include?('14.95ZLD'),
|
|
36
|
-
"#{amount} is not equal to '14.95ZLD'"
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_prints_zld_with_many_digits
|
|
41
|
-
amount = Zold::Amount.new(zld: 0.12345678)
|
|
42
|
-
assert_equal('0.123', amount.to_zld(3))
|
|
43
|
-
assert_equal('0.1235', amount.to_zld(4))
|
|
44
|
-
assert_equal('0.12346', amount.to_zld(5))
|
|
45
|
-
assert_equal('0.123457', amount.to_zld(6))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_compares_with_zero
|
|
49
|
-
amount = Zold::Amount.new(zld: 0.00001)
|
|
50
|
-
assert(!amount.zero?)
|
|
51
|
-
assert(amount.positive?)
|
|
52
|
-
assert(!amount.negative?)
|
|
53
|
-
assert(amount != Zold::Amount::ZERO)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_parses_zents
|
|
57
|
-
amount = Zold::Amount.new(zents: 900_000_000)
|
|
58
|
-
assert(
|
|
59
|
-
amount.to_s.include?('0.21ZLD'),
|
|
60
|
-
"#{amount} is not equal to '0.21ZLD'"
|
|
61
|
-
)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_compares_amounts
|
|
65
|
-
amount = Zold::Amount.new(zents: 700_000_000)
|
|
66
|
-
assert(
|
|
67
|
-
amount > Zold::Amount::ZERO,
|
|
68
|
-
"#{amount} is not greater than zero"
|
|
69
|
-
)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def test_multiplies
|
|
73
|
-
amount = Zold::Amount.new(zld: 1.2)
|
|
74
|
-
assert(Zold::Amount.new(zld: 2.4), amount * 2)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_divides
|
|
78
|
-
amount = Zold::Amount.new(zld: 8.2)
|
|
79
|
-
assert(Zold::Amount.new(zld: 4.1), amount / 2)
|
|
80
|
-
end
|
|
81
|
-
end
|
data/test/test_cached_wallets.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'tmpdir'
|
|
25
|
-
require_relative 'test__helper'
|
|
26
|
-
require_relative 'fake_home'
|
|
27
|
-
require_relative '../lib/zold/key'
|
|
28
|
-
require_relative '../lib/zold/id'
|
|
29
|
-
require_relative '../lib/zold/wallets'
|
|
30
|
-
require_relative '../lib/zold/cached_wallets'
|
|
31
|
-
require_relative '../lib/zold/amount'
|
|
32
|
-
|
|
33
|
-
# CachedWallets test.
|
|
34
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
36
|
-
# License:: MIT
|
|
37
|
-
class TestCachedWallets < Zold::Test
|
|
38
|
-
def test_adds_wallet
|
|
39
|
-
Dir.mktmpdir do |dir|
|
|
40
|
-
wallets = Zold::CachedWallets.new(Zold::Wallets.new(dir))
|
|
41
|
-
id = Zold::Id.new
|
|
42
|
-
first = nil
|
|
43
|
-
wallets.acq(id, exclusive: true) do |wallet|
|
|
44
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
|
45
|
-
assert_equal(1, wallets.all.count)
|
|
46
|
-
first = wallet
|
|
47
|
-
end
|
|
48
|
-
wallets.acq(id) do |wallet|
|
|
49
|
-
assert_equal(first, wallet)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_flushes_correctly
|
|
55
|
-
Dir.mktmpdir do |dir|
|
|
56
|
-
wallets = Zold::CachedWallets.new(Zold::Wallets.new(dir))
|
|
57
|
-
id = Zold::Id.new
|
|
58
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
59
|
-
body = wallets.acq(id, exclusive: true) do |wallet|
|
|
60
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
|
61
|
-
File.read(wallet.path)
|
|
62
|
-
end
|
|
63
|
-
wallets.acq(id, exclusive: true) do |wallet|
|
|
64
|
-
wallet.sub(Zold::Amount.new(zld: 1.0), "NOPREFIX@#{Zold::Id.new}", key)
|
|
65
|
-
end
|
|
66
|
-
assert_equal(1, wallets.acq(id, &:txns).count)
|
|
67
|
-
wallets.acq(id, exclusive: true) do |wallet|
|
|
68
|
-
File.write(wallet.path, body)
|
|
69
|
-
end
|
|
70
|
-
assert_equal(0, wallets.acq(id, &:txns).count)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
data/test/test_copies.rb
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'tmpdir'
|
|
25
|
-
require 'time'
|
|
26
|
-
require_relative 'fake_home'
|
|
27
|
-
require_relative 'test__helper'
|
|
28
|
-
require_relative '../lib/zold/id'
|
|
29
|
-
require_relative '../lib/zold/age'
|
|
30
|
-
require_relative '../lib/zold/copies'
|
|
31
|
-
require_relative '../lib/zold/dir_items'
|
|
32
|
-
require_relative '../lib/zold/wallet'
|
|
33
|
-
|
|
34
|
-
# Copies test.
|
|
35
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
36
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
37
|
-
# License:: MIT
|
|
38
|
-
class TestCopies < Zold::Test
|
|
39
|
-
def test_adds_and_removes_copies
|
|
40
|
-
Dir.mktmpdir do |dir|
|
|
41
|
-
copies = Zold::Copies.new(File.join(dir, 'my/a/copies'), log: fake_log)
|
|
42
|
-
copies.add(content('alpha'), '192.168.0.1', 80, 1)
|
|
43
|
-
copies.add(content('beta'), '192.168.0.2', 80, 3)
|
|
44
|
-
copies.add(content('beta'), '192.168.0.3', 80, 7)
|
|
45
|
-
copies.add(content('alpha'), '192.168.0.4', 80, 10)
|
|
46
|
-
copies.add(content('hello-to-delete'), '192.168.0.5', 80, 10)
|
|
47
|
-
copies.remove('192.168.0.5', 80)
|
|
48
|
-
copies.clean
|
|
49
|
-
assert_equal(2, copies.all.count, copies.all.map { |c| c[:name] }.join('; '))
|
|
50
|
-
assert_equal(11, copies.all.find { |c| c[:name] == '1' }[:score])
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_lists_empty_dir
|
|
55
|
-
Dir.mktmpdir do |dir|
|
|
56
|
-
copies = Zold::Copies.new(File.join(dir, 'xxx'), log: fake_log)
|
|
57
|
-
assert(copies.all.empty?, "#{copies.all.count} is not zero")
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_overwrites_host
|
|
62
|
-
Dir.mktmpdir do |dir|
|
|
63
|
-
copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log)
|
|
64
|
-
host = 'b1.zold.io'
|
|
65
|
-
copies.add(content('z1'), host, 80, 5)
|
|
66
|
-
copies.add(content('z1'), host, 80, 6)
|
|
67
|
-
copies.add(content('z1'), host, 80, 7)
|
|
68
|
-
assert(copies.all.count == 1, "#{copies.all.count} is not equal to 1")
|
|
69
|
-
assert(copies.all[0][:score] == 7, "#{copies.all[0][:score]} is not 7")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_master_first
|
|
74
|
-
Dir.mktmpdir do |dir|
|
|
75
|
-
copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: fake_log)
|
|
76
|
-
copies.add(content('z1'), 'edge-1', 80, 100, master: false)
|
|
77
|
-
copies.add(content('z2'), 'master', 80, 1, master: true)
|
|
78
|
-
copies.add(content('z1'), 'edge-2', 80, 50, master: false)
|
|
79
|
-
copies.add(content('z1'), 'edge-3', 80, 400, master: false)
|
|
80
|
-
assert(copies.all[0][:master])
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def test_cleans_copies
|
|
85
|
-
Dir.mktmpdir do |dir|
|
|
86
|
-
copies = Zold::Copies.new(dir, log: fake_log)
|
|
87
|
-
copies.add(content('h1'), 'zold.io', 4096, 10, time: Time.now - (25 * 60 * 60))
|
|
88
|
-
copies.add(content('h1'), 'zold.io', 4097, 20, time: Time.now - (26 * 60 * 60))
|
|
89
|
-
assert(File.exist?(File.join(dir, "1#{Zold::Copies::EXT}")))
|
|
90
|
-
copies.clean
|
|
91
|
-
assert(copies.all.empty?, "#{copies.all.count} is not empty")
|
|
92
|
-
assert(!File.exist?(File.join(dir, "1#{Zold::Copies::EXT}")))
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_cleans_broken_copies
|
|
97
|
-
Dir.mktmpdir do |dir|
|
|
98
|
-
copies = Zold::Copies.new(dir, log: fake_log)
|
|
99
|
-
copies.add('broken wallet content', 'zold.io', 4096, 10, time: Time.now)
|
|
100
|
-
copies.clean
|
|
101
|
-
assert(copies.all.empty?, "#{copies.all.count} is not empty")
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def test_ignores_garbage
|
|
106
|
-
Dir.mktmpdir do |dir|
|
|
107
|
-
copies = Zold::Copies.new(dir, log: fake_log)
|
|
108
|
-
copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (25 * 60 * 60))
|
|
109
|
-
FileUtils.mkdir(File.join(dir, '55'))
|
|
110
|
-
assert_equal(1, copies.all.count)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def test_sorts_them_by_score
|
|
115
|
-
Dir.mktmpdir do |dir|
|
|
116
|
-
copies = Zold::Copies.new(dir, log: fake_log)
|
|
117
|
-
copies.add(content('content-1'), '1.zold.io', 80, 1)
|
|
118
|
-
copies.add(content('content-2'), '2.zold.io', 80, 2)
|
|
119
|
-
copies.add(content('content-3'), '3.zold.io', 80, 50)
|
|
120
|
-
copies.add(content('content-4'), '4.zold.io', 80, 3)
|
|
121
|
-
assert_equal('50 3 2 1', copies.all.map { |c| c[:score] }.join(' '))
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def test_ignores_too_old_scores
|
|
126
|
-
Dir.mktmpdir do |dir|
|
|
127
|
-
copies = Zold::Copies.new(dir, log: fake_log)
|
|
128
|
-
copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - (1000 * 60 * 60))
|
|
129
|
-
assert_equal(0, copies.all[0][:score])
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
private
|
|
134
|
-
|
|
135
|
-
def content(text)
|
|
136
|
-
id = Zold::Id.new('aaaabbbbccccdddd')
|
|
137
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
138
|
-
wallet = home.create_wallet(id)
|
|
139
|
-
amount = Zold::Amount.new(zld: 1.99)
|
|
140
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
141
|
-
wallet.sub(amount, 'NOPREFIX@0000111122223333', key, text, time: Time.parse('2018-01-01T01:01:01Z'))
|
|
142
|
-
File.read(wallet.path)
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
end
|
data/test/test_dir_items.rb
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
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/endless'
|
|
29
|
-
require_relative '../lib/zold/dir_items'
|
|
30
|
-
|
|
31
|
-
# DirItems test.
|
|
32
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
33
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
34
|
-
# License:: MIT
|
|
35
|
-
class TestDirItems < Zold::Test
|
|
36
|
-
def test_intensive_write_in_threads
|
|
37
|
-
Dir.mktmpdir do |dir|
|
|
38
|
-
file = File.join(dir, 'hey.txt')
|
|
39
|
-
back = Thread.start do
|
|
40
|
-
Zold::Endless.new('test-diritems', log: fake_log).run do
|
|
41
|
-
Zold::DirItems.new(dir).fetch
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
Threads.new(100).assert do
|
|
45
|
-
start = Time.now
|
|
46
|
-
File.write(file, 'test')
|
|
47
|
-
fake_log.info("Saved in #{Zold::Age.new(start)}")
|
|
48
|
-
sleep 1
|
|
49
|
-
end
|
|
50
|
-
back.kill
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_lists_empty_dir
|
|
55
|
-
Dir.mktmpdir do |dir|
|
|
56
|
-
d = File.join(dir, 'path с пробелами')
|
|
57
|
-
FileUtils.mkdir_p(d)
|
|
58
|
-
assert_equal(0, Zold::DirItems.new(d).fetch.count)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_lists_recursively
|
|
63
|
-
Dir.mktmpdir do |dir|
|
|
64
|
-
files = ['test1.txt', 'a/b/c/text', 'd/e/f/text', 'a/b/c/zz/text.1.2.3']
|
|
65
|
-
files.each do |f|
|
|
66
|
-
path = File.join(dir, f)
|
|
67
|
-
FileUtils.mkdir_p(File.dirname(path))
|
|
68
|
-
FileUtils.touch(path)
|
|
69
|
-
end
|
|
70
|
-
found = Zold::DirItems.new(dir).fetch
|
|
71
|
-
assert_equal(files.count, found.count)
|
|
72
|
-
files.each do |f|
|
|
73
|
-
assert(found.include?(f), f)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def test_lists_non_recursively
|
|
79
|
-
Dir.mktmpdir do |dir|
|
|
80
|
-
files = ['1.txt', 'a/1.txt', 'a/b/1.txt', 'a/b/c/1.txt']
|
|
81
|
-
files.each do |f|
|
|
82
|
-
path = File.join(dir, f)
|
|
83
|
-
FileUtils.mkdir_p(File.dirname(path))
|
|
84
|
-
FileUtils.touch(path)
|
|
85
|
-
end
|
|
86
|
-
found = Zold::DirItems.new(dir).fetch(recursive: false)
|
|
87
|
-
assert_equal(1, found.count)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
data/test/test_gem.rb
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
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
|
-
|
|
23
|
-
require_relative '../lib/zold/gem'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require 'minitest/autorun'
|
|
26
|
-
|
|
27
|
-
class TestGem < Zold::Test
|
|
28
|
-
def test_last_version
|
|
29
|
-
version = (1..3).map { rand(9).to_s }.join('.')
|
|
30
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
|
|
31
|
-
status: 200,
|
|
32
|
-
body: "{\"version\": \"#{version}\"}"
|
|
33
|
-
)
|
|
34
|
-
assert_equal(version, Zold::Gem.new.last_version)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_last_version_live
|
|
38
|
-
WebMock.allow_net_connect!
|
|
39
|
-
assert(!Zold::Gem.new.last_version.nil?)
|
|
40
|
-
end
|
|
41
|
-
end
|