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
|
@@ -1,265 +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 'zold/score'
|
|
27
|
-
require_relative '../test__helper'
|
|
28
|
-
require_relative '../../lib/zold/version'
|
|
29
|
-
require_relative '../../lib/zold/wallets'
|
|
30
|
-
require_relative '../../lib/zold/remotes'
|
|
31
|
-
require_relative '../../lib/zold/key'
|
|
32
|
-
require_relative '../../lib/zold/log'
|
|
33
|
-
require_relative '../../lib/zold/commands/remote'
|
|
34
|
-
|
|
35
|
-
# REMOTE test.
|
|
36
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
37
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
38
|
-
# License:: MIT
|
|
39
|
-
class TestRemote < Zold::Test
|
|
40
|
-
def test_updates_remote
|
|
41
|
-
Dir.mktmpdir do |dir|
|
|
42
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'a/b/c/remotes'))
|
|
43
|
-
zero = Zold::Score::ZERO
|
|
44
|
-
stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
|
|
45
|
-
status: 200,
|
|
46
|
-
headers: {},
|
|
47
|
-
body: {
|
|
48
|
-
version: Zold::VERSION,
|
|
49
|
-
score: zero.to_h,
|
|
50
|
-
all: [
|
|
51
|
-
{ host: 'localhost', port: 888 },
|
|
52
|
-
{ host: 'localhost', port: 999 }
|
|
53
|
-
]
|
|
54
|
-
}.to_json
|
|
55
|
-
)
|
|
56
|
-
stub_request(:get, 'http://localhost:2/remotes').to_return(
|
|
57
|
-
status: 404
|
|
58
|
-
)
|
|
59
|
-
stub_request(:get, 'http://localhost:888/remotes').to_return(
|
|
60
|
-
status: 404
|
|
61
|
-
)
|
|
62
|
-
stub_request(:get, 'http://localhost:999/remotes').to_return(
|
|
63
|
-
status: 404
|
|
64
|
-
)
|
|
65
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
|
|
66
|
-
status: 200,
|
|
67
|
-
headers: {},
|
|
68
|
-
body: '{"version": "0.0.0"}'
|
|
69
|
-
)
|
|
70
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
71
|
-
cmd.run(%w[remote clean])
|
|
72
|
-
assert(remotes.all.empty?)
|
|
73
|
-
cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
|
|
74
|
-
cmd.run(%w[remote add localhost 2 --skip-ping])
|
|
75
|
-
assert_equal(2, remotes.all.count)
|
|
76
|
-
cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping'])
|
|
77
|
-
assert_equal(4, remotes.all.count, remotes.all)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def test_new_version_rubygems
|
|
82
|
-
Dir.mktmpdir do |dir|
|
|
83
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
84
|
-
zero = Zold::Score::ZERO
|
|
85
|
-
stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
|
|
86
|
-
status: 200,
|
|
87
|
-
body: {
|
|
88
|
-
version: Zold::VERSION,
|
|
89
|
-
score: zero.to_h,
|
|
90
|
-
repo: Zold::REPO,
|
|
91
|
-
all: [
|
|
92
|
-
{ host: zero.host, port: zero.port }
|
|
93
|
-
]
|
|
94
|
-
}.to_json
|
|
95
|
-
)
|
|
96
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
|
|
97
|
-
status: 200,
|
|
98
|
-
body: "{\"version\": \"9.9.9\", \"repo\": \"#{Zold::REPO}\"}"
|
|
99
|
-
)
|
|
100
|
-
log = TestLogger.new
|
|
101
|
-
cmd = Zold::Remote.new(remotes: remotes, log: log)
|
|
102
|
-
cmd.run(%w[remote clean])
|
|
103
|
-
cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
|
|
104
|
-
cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping', '--reboot'])
|
|
105
|
-
assert(log.msgs.to_s.include?(', reboot!'))
|
|
106
|
-
log.msgs = []
|
|
107
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
|
|
108
|
-
status: 200,
|
|
109
|
-
body: "{\"version\": \"#{Zold::VERSION}\"}"
|
|
110
|
-
)
|
|
111
|
-
cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping', '--reboot'])
|
|
112
|
-
assert(!log.msgs.to_s.include?(', reboot!'))
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def test_elects_a_remote
|
|
117
|
-
Dir.mktmpdir do |dir|
|
|
118
|
-
zero = Zold::Score::ZERO
|
|
119
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
120
|
-
remotes.clean
|
|
121
|
-
remotes.add(zero.host, zero.port)
|
|
122
|
-
stub_request(:get, "http://#{zero.host}:#{zero.port}/").to_return(
|
|
123
|
-
status: 200,
|
|
124
|
-
body: {
|
|
125
|
-
version: Zold::VERSION,
|
|
126
|
-
score: zero.to_h
|
|
127
|
-
}.to_json
|
|
128
|
-
)
|
|
129
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
130
|
-
winners = cmd.run(%w[remote elect --ignore-score-value])
|
|
131
|
-
assert_equal(1, winners.count)
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def test_resets_remotes
|
|
136
|
-
Dir.mktmpdir do |dir|
|
|
137
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
138
|
-
Zold::Remote.new(remotes: remotes, log: fake_log).run(%w[remote reset])
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def test_remote_trim_with_tolerate
|
|
143
|
-
Dir.mktmpdir do |dir|
|
|
144
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
145
|
-
score = Zold::Score.new(
|
|
146
|
-
host: 'aa1.example.org', port: 9999, invoice: 'NOPREFIX4@ffffffffffffffff'
|
|
147
|
-
)
|
|
148
|
-
stub_request(:get, 'http://localhost:8883/version').to_return(
|
|
149
|
-
status: 200,
|
|
150
|
-
body: '0.0.0'
|
|
151
|
-
)
|
|
152
|
-
stub_request(:get, "http://#{score.host}:#{score.port}/remotes").to_return(
|
|
153
|
-
status: 200,
|
|
154
|
-
body: {
|
|
155
|
-
version: Zold::VERSION,
|
|
156
|
-
score: score.to_h,
|
|
157
|
-
all: [
|
|
158
|
-
{ host: 'localhost', port: 8883 }
|
|
159
|
-
]
|
|
160
|
-
}.to_json
|
|
161
|
-
)
|
|
162
|
-
stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
|
|
163
|
-
status: 200,
|
|
164
|
-
body: '{"version": "0.0.0"}'
|
|
165
|
-
)
|
|
166
|
-
stub_request(:get, 'http://localhost:8883/remotes').to_return(status: 404)
|
|
167
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
168
|
-
cmd.run(%w[remote clean])
|
|
169
|
-
assert(remotes.all.empty?)
|
|
170
|
-
cmd.run(['remote', 'add', score.host, score.port.to_s, '--skip-ping'])
|
|
171
|
-
cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping'])
|
|
172
|
-
assert_equal(2, remotes.all.count)
|
|
173
|
-
cmd.run(['remote', 'update', '--ignore-score-weakness'])
|
|
174
|
-
cmd.run(['remote', 'trim', '--tolerate=0'])
|
|
175
|
-
assert_equal(1, remotes.all.count, remotes.all)
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_select_selects_the_strongest_nodes
|
|
180
|
-
Dir.mktmpdir do |dir|
|
|
181
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
182
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
183
|
-
(1..11).each do |i|
|
|
184
|
-
cmd.run(%W[remote add localhost #{i} --skip-ping])
|
|
185
|
-
remotes.rescore('localhost', i, i)
|
|
186
|
-
i.times { remotes.error('localhost', i) }
|
|
187
|
-
end
|
|
188
|
-
cmd.run(%w[remote select --max-nodes=5])
|
|
189
|
-
assert_equal(5, remotes.all.count)
|
|
190
|
-
scores = remotes.all.map { |r| r[:score] }
|
|
191
|
-
assert_equal([7, 8, 9, 10, 11], scores.sort)
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def test_select_respects_max_nodes_option
|
|
196
|
-
Dir.mktmpdir do |dir|
|
|
197
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
198
|
-
remotes.masters
|
|
199
|
-
zero = Zold::Score::ZERO
|
|
200
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
201
|
-
(5000..5010).each do |port|
|
|
202
|
-
stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
|
|
203
|
-
status: 200,
|
|
204
|
-
body: {
|
|
205
|
-
version: Zold::VERSION,
|
|
206
|
-
score: zero.to_h,
|
|
207
|
-
all: [
|
|
208
|
-
{ host: 'localhost', port: port }
|
|
209
|
-
]
|
|
210
|
-
}.to_json
|
|
211
|
-
)
|
|
212
|
-
stub_request(:get, "http://localhost:#{port}/version").to_return(
|
|
213
|
-
status: 200,
|
|
214
|
-
body: {
|
|
215
|
-
version: Zold::VERSION
|
|
216
|
-
}.to_json
|
|
217
|
-
)
|
|
218
|
-
cmd.run(%W[remote add localhost #{port}])
|
|
219
|
-
end
|
|
220
|
-
assert_equal(11 + File.readlines('resources/masters').count, remotes.all.count)
|
|
221
|
-
cmd.run(%w[remote select --max-nodes=5 --masters-too])
|
|
222
|
-
assert_equal(5, remotes.all.count)
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
def test_sets_masters
|
|
227
|
-
Dir.mktmpdir do |dir|
|
|
228
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
229
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
230
|
-
cmd.run(%w[remote masters])
|
|
231
|
-
assert(!remotes.all.empty?)
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def test_select_doesnt_touch_masters
|
|
236
|
-
Dir.mktmpdir do |dir|
|
|
237
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
|
|
238
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
239
|
-
cmd.run(%w[remote masters])
|
|
240
|
-
cmd.run(%w[remote select --max-nodes=0])
|
|
241
|
-
assert(!remotes.all.empty?)
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
def test_updates_just_once
|
|
246
|
-
Dir.mktmpdir do |dir|
|
|
247
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'a/b/c/remotes'))
|
|
248
|
-
zero = Zold::Score::ZERO
|
|
249
|
-
get = stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
|
|
250
|
-
status: 200,
|
|
251
|
-
headers: {},
|
|
252
|
-
body: {
|
|
253
|
-
version: Zold::VERSION,
|
|
254
|
-
score: zero.to_h,
|
|
255
|
-
all: []
|
|
256
|
-
}.to_json
|
|
257
|
-
)
|
|
258
|
-
cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
|
|
259
|
-
cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
|
|
260
|
-
cmd.run(['remote', 'update', '--ignore-score-weakness', '--depth=10'])
|
|
261
|
-
assert_equal(1, remotes.all.count)
|
|
262
|
-
assert_requested(get, times: 1)
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
end
|
|
@@ -1,66 +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/commands/remove'
|
|
27
|
-
|
|
28
|
-
# REMOVE test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestRemove < Zold::Test
|
|
33
|
-
def test_removes_one_wallet
|
|
34
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
35
|
-
wallet = home.create_wallet
|
|
36
|
-
assert_equal(1, home.wallets.all.count)
|
|
37
|
-
Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove', wallet.id.to_s])
|
|
38
|
-
assert(home.wallets.all.empty?)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_removes_wallets
|
|
43
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
44
|
-
home.create_wallet
|
|
45
|
-
home.create_wallet
|
|
46
|
-
Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove'])
|
|
47
|
-
assert(home.wallets.all.empty?)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_removes_no_wallets
|
|
52
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
53
|
-
Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove'])
|
|
54
|
-
assert(home.wallets.all.empty?)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_removes_absent_wallets
|
|
59
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
60
|
-
Zold::Remove.new(wallets: home.wallets, log: fake_log).run(
|
|
61
|
-
['remove', '7654321076543210', '--force']
|
|
62
|
-
)
|
|
63
|
-
assert(home.wallets.all.empty?)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
data/test/commands/test_show.rb
DELETED
|
@@ -1,48 +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/wallets'
|
|
27
|
-
require_relative '../../lib/zold/wallet'
|
|
28
|
-
require_relative '../../lib/zold/key'
|
|
29
|
-
require_relative '../../lib/zold/id'
|
|
30
|
-
require_relative '../../lib/zold/commands/show'
|
|
31
|
-
|
|
32
|
-
# SHOW test.
|
|
33
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
34
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
35
|
-
# License:: MIT
|
|
36
|
-
class TestShow < Zold::Test
|
|
37
|
-
def test_checks_wallet_balance
|
|
38
|
-
Dir.mktmpdir do |dir|
|
|
39
|
-
id = Zold::Id.new
|
|
40
|
-
wallets = Zold::Wallets.new(dir)
|
|
41
|
-
wallets.acq(id) do |wallet|
|
|
42
|
-
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
|
43
|
-
balance = Zold::Show.new(wallets: wallets, copies: File.join(dir, 'c'), log: fake_log).run(['show', id.to_s])
|
|
44
|
-
assert_equal(Zold::Amount::ZERO, balance)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
data/test/commands/test_taxes.rb
DELETED
|
@@ -1,76 +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_relative '../test__helper'
|
|
27
|
-
require_relative '../fake_home'
|
|
28
|
-
require_relative '../../lib/zold/wallets'
|
|
29
|
-
require_relative '../../lib/zold/amount'
|
|
30
|
-
require_relative '../../lib/zold/key'
|
|
31
|
-
require_relative '../../lib/zold/log'
|
|
32
|
-
require_relative '../../lib/zold/id'
|
|
33
|
-
require_relative '../../lib/zold/commands/taxes'
|
|
34
|
-
|
|
35
|
-
# TAXES test.
|
|
36
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
37
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
38
|
-
# License:: MIT
|
|
39
|
-
class TestTaxes < Zold::Test
|
|
40
|
-
def test_pays_taxes
|
|
41
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
42
|
-
wallets = home.wallets
|
|
43
|
-
wallet = home.create_wallet
|
|
44
|
-
fund = Zold::Amount.new(zld: 19.99)
|
|
45
|
-
10.times do |i|
|
|
46
|
-
wallet.add(
|
|
47
|
-
Zold::Txn.new(
|
|
48
|
-
i + 1,
|
|
49
|
-
Time.now - (24 * 60 * 60 * 365 * 300),
|
|
50
|
-
fund,
|
|
51
|
-
'NOPREFIX', Zold::Id.new, '-'
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
end
|
|
55
|
-
remotes = home.remotes
|
|
56
|
-
score = Zold::Score.new(host: 'localhost', port: 80, strength: 1, invoice: 'NOPREFIX@0000000000000000')
|
|
57
|
-
10.times { score = score.next }
|
|
58
|
-
remotes.add(score.host, score.port)
|
|
59
|
-
stub_request(:get, "http://#{score.host}:#{score.port}/").to_return(
|
|
60
|
-
status: 200,
|
|
61
|
-
body: {
|
|
62
|
-
score: score.to_h
|
|
63
|
-
}.to_json
|
|
64
|
-
)
|
|
65
|
-
before = wallet.balance
|
|
66
|
-
tax = Zold::Tax.new(wallet, ignore_score_weakness: true)
|
|
67
|
-
debt = tax.debt
|
|
68
|
-
Zold::Taxes.new(wallets: wallets, remotes: remotes, log: fake_log).run(
|
|
69
|
-
['taxes', '--private-key=fixtures/id_rsa', '--ignore-score-weakness', 'pay', wallet.id.to_s]
|
|
70
|
-
)
|
|
71
|
-
wallet.flush
|
|
72
|
-
assert(tax.paid.positive?, tax.paid)
|
|
73
|
-
assert_equal((before - debt).to_zld(6), wallet.balance.to_zld(6))
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
data/test/fake_home.rb
DELETED
|
@@ -1,104 +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 'tmpdir'
|
|
24
|
-
require_relative '../lib/zold/log'
|
|
25
|
-
require_relative '../lib/zold/id'
|
|
26
|
-
require_relative '../lib/zold/wallet'
|
|
27
|
-
require_relative '../lib/zold/wallets'
|
|
28
|
-
require_relative '../lib/zold/sync_wallets'
|
|
29
|
-
require_relative '../lib/zold/cached_wallets'
|
|
30
|
-
require_relative '../lib/zold/key'
|
|
31
|
-
require_relative '../lib/zold/version'
|
|
32
|
-
require_relative '../lib/zold/remotes'
|
|
33
|
-
|
|
34
|
-
# Fake home dir.
|
|
35
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
36
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
37
|
-
# License:: MIT
|
|
38
|
-
class FakeHome
|
|
39
|
-
attr_reader :dir
|
|
40
|
-
|
|
41
|
-
def initialize(dir = __dir__, log: Zold::Log::NULL)
|
|
42
|
-
@dir = dir
|
|
43
|
-
@log = log
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def run
|
|
47
|
-
Dir.mktmpdir do |dir|
|
|
48
|
-
FileUtils.copy(File.expand_path(File.join(__dir__, '../fixtures/id_rsa')), File.join(dir, 'id_rsa'))
|
|
49
|
-
yield FakeHome.new(dir, log: @log)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def wallets
|
|
54
|
-
Zold::SyncWallets.new(Zold::CachedWallets.new(Zold::Wallets.new(@dir)), log: @log)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def create_wallet(id = Zold::Id.new, dir = @dir, txns: 0)
|
|
58
|
-
target = Zold::Wallet.new(File.join(dir, id.to_s + Zold::Wallet::EXT))
|
|
59
|
-
wallets.acq(id, exclusive: true) do |w|
|
|
60
|
-
w.init(id, Zold::Key.new(file: File.expand_path(File.join(__dir__, '../fixtures/id_rsa.pub'))))
|
|
61
|
-
File.write(target.path, File.read(w.path))
|
|
62
|
-
txns.times do |i|
|
|
63
|
-
w.add(
|
|
64
|
-
Zold::Txn.new(
|
|
65
|
-
1, Time.now,
|
|
66
|
-
Zold::Amount.new(zld: (i + 1).to_f),
|
|
67
|
-
'NOPREFIX', Zold::Id.new, '-'
|
|
68
|
-
)
|
|
69
|
-
)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
target
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def create_wallet_json(id = Zold::Id.new)
|
|
76
|
-
require 'zold/score'
|
|
77
|
-
score = Zold::Score::ZERO
|
|
78
|
-
Dir.mktmpdir 'wallets' do |external_dir|
|
|
79
|
-
wallet = create_wallet(id, external_dir)
|
|
80
|
-
{
|
|
81
|
-
version: Zold::VERSION,
|
|
82
|
-
protocol: Zold::PROTOCOL,
|
|
83
|
-
id: wallet.id.to_s,
|
|
84
|
-
score: score.to_h,
|
|
85
|
-
size: wallet.size,
|
|
86
|
-
wallets: 1,
|
|
87
|
-
mtime: wallet.mtime.utc.iso8601,
|
|
88
|
-
digest: wallet.digest,
|
|
89
|
-
balance: wallet.balance.to_i,
|
|
90
|
-
body: File.read(wallet.path)
|
|
91
|
-
}.to_json
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def copies(wallet = create_wallet)
|
|
96
|
-
Zold::Copies.new(File.join(@dir, "copies/#{wallet.id}"))
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def remotes
|
|
100
|
-
remotes = Zold::Remotes.new(file: File.join(@dir, 'secrets/remotes'))
|
|
101
|
-
remotes.clean
|
|
102
|
-
remotes
|
|
103
|
-
end
|
|
104
|
-
end
|
data/test/node/fake_entrance.rb
DELETED
|
@@ -1,43 +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
|
-
# Fake entrance.
|
|
24
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
25
|
-
# Copyright:: Copyright (c) 2018-2024 Zerocracy
|
|
26
|
-
# License:: MIT
|
|
27
|
-
class FakeEntrance
|
|
28
|
-
def initialize
|
|
29
|
-
# Nothing here
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def to_json
|
|
33
|
-
{}
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def start
|
|
37
|
-
yield self
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def push(id, _)
|
|
41
|
-
[id]
|
|
42
|
-
end
|
|
43
|
-
end
|