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_front.rb
DELETED
|
@@ -1,399 +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 'json'
|
|
25
|
-
require 'time'
|
|
26
|
-
require 'securerandom'
|
|
27
|
-
require 'threads'
|
|
28
|
-
require 'zold/score'
|
|
29
|
-
require 'memory_profiler'
|
|
30
|
-
require_relative '../test__helper'
|
|
31
|
-
require_relative 'fake_node'
|
|
32
|
-
require_relative '../fake_home'
|
|
33
|
-
require_relative '../../lib/zold/http'
|
|
34
|
-
require_relative '../../lib/zold/age'
|
|
35
|
-
require_relative '../../lib/zold/json_page'
|
|
36
|
-
|
|
37
|
-
class FrontTest < Zold::Test
|
|
38
|
-
def app
|
|
39
|
-
Zold::Front
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Use this test to check how much memory is being used after doing a large
|
|
43
|
-
# number of routine operations. There should be no suspicious information
|
|
44
|
-
# in the report, which will be printed to the console.
|
|
45
|
-
def test_memory_leakage
|
|
46
|
-
skip
|
|
47
|
-
report = MemoryProfiler.report(top: 10) do
|
|
48
|
-
FakeNode.new(log: fake_log).run(opts('--network=foo')) do |port|
|
|
49
|
-
100.times do
|
|
50
|
-
Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo').get
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
report.pretty_print
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_renders_front_json
|
|
58
|
-
FakeNode.new(log: fake_log).run(opts('--network=foo')) do |port|
|
|
59
|
-
res = Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo').get
|
|
60
|
-
json = JSON.parse(res.body)
|
|
61
|
-
assert_equal(Zold::VERSION, json['version'])
|
|
62
|
-
assert_equal(Zold::PROTOCOL, json['protocol'])
|
|
63
|
-
assert_equal('foo', json['network'])
|
|
64
|
-
assert_equal('zold-io/zold', json['repo'])
|
|
65
|
-
assert(json['pid'].positive?, json)
|
|
66
|
-
assert(json['cpus'].positive?, json)
|
|
67
|
-
assert(!json['journal'].negative?, json)
|
|
68
|
-
assert(json['memory'].positive?, json)
|
|
69
|
-
assert(!json['load'].negative?, json)
|
|
70
|
-
assert(json['wallets'].positive?, json)
|
|
71
|
-
assert(json['remotes'].zero?, json)
|
|
72
|
-
assert(json['nscore'].zero?, json)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_renders_public_pages
|
|
77
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
78
|
-
{
|
|
79
|
-
200 => [
|
|
80
|
-
'/robots.txt',
|
|
81
|
-
'/',
|
|
82
|
-
'/remotes',
|
|
83
|
-
'/version',
|
|
84
|
-
'/protocol',
|
|
85
|
-
'/farm',
|
|
86
|
-
'/ledger',
|
|
87
|
-
'/ledger.json',
|
|
88
|
-
'/metronome',
|
|
89
|
-
'/journal',
|
|
90
|
-
'/score',
|
|
91
|
-
'/queue',
|
|
92
|
-
'/trace',
|
|
93
|
-
'/threads',
|
|
94
|
-
'/ps'
|
|
95
|
-
],
|
|
96
|
-
404 => [
|
|
97
|
-
'/this-is-absent',
|
|
98
|
-
'/wallet/ffffeeeeddddcccc',
|
|
99
|
-
'/wallet/ffffeeeeddddcccc.bin',
|
|
100
|
-
'/wallet/ffffeeeeddddcccc.txt',
|
|
101
|
-
'/wallet/ffffeeeeddddcccc/balance',
|
|
102
|
-
'/wallet/ffffeeeeddddcccc/key',
|
|
103
|
-
'/wallet/ffffeeeeddddcccc/mtime',
|
|
104
|
-
'/wallet/ffffeeeeddddcccc/digest'
|
|
105
|
-
]
|
|
106
|
-
}.each do |code, paths|
|
|
107
|
-
paths.each do |p|
|
|
108
|
-
uri = URI("http://localhost:#{port}#{p}")
|
|
109
|
-
response = Zold::Http.new(uri: uri).get
|
|
110
|
-
assert_equal(
|
|
111
|
-
code, response.status,
|
|
112
|
-
"Invalid response code for #{uri}: #{response.status_line}"
|
|
113
|
-
)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def test_updates_list_of_remotes
|
|
120
|
-
FakeNode.new(log: fake_log).run(['--no-metronome', '--ignore-score-weakness', '--no-cache']) do |port|
|
|
121
|
-
(Zold::Remotes::MAX_NODES + 5).times do |i|
|
|
122
|
-
score = Zold::Score.new(
|
|
123
|
-
host: 'localhost', port: i + 1, invoice: 'NOPREFIX@ffffffffffffffff', strength: 1
|
|
124
|
-
).next.next.next.next
|
|
125
|
-
response = Zold::Http.new(uri: "http://localhost:#{port}/remotes", score: score).get
|
|
126
|
-
assert_equal(200, response.status, response.body)
|
|
127
|
-
assert_equal(
|
|
128
|
-
[i + 1, Zold::Remotes::MAX_NODES + 1].min,
|
|
129
|
-
Zold::JsonPage.new(response.body).to_hash['all'].count, response.body
|
|
130
|
-
)
|
|
131
|
-
assert_match(
|
|
132
|
-
/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z/,
|
|
133
|
-
Zold::JsonPage.new(response.body).to_hash['mtime'].to_s,
|
|
134
|
-
response.body
|
|
135
|
-
)
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def test_increments_score
|
|
141
|
-
FakeNode.new(log: fake_log).run(opts('--threads=1')) do |port|
|
|
142
|
-
3.times do |i|
|
|
143
|
-
assert_equal_wait(true, max: 120) do
|
|
144
|
-
response = Zold::Http.new(uri: "http://localhost:#{port}/").get
|
|
145
|
-
assert_equal(200, response.status, response.body)
|
|
146
|
-
score = Zold::Score.parse_json(Zold::JsonPage.new(response.body).to_hash['score'])
|
|
147
|
-
score.value >= i
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
[
|
|
154
|
-
'.txt', '.html',
|
|
155
|
-
'/balance', '/key', '/mtime',
|
|
156
|
-
'/digest', '/size',
|
|
157
|
-
'/age', '/mnemo', '/debt', '/txns',
|
|
158
|
-
'/txns.json', '.bin', '/copies'
|
|
159
|
-
].each do |p|
|
|
160
|
-
method = "test_wallet_page_#{p.gsub(/[^a-z]/, '_')}"
|
|
161
|
-
define_method(method) do
|
|
162
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
163
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
164
|
-
wallet = home.create_wallet(txns: 2)
|
|
165
|
-
base = "http://localhost:#{port}"
|
|
166
|
-
response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path)
|
|
167
|
-
assert_equal(200, response.status, response.body)
|
|
168
|
-
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
|
169
|
-
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}#{p}").get.status }
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def test_renders_wallets_page
|
|
176
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
177
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
178
|
-
wallet = home.create_wallet(txns: 2)
|
|
179
|
-
base = "http://localhost:#{port}"
|
|
180
|
-
response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path)
|
|
181
|
-
assert_equal(200, response.status, response.body)
|
|
182
|
-
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
|
183
|
-
response = Zold::Http.new(uri: "#{base}/wallets").get
|
|
184
|
-
assert_equal(200, response.status, response.body)
|
|
185
|
-
assert(response.body.to_s.split("\n").include?(wallet.id.to_s), response.body)
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def test_fetch_in_multiple_threads
|
|
191
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
192
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
193
|
-
wallet = home.create_wallet
|
|
194
|
-
base = "http://localhost:#{port}"
|
|
195
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path)
|
|
196
|
-
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
|
197
|
-
threads = []
|
|
198
|
-
mutex = Mutex.new
|
|
199
|
-
Threads.new(6).assert(100) do
|
|
200
|
-
assert_equal_wait(200) do
|
|
201
|
-
res = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get
|
|
202
|
-
mutex.synchronize { threads << res.headers['X-Zold-Thread'] }
|
|
203
|
-
res.status
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
assert(threads.uniq.count > 1)
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def test_pushes_twice
|
|
212
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
213
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
214
|
-
wallet = home.create_wallet
|
|
215
|
-
base = "http://localhost:#{port}"
|
|
216
|
-
assert_equal(
|
|
217
|
-
200,
|
|
218
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path).status
|
|
219
|
-
)
|
|
220
|
-
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
|
221
|
-
3.times do
|
|
222
|
-
r = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path)
|
|
223
|
-
assert_equal(304, r.status, r.body)
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def test_pushes_many_wallets
|
|
230
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
231
|
-
base = "http://localhost:#{port}"
|
|
232
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
233
|
-
Threads.new(5).assert do
|
|
234
|
-
wallet = home.create_wallet
|
|
235
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path)
|
|
236
|
-
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
def test_different_logos
|
|
243
|
-
{
|
|
244
|
-
'0' => 'https://www.zold.io/images/logo-red.png',
|
|
245
|
-
'4' => 'https://www.zold.io/images/logo-orange.png',
|
|
246
|
-
'16' => 'https://www.zold.io/images/logo-green.png'
|
|
247
|
-
}.each do |num, path|
|
|
248
|
-
score = Zold::Score.new(
|
|
249
|
-
host: 'localhost', port: 999,
|
|
250
|
-
invoice: 'NOPREFIX@ffffffffffffffff',
|
|
251
|
-
strength: 1
|
|
252
|
-
)
|
|
253
|
-
num.to_i.times do
|
|
254
|
-
score = score.next
|
|
255
|
-
end
|
|
256
|
-
if score.value >= 16
|
|
257
|
-
assert_equal(
|
|
258
|
-
path, 'https://www.zold.io/images/logo-green.png',
|
|
259
|
-
"Expected #{path} for score #{score.value}"
|
|
260
|
-
)
|
|
261
|
-
elsif score.value >= 4
|
|
262
|
-
assert_equal(
|
|
263
|
-
path, 'https://www.zold.io/images/logo-orange.png',
|
|
264
|
-
"Expected #{path} for score #{score.value}"
|
|
265
|
-
)
|
|
266
|
-
else
|
|
267
|
-
assert_equal(
|
|
268
|
-
path, 'https://www.zold.io/images/logo-red.png',
|
|
269
|
-
"Expected #{path} for score #{score.value}"
|
|
270
|
-
)
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
def test_gzip
|
|
276
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
277
|
-
response = Zold::Http.new(uri: URI("http://localhost:#{port}/version")).get
|
|
278
|
-
assert_equal(200, response.status, response)
|
|
279
|
-
assert_operator(300, :>, response.body.length.to_i, 'Expected the content to be small')
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
def test_performance
|
|
284
|
-
times = Queue.new
|
|
285
|
-
FakeNode.new(log: fake_log).run(opts('--threads=4', '--strength=6')) do |port|
|
|
286
|
-
Threads.new(10).assert(100) do
|
|
287
|
-
start = Time.now
|
|
288
|
-
Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
|
|
289
|
-
times << (Time.now - start)
|
|
290
|
-
end
|
|
291
|
-
end
|
|
292
|
-
all = []
|
|
293
|
-
all << times.pop(true) until times.empty?
|
|
294
|
-
fake_log.info("Average response time is #{all.inject(&:+) / all.count}")
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
# The score exposed via the HTTP header must be reduced to the value of 16.
|
|
298
|
-
# We need this in order to optimize the amount of data we transfer in each
|
|
299
|
-
# HTTP request. This value is enough to identify a valueable node, and filter
|
|
300
|
-
# out those that are too weak.
|
|
301
|
-
def test_score_is_reduced
|
|
302
|
-
FakeNode.new(log: fake_log).run(opts('--threads=1', '--strength=1', '--farmer=plain')) do |port|
|
|
303
|
-
scores = []
|
|
304
|
-
50.times do
|
|
305
|
-
res = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
|
|
306
|
-
scores << Zold::Score.parse(res.headers[Zold::Http::SCORE_HEADER]).value
|
|
307
|
-
sleep(0.1)
|
|
308
|
-
end
|
|
309
|
-
assert(scores.uniq.sort.reverse[0] <= Zold::Front::MIN_SCORE)
|
|
310
|
-
end
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
def test_headers_are_being_set_correctly
|
|
314
|
-
FakeNode.new(log: fake_log).run(opts('--expose-version=9.9.9')) do |port|
|
|
315
|
-
response = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
|
|
316
|
-
assert_equal('no-cache', response.headers['Cache-Control'])
|
|
317
|
-
assert_equal('close', response.headers['Connection'])
|
|
318
|
-
assert_equal('9.9.9', response.headers['X-Zold-Version'])
|
|
319
|
-
assert_equal(app.settings.protocol.to_s, response.headers[Zold::Http::PROTOCOL_HEADER])
|
|
320
|
-
assert_equal('*', response.headers['Access-Control-Allow-Origin'])
|
|
321
|
-
assert(response.headers['X-Zold-Milliseconds'])
|
|
322
|
-
assert(!response.headers[Zold::Http::SCORE_HEADER].nil?)
|
|
323
|
-
end
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
def test_alias_parameter
|
|
327
|
-
name = SecureRandom.hex(4)
|
|
328
|
-
FakeNode.new(log: fake_log).run(opts("--alias=#{name}")) do |port|
|
|
329
|
-
uri = URI("http://localhost:#{port}/")
|
|
330
|
-
response = Zold::Http.new(uri: uri).get
|
|
331
|
-
assert_match(
|
|
332
|
-
name,
|
|
333
|
-
Zold::JsonPage.new(response.body).to_hash['alias'].to_s,
|
|
334
|
-
response.body
|
|
335
|
-
)
|
|
336
|
-
end
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
def test_default_alias_parameter
|
|
340
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
341
|
-
uri = URI("http://localhost:#{port}/")
|
|
342
|
-
response = Zold::Http.new(uri: uri).get
|
|
343
|
-
assert_match(
|
|
344
|
-
"localhost:#{port}",
|
|
345
|
-
Zold::JsonPage.new(response.body).to_hash['alias'].to_s,
|
|
346
|
-
response.body
|
|
347
|
-
)
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
def test_invalid_alias
|
|
352
|
-
skip
|
|
353
|
-
exception = assert_raises RuntimeError do
|
|
354
|
-
FakeNode.new(log: fake_log).run(opts('--alias=invalid-alias')) do |port|
|
|
355
|
-
uri = URI("http://localhost:#{port}/")
|
|
356
|
-
Zold::Http.new(uri: uri).get
|
|
357
|
-
end
|
|
358
|
-
end
|
|
359
|
-
assert(exception.message.include?('should be a 4 to 16 char long'), exception.message)
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
def test_push_fetch_in_multiple_threads
|
|
363
|
-
key = Zold::Key.new(text: File.read('fixtures/id_rsa'))
|
|
364
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
365
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
366
|
-
wallet = home.create_wallet(Zold::Id::ROOT)
|
|
367
|
-
base = "http://localhost:#{port}"
|
|
368
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path)
|
|
369
|
-
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
|
370
|
-
cycles = 50
|
|
371
|
-
cycles.times do
|
|
372
|
-
wallet.sub(Zold::Amount.new(zents: 10), "NOPREFIX@#{Zold::Id.new}", key)
|
|
373
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(wallet.path)
|
|
374
|
-
assert_equal(200, Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status)
|
|
375
|
-
end
|
|
376
|
-
assert_equal_wait(-10 * cycles) do
|
|
377
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}/balance").get.body.to_i
|
|
378
|
-
end
|
|
379
|
-
end
|
|
380
|
-
end
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
def test_checksum_in_json
|
|
384
|
-
FakeNode.new(log: fake_log).run(opts) do |port|
|
|
385
|
-
uri = URI("http://localhost:#{port}/")
|
|
386
|
-
response = Zold::Http.new(uri: uri).get
|
|
387
|
-
assert(
|
|
388
|
-
Zold::JsonPage.new(response.body).to_hash.key?('checksum'),
|
|
389
|
-
response.body
|
|
390
|
-
)
|
|
391
|
-
end
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
private
|
|
395
|
-
|
|
396
|
-
def opts(*extra)
|
|
397
|
-
['--no-metronome', '--ignore-score-weakness', '--standalone', '--threads=0', '--strength=1'] + extra
|
|
398
|
-
end
|
|
399
|
-
end
|
|
@@ -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_relative '../fake_home'
|
|
25
|
-
require_relative '../test__helper'
|
|
26
|
-
require_relative '../../lib/zold/id'
|
|
27
|
-
require_relative '../../lib/zold/node/nodup_entrance'
|
|
28
|
-
require_relative 'fake_entrance'
|
|
29
|
-
|
|
30
|
-
# NoDupEntrance test.
|
|
31
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
32
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
33
|
-
# License:: MIT
|
|
34
|
-
class TestNoDupEntrance < Zold::Test
|
|
35
|
-
def test_ignores_dup
|
|
36
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
37
|
-
wallet = home.create_wallet
|
|
38
|
-
Zold::NoDupEntrance.new(RealEntrance.new, home.wallets, log: fake_log).start do |e|
|
|
39
|
-
assert(e.push(wallet.id, File.read(wallet.path)).empty?)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
class RealEntrance < FakeEntrance
|
|
45
|
-
def push(id, _)
|
|
46
|
-
[id]
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -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_relative '../test__helper'
|
|
25
|
-
require_relative '../../lib/zold/id'
|
|
26
|
-
require_relative '../../lib/zold/node/nospam_entrance'
|
|
27
|
-
require_relative 'fake_entrance'
|
|
28
|
-
|
|
29
|
-
# NoSpamEntrance test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestNoSpamEntrance < Zold::Test
|
|
34
|
-
def test_ignores_spam
|
|
35
|
-
Zold::NoSpamEntrance.new(RealEntrance.new, log: fake_log).start do |e|
|
|
36
|
-
id = Zold::Id.new
|
|
37
|
-
content = 'hello'
|
|
38
|
-
assert(!e.push(id, content).empty?)
|
|
39
|
-
assert(e.push(id, content).empty?)
|
|
40
|
-
assert(e.push(id, content).empty?)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
class RealEntrance < FakeEntrance
|
|
45
|
-
def push(id, _)
|
|
46
|
-
[id]
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,59 +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/wallet'
|
|
27
|
-
require_relative '../../lib/zold/id'
|
|
28
|
-
require_relative '../../lib/zold/key'
|
|
29
|
-
require_relative '../../lib/zold/node/safe_entrance'
|
|
30
|
-
require_relative '../../lib/zold/node/soft_error'
|
|
31
|
-
require_relative 'fake_entrance'
|
|
32
|
-
|
|
33
|
-
# SafeEntrance test.
|
|
34
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
36
|
-
# License:: MIT
|
|
37
|
-
class TestSafeEntrance < Zold::Test
|
|
38
|
-
def test_rejects_wallet_with_negative_balance
|
|
39
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
40
|
-
wallet = home.create_wallet
|
|
41
|
-
amount = Zold::Amount.new(zld: 39.99)
|
|
42
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
43
|
-
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
|
44
|
-
assert_raises Zold::SoftError do
|
|
45
|
-
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id, File.read(wallet.path))
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_rejects_wallet_with_wrong_network
|
|
51
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
52
|
-
wallet = Zold::Wallet.new(File.join(home.dir, 'wallet.z'))
|
|
53
|
-
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'), network: 'someothernetwork')
|
|
54
|
-
assert_raises StandardError do
|
|
55
|
-
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id, File.read(wallet.path))
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,67 +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 'fake_node'
|
|
26
|
-
require_relative '../test__helper'
|
|
27
|
-
require_relative '../../lib/zold/id'
|
|
28
|
-
require_relative '../../lib/zold/node/entrance'
|
|
29
|
-
require_relative '../../lib/zold/node/pipeline'
|
|
30
|
-
require_relative '../../lib/zold/node/spread_entrance'
|
|
31
|
-
require_relative 'fake_entrance'
|
|
32
|
-
|
|
33
|
-
# SpreadEntrance test.
|
|
34
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
36
|
-
# License:: MIT
|
|
37
|
-
class TestSpreadEntrance < Zold::Test
|
|
38
|
-
def test_renders_json
|
|
39
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
40
|
-
wallet = home.create_wallet(Zold::Id.new)
|
|
41
|
-
Zold::SpreadEntrance.new(
|
|
42
|
-
Zold::Entrance.new(
|
|
43
|
-
home.wallets,
|
|
44
|
-
Zold::Pipeline.new(home.remotes, home.copies(wallet).root, 'x'),
|
|
45
|
-
log: fake_log
|
|
46
|
-
),
|
|
47
|
-
home.wallets, home.remotes, 'x', log: fake_log
|
|
48
|
-
).start do |e|
|
|
49
|
-
assert_equal(0, e.to_json[:modified])
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_ignores_duplicates
|
|
55
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
56
|
-
FakeNode.new(log: fake_log).run(['--ignore-score-weakness']) do |port|
|
|
57
|
-
wallet = home.create_wallet
|
|
58
|
-
remotes = home.remotes
|
|
59
|
-
remotes.add('localhost', port)
|
|
60
|
-
Zold::SpreadEntrance.new(FakeEntrance.new, home.wallets, remotes, 'x', log: fake_log).start do |e|
|
|
61
|
-
8.times { e.push(wallet.id, File.read(wallet.path)) }
|
|
62
|
-
assert(e.to_json[:modified] < 2, "It's too big: #{e.to_json[:modified]}")
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
@@ -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 'minitest/autorun'
|
|
24
|
-
require_relative '../fake_home'
|
|
25
|
-
require_relative '../test__helper'
|
|
26
|
-
require_relative '../../lib/zold/node/sync_entrance'
|
|
27
|
-
require_relative 'fake_entrance'
|
|
28
|
-
|
|
29
|
-
# SyncEntrance test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestSyncEntrance < Zold::Test
|
|
34
|
-
def test_renders_json
|
|
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
|
-
assert(!e.to_json.nil?)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|