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/test_metronome.rb
DELETED
|
@@ -1,89 +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/metronome'
|
|
26
|
-
|
|
27
|
-
# Metronome test.
|
|
28
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
29
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
30
|
-
# License:: MIT
|
|
31
|
-
class TestMetronome < Zold::Test
|
|
32
|
-
def test_start_and_stop
|
|
33
|
-
metronome = Zold::Metronome.new(fake_log)
|
|
34
|
-
list = []
|
|
35
|
-
metronome.add(FakeRoutine.new(list))
|
|
36
|
-
metronome.start do
|
|
37
|
-
assert_wait { !list.empty? }
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_prints_to_text
|
|
42
|
-
metronome = Zold::Metronome.new(fake_log)
|
|
43
|
-
metronome.add(FakeRoutine.new([]))
|
|
44
|
-
metronome.start do |m|
|
|
45
|
-
assert(!m.to_text.nil?)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_prints_empty_to_text
|
|
50
|
-
metronome = Zold::Metronome.new(fake_log)
|
|
51
|
-
metronome.start do |m|
|
|
52
|
-
assert(!m.to_text.nil?)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_continues_even_after_error
|
|
57
|
-
metronome = Zold::Metronome.new(fake_log)
|
|
58
|
-
routine = BrokenRoutine.new
|
|
59
|
-
metronome.add(routine)
|
|
60
|
-
metronome.start do
|
|
61
|
-
assert_wait { routine.count >= 2 }
|
|
62
|
-
assert(routine.count > 1)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
class FakeRoutine
|
|
67
|
-
def initialize(list)
|
|
68
|
-
@list = list
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def exec(i)
|
|
72
|
-
@list << i
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
class BrokenRoutine
|
|
77
|
-
attr_reader :count
|
|
78
|
-
|
|
79
|
-
def initialize
|
|
80
|
-
@count = 0
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def exec(i)
|
|
84
|
-
@count = i
|
|
85
|
-
sleep 0.1
|
|
86
|
-
raise
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
data/test/test_patch.rb
DELETED
|
@@ -1,178 +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 'fake_home'
|
|
25
|
-
require_relative 'test__helper'
|
|
26
|
-
require_relative '../lib/zold/key'
|
|
27
|
-
require_relative '../lib/zold/id'
|
|
28
|
-
require_relative '../lib/zold/wallet'
|
|
29
|
-
require_relative '../lib/zold/prefixes'
|
|
30
|
-
require_relative '../lib/zold/amount'
|
|
31
|
-
require_relative '../lib/zold/patch'
|
|
32
|
-
|
|
33
|
-
# Patch test.
|
|
34
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
36
|
-
# License:: MIT
|
|
37
|
-
class TestPatch < Zold::Test
|
|
38
|
-
def test_builds_patch
|
|
39
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
40
|
-
first = home.create_wallet
|
|
41
|
-
second = home.create_wallet
|
|
42
|
-
third = home.create_wallet
|
|
43
|
-
File.write(second.path, File.read(first.path))
|
|
44
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
45
|
-
first.sub(Zold::Amount.new(zld: 39.0), "NOPREFIX@#{Zold::Id.new}", key)
|
|
46
|
-
first.sub(Zold::Amount.new(zld: 11.0), "NOPREFIX@#{Zold::Id.new}", key)
|
|
47
|
-
first.sub(Zold::Amount.new(zld: 3.0), "NOPREFIX@#{Zold::Id.new}", key)
|
|
48
|
-
second.sub(Zold::Amount.new(zld: 44.0), "NOPREFIX@#{Zold::Id.new}", key)
|
|
49
|
-
File.write(third.path, File.read(first.path))
|
|
50
|
-
t = third.sub(Zold::Amount.new(zld: 10.0), "NOPREFIX@#{Zold::Id.new}", key)
|
|
51
|
-
third.add(t.inverse(Zold::Id.new))
|
|
52
|
-
patch = Zold::Patch.new(home.wallets, log: fake_log)
|
|
53
|
-
patch.join(first) { false }
|
|
54
|
-
patch.join(second) { false }
|
|
55
|
-
patch.join(third) { false }
|
|
56
|
-
assert_equal(true, patch.save(first.path, overwrite: true, allow_negative_balance: true))
|
|
57
|
-
assert_equal(Zold::Amount.new(zld: -53.0), first.balance)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_rejects_fake_positives
|
|
62
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
63
|
-
first = home.create_wallet
|
|
64
|
-
second = home.create_wallet
|
|
65
|
-
File.write(second.path, File.read(first.path))
|
|
66
|
-
second.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 11.0), 'NOPREFIX', Zold::Id.new, 'fake'))
|
|
67
|
-
patch = Zold::Patch.new(home.wallets, log: fake_log)
|
|
68
|
-
patch.join(first) { false }
|
|
69
|
-
patch.join(second) { false }
|
|
70
|
-
assert_equal(false, patch.save(first.path, overwrite: true))
|
|
71
|
-
first.flush
|
|
72
|
-
assert_equal(Zold::Amount::ZERO, first.balance)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_accepts_negative_balance_in_root_wallet
|
|
77
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
78
|
-
first = home.create_wallet(Zold::Id::ROOT)
|
|
79
|
-
second = home.create_wallet
|
|
80
|
-
File.write(second.path, File.read(first.path))
|
|
81
|
-
amount = Zold::Amount.new(zld: 333.0)
|
|
82
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
83
|
-
second.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
|
84
|
-
patch = Zold::Patch.new(home.wallets, log: fake_log)
|
|
85
|
-
patch.join(first) { false }
|
|
86
|
-
patch.join(second) { false }
|
|
87
|
-
assert_equal(true, patch.save(first.path, overwrite: true))
|
|
88
|
-
first.flush
|
|
89
|
-
assert_equal(amount * -1, first.balance)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def test_merges_similar_ids_but_different_signs
|
|
94
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
95
|
-
first = home.create_wallet(Zold::Id::ROOT)
|
|
96
|
-
second = home.create_wallet
|
|
97
|
-
File.write(second.path, File.read(first.path))
|
|
98
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
99
|
-
second.sub(Zold::Amount.new(zld: 7.0), "NOPREFIX@#{Zold::Id.new}", key)
|
|
100
|
-
first.add(
|
|
101
|
-
Zold::Txn.new(
|
|
102
|
-
1, Time.now, Zold::Amount.new(zld: 9.0),
|
|
103
|
-
Zold::Prefixes.new(first).create, Zold::Id.new, 'fake'
|
|
104
|
-
)
|
|
105
|
-
)
|
|
106
|
-
patch = Zold::Patch.new(home.wallets, log: fake_log)
|
|
107
|
-
patch.join(first) { false }
|
|
108
|
-
patch.join(second) { false }
|
|
109
|
-
assert_equal(true, patch.save(first.path, overwrite: true))
|
|
110
|
-
first.flush
|
|
111
|
-
assert_equal(Zold::Amount.new(zld: 2.0).to_s, first.balance.to_s)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_merges_fragmented_parts
|
|
116
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
117
|
-
first = home.create_wallet(Zold::Id::ROOT)
|
|
118
|
-
second = home.create_wallet
|
|
119
|
-
File.write(second.path, File.read(first.path))
|
|
120
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
121
|
-
start = Time.parse('2017-07-19T21:24:51Z')
|
|
122
|
-
first.add(
|
|
123
|
-
Zold::Txn.new(
|
|
124
|
-
1, start, Zold::Amount.new(zld: -2.0),
|
|
125
|
-
'NOPREFIX', Zold::Id.new, 'first payment'
|
|
126
|
-
).signed(key, first.id)
|
|
127
|
-
)
|
|
128
|
-
second.add(
|
|
129
|
-
Zold::Txn.new(
|
|
130
|
-
2, start + 1, Zold::Amount.new(zld: -2.0),
|
|
131
|
-
'NOPREFIX', Zold::Id.new, 'second payment'
|
|
132
|
-
).signed(key, first.id)
|
|
133
|
-
)
|
|
134
|
-
first.add(
|
|
135
|
-
Zold::Txn.new(
|
|
136
|
-
3, start + 2, Zold::Amount.new(zld: -2.0),
|
|
137
|
-
'NOPREFIX', Zold::Id.new, 'third payment'
|
|
138
|
-
).signed(key, first.id)
|
|
139
|
-
)
|
|
140
|
-
patch = Zold::Patch.new(home.wallets, log: fake_log)
|
|
141
|
-
patch.join(first) { false }
|
|
142
|
-
patch.join(second) { false }
|
|
143
|
-
assert_equal(true, patch.save(first.path, overwrite: true))
|
|
144
|
-
first.flush
|
|
145
|
-
assert_equal(3, first.txns.count)
|
|
146
|
-
assert_equal(Zold::Amount.new(zld: -6.0).to_s, first.balance.to_s)
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def test_protocols_new_txns
|
|
151
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
152
|
-
first = home.create_wallet(Zold::Id::ROOT)
|
|
153
|
-
second = home.create_wallet
|
|
154
|
-
File.write(second.path, File.read(first.path))
|
|
155
|
-
amount = Zold::Amount.new(zld: 333.0)
|
|
156
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
157
|
-
target = Zold::Id.new
|
|
158
|
-
second.sub(amount, "NOPREFIX@#{target}", key, 'some details')
|
|
159
|
-
second.sub(amount * 2, "NOPREFIX@#{target}", key)
|
|
160
|
-
patch = Zold::Patch.new(home.wallets, log: fake_log)
|
|
161
|
-
patch.legacy(first)
|
|
162
|
-
Tempfile.open do |f|
|
|
163
|
-
patch.join(second, ledger: f.path) { false }
|
|
164
|
-
lines = File.read(f).split("\n")
|
|
165
|
-
assert_equal(2, lines.count)
|
|
166
|
-
parts = lines[0].split(';')
|
|
167
|
-
assert(!Zold::Txn.parse_time(parts[0]).nil?)
|
|
168
|
-
assert_equal(1, parts[1].to_i)
|
|
169
|
-
assert(!Zold::Txn.parse_time(parts[2]).nil?)
|
|
170
|
-
assert_equal(Zold::Id::ROOT.to_s, parts[3])
|
|
171
|
-
assert_equal(target.to_s, parts[4])
|
|
172
|
-
assert_equal(amount, Zold::Amount.new(zents: parts[5].to_i))
|
|
173
|
-
assert_equal('NOPREFIX', parts[6])
|
|
174
|
-
assert_equal('some details', parts[7])
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
end
|
data/test/test_prefixes.rb
DELETED
|
@@ -1,49 +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 'fake_home'
|
|
26
|
-
require_relative '../lib/zold/key'
|
|
27
|
-
require_relative '../lib/zold/id'
|
|
28
|
-
require_relative '../lib/zold/wallet'
|
|
29
|
-
require_relative '../lib/zold/prefixes'
|
|
30
|
-
|
|
31
|
-
# Prefixes test.
|
|
32
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
33
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
34
|
-
# License:: MIT
|
|
35
|
-
class TestPrefixes < Zold::Test
|
|
36
|
-
def test_creates_and_validates
|
|
37
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
38
|
-
wallet = home.create_wallet
|
|
39
|
-
prefixes = Zold::Prefixes.new(wallet)
|
|
40
|
-
(8..32).each do |len|
|
|
41
|
-
50.times do
|
|
42
|
-
prefix = prefixes.create(len)
|
|
43
|
-
assert_equal(len, prefix.length)
|
|
44
|
-
assert(wallet.prefix?(prefix), "Prefix '#{prefix}' not found")
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
data/test/test_remotes.rb
DELETED
|
@@ -1,319 +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 'webmock/minitest'
|
|
26
|
-
require 'threads'
|
|
27
|
-
require_relative 'test__helper'
|
|
28
|
-
require_relative '../lib/zold/log'
|
|
29
|
-
require_relative '../lib/zold/age'
|
|
30
|
-
require_relative '../lib/zold/remotes'
|
|
31
|
-
require_relative '../lib/zold/verbose_thread'
|
|
32
|
-
|
|
33
|
-
# Remotes test.
|
|
34
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
36
|
-
# License:: MIT
|
|
37
|
-
class TestRemotes < Zold::Test
|
|
38
|
-
def test_adds_remotes
|
|
39
|
-
Dir.mktmpdir do |dir|
|
|
40
|
-
file = File.join(dir, 'remotes')
|
|
41
|
-
FileUtils.touch(file)
|
|
42
|
-
remotes = Zold::Remotes.new(file: file)
|
|
43
|
-
remotes.add('127.0.0.1')
|
|
44
|
-
assert(1, remotes.all.count)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_finds_masters
|
|
49
|
-
Dir.mktmpdir do |dir|
|
|
50
|
-
file = File.join(dir, 'remotes')
|
|
51
|
-
FileUtils.touch(file)
|
|
52
|
-
remotes = Zold::Remotes.new(file: file)
|
|
53
|
-
assert(remotes.master?('b2.zold.io', 4096))
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_reads_broken_file
|
|
58
|
-
Dir.mktmpdir do |dir|
|
|
59
|
-
file = File.join(dir, 'remotes')
|
|
60
|
-
[
|
|
61
|
-
',0,0,0',
|
|
62
|
-
'some garbage',
|
|
63
|
-
'',
|
|
64
|
-
"\n\n\n\n"
|
|
65
|
-
].each do |t|
|
|
66
|
-
File.write(file, t)
|
|
67
|
-
remotes = Zold::Remotes.new(file: file)
|
|
68
|
-
assert(remotes.all.empty?, remotes.all)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_iterates_and_fails
|
|
74
|
-
Dir.mktmpdir do |dir|
|
|
75
|
-
file = File.join(dir, 'remotes')
|
|
76
|
-
FileUtils.touch(file)
|
|
77
|
-
remotes = Zold::Remotes.new(file: file)
|
|
78
|
-
ips = (0..50)
|
|
79
|
-
ips.each { |i| remotes.add("0.0.0.#{i + 1}", 9999) }
|
|
80
|
-
remotes.iterate(Zold::Log::NULL) { raise 'Intended' }
|
|
81
|
-
ips.each { |i| assert(1, remotes.all[i][:errors]) }
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def test_iterates_all_failures
|
|
86
|
-
Dir.mktmpdir do |dir|
|
|
87
|
-
file = File.join(dir, 'remotes')
|
|
88
|
-
FileUtils.touch(file)
|
|
89
|
-
remotes = Zold::Remotes.new(file: file)
|
|
90
|
-
5.times { |i| remotes.add("0.0.0.#{i + 1}", 9999) }
|
|
91
|
-
total = 0
|
|
92
|
-
remotes.iterate(Zold::Log::NULL) do
|
|
93
|
-
total += 1
|
|
94
|
-
raise 'Intended'
|
|
95
|
-
end
|
|
96
|
-
assert_equal(5, total)
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def test_closes_threads_carefully
|
|
101
|
-
Dir.mktmpdir do |dir|
|
|
102
|
-
file = File.join(dir, 'remotes')
|
|
103
|
-
FileUtils.touch(file)
|
|
104
|
-
remotes = Zold::Remotes.new(file: file)
|
|
105
|
-
5.times { |i| remotes.add("0.0.0.#{i + 1}", 9999) }
|
|
106
|
-
total = 0
|
|
107
|
-
remotes.iterate(Zold::Log::NULL) do
|
|
108
|
-
sleep 0.25
|
|
109
|
-
total += 1
|
|
110
|
-
end
|
|
111
|
-
assert_equal(5, total)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_iterates_them_all_even_with_delays
|
|
116
|
-
Dir.mktmpdir do |dir|
|
|
117
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'rrr.csv'))
|
|
118
|
-
remotes.clean
|
|
119
|
-
5.times { |i| remotes.add("0.0.0.#{i + 1}", 8080) }
|
|
120
|
-
total = 0
|
|
121
|
-
remotes.iterate(fake_log) do
|
|
122
|
-
sleep 0.25
|
|
123
|
-
total += 1
|
|
124
|
-
end
|
|
125
|
-
assert_equal(5, total)
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def fake_log_msg_of_iterates_when_fail
|
|
130
|
-
Dir.mktmpdir do |dir|
|
|
131
|
-
file = File.join(dir, 'remotes')
|
|
132
|
-
FileUtils.touch(file)
|
|
133
|
-
remotes = Zold::Remotes.new(file: file)
|
|
134
|
-
remotes.add('0.0.0.1', 9999)
|
|
135
|
-
log = TestLogger.new
|
|
136
|
-
remotes.iterate(log) { raise 'Intended' }
|
|
137
|
-
assert(log.msgs.find { |m| m.include?(' in ') })
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def fake_log_msg_of_iterates_when_take_too_long
|
|
142
|
-
Dir.mktmpdir do |dir|
|
|
143
|
-
file = File.join(dir, 'remotes')
|
|
144
|
-
FileUtils.touch(file)
|
|
145
|
-
remotes = Zold::Remotes.new(file: file, timeout: 1)
|
|
146
|
-
remotes.add('127.0.0.1')
|
|
147
|
-
log = TestLogger.new
|
|
148
|
-
remotes.iterate(log) { sleep(2) }
|
|
149
|
-
assert(log.msgs.find { |m| m.include?('Took too long to execute') })
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def test_removes_remotes
|
|
154
|
-
Dir.mktmpdir do |dir|
|
|
155
|
-
file = File.join(dir, 'remotes')
|
|
156
|
-
FileUtils.touch(file)
|
|
157
|
-
remotes = Zold::Remotes.new(file: file)
|
|
158
|
-
remotes.add('127.0.0.1')
|
|
159
|
-
remotes.add('LOCALHOST', 433)
|
|
160
|
-
remotes.remove('localhost', 433)
|
|
161
|
-
assert(1, remotes.all.count)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def test_resets_remotes
|
|
166
|
-
Dir.mktmpdir do |dir|
|
|
167
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes'))
|
|
168
|
-
remotes.clean
|
|
169
|
-
remotes.masters
|
|
170
|
-
remotes.masters
|
|
171
|
-
assert(!remotes.all.empty?)
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def test_modifies_score
|
|
176
|
-
Dir.mktmpdir do |dir|
|
|
177
|
-
file = File.join(dir, 'remotes')
|
|
178
|
-
FileUtils.touch(file)
|
|
179
|
-
remotes = Zold::Remotes.new(file: file)
|
|
180
|
-
remotes.add('127.0.0.1', 1024)
|
|
181
|
-
remotes.rescore('127.0.0.1', 1024, 15)
|
|
182
|
-
remotes.all.each do |r|
|
|
183
|
-
assert_equal(15, r[:score])
|
|
184
|
-
assert_equal('http://127.0.0.1:1024/', r[:home].to_s)
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
def test_tolerates_invalid_requests
|
|
190
|
-
Dir.mktmpdir do |dir|
|
|
191
|
-
file = File.join(dir, 'remotes')
|
|
192
|
-
remotes = Zold::Remotes.new(file: file)
|
|
193
|
-
remotes.error('127.0.0.1', 1024)
|
|
194
|
-
remotes.rescore('127.0.0.1', 1024, 15)
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
def test_modifies_from_many_threads
|
|
199
|
-
Dir.mktmpdir do |dir|
|
|
200
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'a.csv'))
|
|
201
|
-
remotes.clean
|
|
202
|
-
host = '192.168.0.1'
|
|
203
|
-
remotes.add(host)
|
|
204
|
-
Threads.new(5).assert do
|
|
205
|
-
remotes.error(host)
|
|
206
|
-
end
|
|
207
|
-
assert_equal(0, remotes.all.reject { |r| r[:host] == host }.size)
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def test_mtime
|
|
212
|
-
Dir.mktmpdir 'test' do |dir|
|
|
213
|
-
file = File.join(dir, 'remotes')
|
|
214
|
-
FileUtils.touch(file)
|
|
215
|
-
File.stub :mtime, Time.mktime(2018, 1, 1) do
|
|
216
|
-
remotes = Zold::Remotes.new(file: file)
|
|
217
|
-
remotes.add('127.0.0.1')
|
|
218
|
-
assert_equal(Time.mktime(2018, 1, 1), remotes.mtime)
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def test_read_mtime_from_file
|
|
224
|
-
Dir.mktmpdir 'test' do |dir|
|
|
225
|
-
file = File.join(dir, 'a/b/c/remotes')
|
|
226
|
-
remotes = Zold::Remotes.new(file: file)
|
|
227
|
-
remotes.clean
|
|
228
|
-
assert_equal(File.mtime(file).to_i, remotes.mtime.to_i)
|
|
229
|
-
end
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
def test_adds_from_many_threads
|
|
233
|
-
Dir.mktmpdir do |dir|
|
|
234
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'xx.csv'))
|
|
235
|
-
remotes.clean
|
|
236
|
-
host = '127.0.0.1'
|
|
237
|
-
Threads.new(2).assert(100) do |_, r|
|
|
238
|
-
port = 8080 + r
|
|
239
|
-
remotes.add(host, port)
|
|
240
|
-
remotes.error(host, port)
|
|
241
|
-
assert(remotes.all.find { |x| x[:port] == port })
|
|
242
|
-
end
|
|
243
|
-
assert_equal(100, remotes.all.count)
|
|
244
|
-
end
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
def test_quickly_ads_and_reads
|
|
248
|
-
Dir.mktmpdir do |dir|
|
|
249
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'uu-90.csv'))
|
|
250
|
-
remotes.clean
|
|
251
|
-
start = Time.now
|
|
252
|
-
100.times { |i| remotes.add('192.168.0.1', 8080 + i) }
|
|
253
|
-
Threads.new(4).assert(10) do |t|
|
|
254
|
-
remotes.add('127.0.0.1', 8080 + t)
|
|
255
|
-
remotes.error('127.0.0.1', 8080 + t)
|
|
256
|
-
remotes.all
|
|
257
|
-
remotes.iterate(fake_log) { remotes.all }
|
|
258
|
-
remotes.remove('127.0.0.1', 8080 + t)
|
|
259
|
-
end
|
|
260
|
-
fake_log.info("Total time: #{Zold::Age.new(start)}")
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
def test_unerror_remote
|
|
265
|
-
Dir.mktmpdir do |dir|
|
|
266
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'uu-90.csv'))
|
|
267
|
-
remotes.clean
|
|
268
|
-
remotes.add('192.168.0.1', 8081)
|
|
269
|
-
assert_equal remotes.all.last[:errors], 0
|
|
270
|
-
remotes.error('192.168.0.1', 8081)
|
|
271
|
-
assert_equal remotes.all.last[:errors], 1
|
|
272
|
-
remotes.unerror('192.168.0.1', 8081)
|
|
273
|
-
assert_equal remotes.all.last[:errors], 0
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
def test_empty_remotes
|
|
278
|
-
Time.stub :now, Time.mktime(2018, 1, 1) do
|
|
279
|
-
remotes = Zold::Remotes::Empty.new
|
|
280
|
-
assert_equal(Time.mktime(2018, 1, 1), remotes.mtime)
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
def test_reads_mtime_from_empty_file
|
|
285
|
-
Dir.mktmpdir do |dir|
|
|
286
|
-
assert(!Zold::Remotes.new(file: File.join(dir, 'file/is/absent')).mtime.nil?)
|
|
287
|
-
end
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
def test_reports_zold_error_header
|
|
291
|
-
Dir.mktmpdir do |dir|
|
|
292
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'uu-90.csv'))
|
|
293
|
-
remotes.clean
|
|
294
|
-
remotes.add('11a-example.org', 8080)
|
|
295
|
-
stub_request(:get, 'http://11a-example.org:8080/').to_return(
|
|
296
|
-
status: 500,
|
|
297
|
-
headers: {
|
|
298
|
-
'X-Zold-Error': 'hey you'
|
|
299
|
-
}
|
|
300
|
-
)
|
|
301
|
-
remotes.iterate(fake_log) do |r|
|
|
302
|
-
r.assert_code(200, r.http.get)
|
|
303
|
-
end
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
def test_manifests_correct_network_name
|
|
308
|
-
Dir.mktmpdir do |dir|
|
|
309
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'uu-083.csv'), network: 'x13')
|
|
310
|
-
remotes.clean
|
|
311
|
-
remotes.add('r5-example.org', 8080)
|
|
312
|
-
stub_request(:get, 'http://r5-example.org:8080/').to_return(status: 200)
|
|
313
|
-
remotes.iterate(fake_log) do |r|
|
|
314
|
-
r.http.get
|
|
315
|
-
end
|
|
316
|
-
assert_requested(:get, 'http://r5-example.org:8080/', headers: { 'X-Zold-Network' => 'x13' })
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
end
|
data/test/test_signature.rb
DELETED
|
@@ -1,49 +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 '../lib/zold/key'
|
|
27
|
-
require_relative '../lib/zold/id'
|
|
28
|
-
require_relative '../lib/zold/txn'
|
|
29
|
-
require_relative '../lib/zold/amount'
|
|
30
|
-
require_relative '../lib/zold/signature'
|
|
31
|
-
|
|
32
|
-
# Signature test.
|
|
33
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
34
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
35
|
-
# License:: MIT
|
|
36
|
-
class TestSignature < Zold::Test
|
|
37
|
-
def test_signs_and_validates
|
|
38
|
-
pvt = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
39
|
-
pub = Zold::Key.new(file: 'fixtures/id_rsa.pub')
|
|
40
|
-
txn = Zold::Txn.new(
|
|
41
|
-
123, Time.now, Zold::Amount.new(zld: 14.95),
|
|
42
|
-
'NOPREFIX', Zold::Id.new, 'hello, world!'
|
|
43
|
-
)
|
|
44
|
-
id = Zold::Id.new
|
|
45
|
-
txn = txn.signed(pvt, id)
|
|
46
|
-
assert_equal(684, txn.sign.length)
|
|
47
|
-
assert(Zold::Signature.new.valid?(pub, id, txn))
|
|
48
|
-
end
|
|
49
|
-
end
|