zold 0.32.0 → 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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/zold/version.rb +1 -1
  4. data/zold.gemspec +1 -1
  5. metadata +2 -168
  6. data/.0pdd.yml +0 -12
  7. data/.gitattributes +0 -9
  8. data/.github/typos.toml +0 -11
  9. data/.github/workflows/actionlint.yml +0 -25
  10. data/.github/workflows/bashate.yml +0 -25
  11. data/.github/workflows/codecov.yml +0 -27
  12. data/.github/workflows/copyrights.yml +0 -15
  13. data/.github/workflows/hadolint.yml +0 -14
  14. data/.github/workflows/markdown-lint.yml +0 -19
  15. data/.github/workflows/pdd.yml +0 -19
  16. data/.github/workflows/rake.yml +0 -31
  17. data/.github/workflows/reuse.yml +0 -19
  18. data/.github/workflows/shellcheck.yml +0 -19
  19. data/.github/workflows/typos.yml +0 -21
  20. data/.github/workflows/xcop.yml +0 -15
  21. data/.github/workflows/yamllint.yml +0 -19
  22. data/.gitignore +0 -15
  23. data/.pdd +0 -7
  24. data/.rubocop.yml +0 -66
  25. data/.ruby-version +0 -1
  26. data/.rultor.yml +0 -41
  27. data/cucumber.yml +0 -6
  28. data/features/cli.feature +0 -18
  29. data/features/gem_package.feature +0 -28
  30. data/features/step_definitions/steps.rb +0 -67
  31. data/features/support/env.rb +0 -9
  32. data/fixtures/448b451bc62e8e16.z +0 -1005
  33. data/fixtures/id_rsa +0 -51
  34. data/fixtures/id_rsa-2 +0 -51
  35. data/fixtures/id_rsa-2.pub +0 -1
  36. data/fixtures/id_rsa.pub +0 -1
  37. data/fixtures/keys/1.pub +0 -1
  38. data/fixtures/keys/2 +0 -51
  39. data/fixtures/keys/2.pub +0 -1
  40. data/fixtures/merge/asserts.rb +0 -20
  41. data/fixtures/merge/id_rsa +0 -51
  42. data/fixtures/merge/id_rsa.pub +0 -1
  43. data/fixtures/merge/into_no_wallet/assert.rb +0 -8
  44. data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/1.zc +0 -6
  45. data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/scores.zc +0 -1
  46. data/fixtures/merge/into_no_wallet/opts +0 -1
  47. data/fixtures/merge/legacy_negatives_stay/0123456789abcdef.z +0 -6
  48. data/fixtures/merge/legacy_negatives_stay/assert.rb +0 -8
  49. data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/1.zc +0 -6
  50. data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/scores.zc +0 -1
  51. data/fixtures/merge/legacy_negatives_stay/opts +0 -2
  52. data/fixtures/merge/missed_wallets/0000000000000000.z +0 -6
  53. data/fixtures/merge/missed_wallets/0123456789abcdef.z +0 -4
  54. data/fixtures/merge/missed_wallets/assert.rb +0 -8
  55. data/fixtures/merge/missed_wallets/copies/0123456789abcdef/1.zc +0 -8
  56. data/fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc +0 -1
  57. data/fixtures/merge/missed_wallets/opts +0 -3
  58. data/fixtures/merge/negative_overwriting/0123456789abcdef.z +0 -6
  59. data/fixtures/merge/negative_overwriting/146b852f2d9ad984.z +0 -6
  60. data/fixtures/merge/negative_overwriting/assert.rb +0 -8
  61. data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/1.zc +0 -6
  62. data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/scores.zc +0 -1
  63. data/fixtures/merge/negative_overwriting/opts +0 -2
  64. data/fixtures/merge/negatives_in_between/0000000000000000.z +0 -6
  65. data/fixtures/merge/negatives_in_between/0123456789abcdef.z +0 -4
  66. data/fixtures/merge/negatives_in_between/assert.rb +0 -8
  67. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/1.zc +0 -6
  68. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc +0 -6
  69. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/3.zc +0 -6
  70. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/scores.zc +0 -3
  71. data/fixtures/merge/negatives_in_between/opts +0 -1
  72. data/fixtures/merge/random_expenses/0000000000000000.z +0 -6
  73. data/fixtures/merge/random_expenses/0123456789abcdef.z +0 -6
  74. data/fixtures/merge/random_expenses/assert.rb +0 -8
  75. data/fixtures/merge/random_expenses/copies/0123456789abcdef/1.zc +0 -7
  76. data/fixtures/merge/random_expenses/copies/0123456789abcdef/2.zc +0 -7
  77. data/fixtures/merge/random_expenses/copies/0123456789abcdef/3.zc +0 -7
  78. data/fixtures/merge/random_expenses/copies/0123456789abcdef/4.zc +0 -7
  79. data/fixtures/merge/random_expenses/copies/0123456789abcdef/5.zc +0 -7
  80. data/fixtures/merge/random_expenses/copies/0123456789abcdef/scores.zc +0 -5
  81. data/fixtures/merge/random_expenses/opts +0 -1
  82. data/fixtures/merge/simple_case/0000000000000000.z +0 -6
  83. data/fixtures/merge/simple_case/0123456789abcdef.z +0 -4
  84. data/fixtures/merge/simple_case/assert.rb +0 -8
  85. data/fixtures/merge/simple_case/copies/0123456789abcdef/1.zc +0 -6
  86. data/fixtures/merge/simple_case/copies/0123456789abcdef/scores.zc +0 -1
  87. data/fixtures/merge/simple_case/opts +0 -1
  88. data/fixtures/merge/unconfirmed_income/0123456789abcdef.z +0 -4
  89. data/fixtures/merge/unconfirmed_income/assert.rb +0 -8
  90. data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/1.zc +0 -6
  91. data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/scores.zc +0 -1
  92. data/fixtures/merge/unconfirmed_income/opts +0 -3
  93. data/fixtures/scripts/_head.sh +0 -72
  94. data/fixtures/scripts/calculate-scores.sh +0 -5
  95. data/fixtures/scripts/distribute-wallet.sh +0 -88
  96. data/fixtures/scripts/print-helps.sh +0 -9
  97. data/fixtures/scripts/pull-on-start.sh +0 -35
  98. data/fixtures/scripts/push-and-pull.sh +0 -46
  99. data/fixtures/scripts/redeploy-on-upgrade.sh +0 -40
  100. data/fixtures/scripts/spread-wallets.sh +0 -56
  101. data/renovate.json +0 -6
  102. data/test/commands/routines/test_audit.rb +0 -23
  103. data/test/commands/routines/test_gc.rb +0 -52
  104. data/test/commands/routines/test_reconcile.rb +0 -33
  105. data/test/commands/routines/test_reconnect.rb +0 -28
  106. data/test/commands/routines/test_retire.rb +0 -22
  107. data/test/commands/test_alias.rb +0 -58
  108. data/test/commands/test_calculate.rb +0 -22
  109. data/test/commands/test_clean.rb +0 -55
  110. data/test/commands/test_create.rb +0 -32
  111. data/test/commands/test_diff.rb +0 -43
  112. data/test/commands/test_fetch.rb +0 -144
  113. data/test/commands/test_invoice.rb +0 -32
  114. data/test/commands/test_list.rb +0 -29
  115. data/test/commands/test_merge.rb +0 -106
  116. data/test/commands/test_node.rb +0 -50
  117. data/test/commands/test_pay.rb +0 -203
  118. data/test/commands/test_propagate.rb +0 -33
  119. data/test/commands/test_pull.rb +0 -52
  120. data/test/commands/test_push.rb +0 -75
  121. data/test/commands/test_remote.rb +0 -247
  122. data/test/commands/test_remove.rb +0 -48
  123. data/test/commands/test_show.rb +0 -30
  124. data/test/commands/test_taxes.rb +0 -58
  125. data/test/fake_home.rb +0 -87
  126. data/test/node/fake_entrance.rb +0 -26
  127. data/test/node/fake_node.rb +0 -88
  128. data/test/node/test_async_entrance.rb +0 -85
  129. data/test/node/test_entrance.rb +0 -64
  130. data/test/node/test_farm.rb +0 -159
  131. data/test/node/test_farmers.rb +0 -58
  132. data/test/node/test_front.rb +0 -379
  133. data/test/node/test_nodup_entrance.rb +0 -31
  134. data/test/node/test_nospam_entrance.rb +0 -31
  135. data/test/node/test_safe_entrance.rb +0 -41
  136. data/test/node/test_spread_entrance.rb +0 -49
  137. data/test/node/test_sync_entrance.rb +0 -23
  138. data/test/node/test_trace.rb +0 -18
  139. data/test/test__helper.rb +0 -113
  140. data/test/test_age.rb +0 -37
  141. data/test/test_amount.rb +0 -62
  142. data/test/test_cached_wallets.rb +0 -55
  143. data/test/test_copies.rb +0 -127
  144. data/test/test_dir_items.rb +0 -72
  145. data/test/test_gem.rb +0 -23
  146. data/test/test_hands.rb +0 -51
  147. data/test/test_hexnum.rb +0 -18
  148. data/test/test_http.rb +0 -207
  149. data/test/test_hungry_wallets.rb +0 -72
  150. data/test/test_id.rb +0 -61
  151. data/test/test_json_page.rb +0 -29
  152. data/test/test_key.rb +0 -81
  153. data/test/test_metronome.rb +0 -71
  154. data/test/test_patch.rb +0 -160
  155. data/test/test_prefixes.rb +0 -31
  156. data/test/test_remotes.rb +0 -301
  157. data/test/test_signature.rb +0 -31
  158. data/test/test_size.rb +0 -21
  159. data/test/test_sync_wallets.rb +0 -39
  160. data/test/test_tax.rb +0 -153
  161. data/test/test_thread_pool.rb +0 -71
  162. data/test/test_tree_wallets.rb +0 -65
  163. data/test/test_txn.rb +0 -71
  164. data/test/test_upgrades.rb +0 -81
  165. data/test/test_verbose_thread.rb +0 -37
  166. data/test/test_version.rb +0 -17
  167. data/test/test_wallet.rb +0 -300
  168. data/test/test_wallets.rb +0 -67
  169. data/test/test_zold.rb +0 -81
  170. data/test/upgrades/test_delete_banned_wallets.rb +0 -29
  171. data/test/upgrades/test_protocol_up.rb +0 -24
@@ -1,203 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'webmock/minitest'
7
- require 'threads'
8
- require 'shellwords'
9
- require_relative '../test__helper'
10
- require_relative '../fake_home'
11
- require_relative '../../lib/zold/wallets'
12
- require_relative '../../lib/zold/json_page'
13
- require_relative '../../lib/zold/amount'
14
- require_relative '../../lib/zold/key'
15
- require_relative '../../lib/zold/id'
16
- require_relative '../../lib/zold/commands/pay'
17
-
18
- # PAY test.
19
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
20
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
21
- # License:: MIT
22
- class TestPay < Zold::Test
23
- def test_sends_from_wallet_to_wallet
24
- FakeHome.new(log: fake_log).run do |home|
25
- source = home.create_wallet
26
- target = home.create_wallet
27
- amount = Zold::Amount.new(zld: 14.95)
28
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
29
- [
30
- 'pay', '--force', '--private-key=fixtures/id_rsa',
31
- source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
32
- ]
33
- )
34
- assert_equal(amount * -1, source.balance)
35
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
36
- [
37
- 'pay', '--private-key=fixtures/id_rsa',
38
- target.id.to_s, source.id.to_s, amount.to_zld, 'Refund'
39
- ]
40
- )
41
- source.flush
42
- assert_equal(Zold::Amount::ZERO, source.balance)
43
- end
44
- end
45
-
46
- def test_pay_without_invoice
47
- FakeHome.new(log: fake_log).run do |home|
48
- remotes = home.remotes
49
- remotes.add('localhost', 4096)
50
- json = home.create_wallet_json
51
- hash = Zold::JsonPage.new(json).to_hash
52
- id = hash['id']
53
- stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 200, body: json)
54
- stub_request(:get, "http://localhost:4096/wallet/#{id}.bin").to_return(status: 200, body: hash['body'])
55
- home.wallets.acq(Zold::Id.new(id)) { |w| File.delete(w.path) }
56
- source = home.create_wallet
57
- amount = Zold::Amount.new(zld: 14.95)
58
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: remotes, log: fake_log).run(
59
- [
60
- 'pay', '--force', '--private-key=fixtures/id_rsa', '--tolerate-edges', '--tolerate-quorum=1',
61
- source.id.to_s, id, amount.to_zld, 'For the car'
62
- ]
63
- )
64
- assert_equal(amount * -1, source.balance)
65
- end
66
- end
67
-
68
- def test_pay_with_keygap
69
- FakeHome.new(log: fake_log).run do |home|
70
- wallet = home.create_wallet
71
- amount = Zold::Amount.new(zld: 2.0)
72
- Tempfile.open do |f|
73
- pem = File.read('fixtures/id_rsa')
74
- keygap = pem[100..120]
75
- File.write(f, pem.gsub(keygap, '*' * keygap.length))
76
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
77
- [
78
- 'pay', '--force', "--private-key=#{Shellwords.escape(f.path)}",
79
- "--keygap=#{Shellwords.escape(keygap)}",
80
- wallet.id.to_s, 'NOPREFIX@dddd0000dddd0000', amount.to_zld, '-'
81
- ]
82
- )
83
- end
84
- assert_equal(amount * -1, wallet.balance)
85
- end
86
- end
87
-
88
- def test_pay_in_many_threads
89
- FakeHome.new(log: fake_log).run do |home|
90
- wallet = home.create_wallet
91
- amount = Zold::Amount.new(zld: 2.0)
92
- wallets = home.wallets
93
- Threads.new(10).assert do
94
- Zold::Pay.new(wallets: wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
95
- [
96
- 'pay', '--force', '--private-key=fixtures/id_rsa',
97
- wallet.id.to_s, 'NOPREFIX@dddd0000dddd0000', amount.to_zld, '-'
98
- ]
99
- )
100
- end
101
- assert_equal(amount * -10, wallet.balance)
102
- end
103
- end
104
-
105
- def test_sends_from_root_wallet
106
- FakeHome.new(log: fake_log).run do |home|
107
- source = home.create_wallet(Zold::Id::ROOT)
108
- target = home.create_wallet
109
- amount = Zold::Amount.new(zld: 14.95)
110
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
111
- [
112
- 'pay', '--private-key=fixtures/id_rsa',
113
- source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
114
- ]
115
- )
116
- assert_equal(amount * -1, source.balance)
117
- end
118
- end
119
-
120
- def test_sends_from_normal_wallet
121
- FakeHome.new(log: fake_log).run do |home|
122
- source = home.create_wallet
123
- target = home.create_wallet
124
- amount = Zold::Amount.new(zld: 14.95)
125
- source.add(
126
- Zold::Txn.new(
127
- 1, Time.now, amount,
128
- 'NOPREFIX', Zold::Id.new, '-'
129
- )
130
- )
131
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
132
- [
133
- 'pay', '--private-key=fixtures/id_rsa',
134
- source.id.to_s, target.id.to_s, amount.to_zld, 'here is the refund'
135
- ]
136
- )
137
- assert_equal(Zold::Amount::ZERO, source.balance)
138
- end
139
- end
140
-
141
- def test_notifies_about_tax_status
142
- FakeHome.new(log: fake_log).run do |home|
143
- source = home.create_wallet
144
- target = home.create_wallet
145
- amount = Zold::Amount.new(zld: 14.95)
146
- accumulating_log = fake_log.dup
147
- class << accumulating_log
148
- attr_accessor :info_messages
149
-
150
- def info(message)
151
- (@info_messages ||= []) << message
152
- end
153
- end
154
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: accumulating_log).run(
155
- [
156
- 'pay', '--force', '--private-key=fixtures/id_rsa',
157
- '--ignore-score-weakness', '--pay-taxes-anyway',
158
- source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
159
- ]
160
- )
161
- assert_equal 1, accumulating_log.info_messages.grep(/^The tax debt/).size,
162
- 'No info_messages notified user of tax debt'
163
- end
164
- end
165
-
166
- def test_pays_and_taxes
167
- FakeHome.new(log: fake_log).run do |home|
168
- wallet = home.create_wallet
169
- fund = Zold::Amount.new(zld: 19.99)
170
- 10.times do |i|
171
- wallet.add(
172
- Zold::Txn.new(
173
- i + 1,
174
- Time.now - (24 * 60 * 60 * 365 * 300),
175
- fund,
176
- 'NOPREFIX', Zold::Id.new, '-'
177
- )
178
- )
179
- end
180
- score = Zold::Score.new(host: 'localhost', port: 80, strength: 1, invoice: 'NOPREFIX@0000000000000000')
181
- 10.times { score = score.next }
182
- remotes = home.remotes
183
- remotes.add(score.host, score.port)
184
- stub_request(:get, "http://#{score.host}:#{score.port}/").to_return(
185
- status: 200,
186
- body: {
187
- score: score.to_h
188
- }.to_json
189
- )
190
- before = wallet.balance
191
- target = home.create_wallet
192
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: remotes, log: fake_log).run(
193
- [
194
- 'pay', '--force', '--private-key=fixtures/id_rsa',
195
- '--ignore-score-weakness',
196
- wallet.id.to_s, target.id.to_s, fund.to_zld, 'For the car'
197
- ]
198
- )
199
- wallet.flush
200
- refute_equal(before.to_zld(6), wallet.balance.to_zld(6))
201
- end
202
- end
203
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require_relative '../test__helper'
7
- require_relative '../fake_home'
8
- require_relative '../../lib/zold/amount'
9
- require_relative '../../lib/zold/commands/propagate'
10
- require_relative '../../lib/zold/commands/pay'
11
-
12
- # PROPAGATE test.
13
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
14
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
15
- # License:: MIT
16
- class TestPropagate < Zold::Test
17
- def test_propagates_wallet
18
- FakeHome.new(log: fake_log).run do |home|
19
- wallet = home.create_wallet
20
- friend = home.create_wallet
21
- amount = Zold::Amount.new(zld: 14.95)
22
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
23
- ['pay', wallet.id.to_s, friend.id.to_s, amount.to_zld, '--force', '--private-key=fixtures/id_rsa']
24
- )
25
- Zold::Propagate.new(wallets: home.wallets, log: fake_log).run(
26
- ['merge', wallet.id.to_s]
27
- )
28
- assert_equal(amount, friend.balance)
29
- assert_equal(1, friend.txns.count)
30
- assert_equal('', friend.txns[0].sign)
31
- end
32
- end
33
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'webmock/minitest'
7
- require_relative '../fake_home'
8
- require_relative '../test__helper'
9
- require_relative '../../lib/zold/id'
10
- require_relative '../../lib/zold/json_page'
11
- require_relative '../../lib/zold/commands/pull'
12
-
13
- # PUSH test.
14
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
15
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
16
- # License:: MIT
17
- class TestPull < Zold::Test
18
- def test_pull_wallet
19
- FakeHome.new(log: fake_log).run do |home|
20
- remotes = home.remotes
21
- remotes.add('localhost', 4096)
22
- json = home.create_wallet_json
23
- hash = Zold::JsonPage.new(json).to_hash
24
- id = hash['id']
25
- stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 200, body: json)
26
- stub_request(:get, "http://localhost:4096/wallet/#{id}.bin").to_return(status: 200, body: hash['body'])
27
- Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: fake_log).run(
28
- ['--ignore-this-stupid-option', 'pull', id.to_s, '--tolerate-edges', '--tolerate-quorum=1']
29
- )
30
- home.wallets.acq(Zold::Id.new(id)) do |wallet|
31
- assert_predicate(wallet, :exists?)
32
- end
33
- end
34
- end
35
-
36
- def test_fails_when_only_edge_nodes
37
- FakeHome.new(log: fake_log).run do |home|
38
- remotes = home.remotes
39
- remotes.add('localhost', 4096)
40
- json = home.create_wallet_json
41
- hash = Zold::JsonPage.new(json).to_hash
42
- id = hash['id']
43
- stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 200, body: json)
44
- stub_request(:get, "http://localhost:4096/wallet/#{id}.bin").to_return(status: 200, body: hash['body'])
45
- assert_raises Zold::Fetch::EdgesOnly do
46
- Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: fake_log).run(
47
- ['--ignore-this-stupid-option', 'pull', id.to_s]
48
- )
49
- end
50
- end
51
- end
52
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'webmock/minitest'
7
- require_relative '../fake_home'
8
- require_relative '../test__helper'
9
- require_relative '../../lib/zold/wallet'
10
- require_relative '../../lib/zold/wallets'
11
- require_relative '../../lib/zold/remotes'
12
- require_relative '../../lib/zold/id'
13
- require_relative '../../lib/zold/key'
14
- require_relative '../../lib/zold/commands/push'
15
-
16
- # PUSH test.
17
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
18
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
19
- # License:: MIT
20
- class TestPush < Zold::Test
21
- def test_pushes_wallet
22
- FakeHome.new(log: fake_log).run do |home|
23
- wallet = home.create_wallet
24
- remotes = home.remotes
25
- remotes.add('localhost', 80)
26
- stub_request(:put, "http://localhost:80/wallet/#{wallet.id}").to_return(status: 304)
27
- Zold::Push.new(wallets: home.wallets, remotes: remotes, log: fake_log).run(
28
- ['--ignore-this-stupid-option', 'push', wallet.id.to_s, '--tolerate-edges', '--tolerate-quorum=1']
29
- )
30
- end
31
- end
32
-
33
- def test_pushes_multiple_wallets
34
- log = TestLogger.new(fake_log)
35
- FakeHome.new(log: log).run do |home|
36
- wallet_a = home.create_wallet
37
- wallet_b = home.create_wallet
38
- remotes = home.remotes
39
- remotes.add('localhost', 80)
40
- stub_request(:put, "http://localhost:80/wallet/#{wallet_a.id}").to_return(status: 304)
41
- stub_request(:put, "http://localhost:80/wallet/#{wallet_b.id}").to_return(status: 304)
42
- Zold::Push.new(wallets: home.wallets, remotes: remotes, log: log).run(
43
- ['--tolerate-edges', '--tolerate-quorum=1', '--threads=2', 'push', wallet_a.id.to_s, wallet_b.id.to_s]
44
- )
45
- end
46
- end
47
-
48
- def test_fails_when_only_edge_nodes
49
- FakeHome.new(log: fake_log).run do |home|
50
- wallet = home.create_wallet
51
- remotes = home.remotes
52
- remotes.add('localhost', 80)
53
- stub_request(:put, "http://localhost:80/wallet/#{wallet.id}").to_return(status: 304)
54
- assert_raises Zold::Push::EdgesOnly do
55
- Zold::Push.new(wallets: home.wallets, remotes: remotes, log: fake_log).run(
56
- ['push', wallet.id.to_s]
57
- )
58
- end
59
- end
60
- end
61
-
62
- def test_fails_when_only_one_node
63
- FakeHome.new(log: fake_log).run do |home|
64
- wallet = home.create_wallet
65
- remotes = home.remotes
66
- remotes.add('localhost', 80)
67
- stub_request(:put, "http://localhost:80/wallet/#{wallet.id}").to_return(status: 304)
68
- assert_raises Zold::Push::NoQuorum do
69
- Zold::Push.new(wallets: home.wallets, remotes: remotes, log: fake_log).run(
70
- ['push', wallet.id.to_s, '--tolerate-edges']
71
- )
72
- end
73
- end
74
- end
75
- end
@@ -1,247 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'tmpdir'
7
- require 'webmock/minitest'
8
- require 'zold/score'
9
- require_relative '../test__helper'
10
- require_relative '../../lib/zold/version'
11
- require_relative '../../lib/zold/wallets'
12
- require_relative '../../lib/zold/remotes'
13
- require_relative '../../lib/zold/key'
14
- require 'loog'
15
- require_relative '../../lib/zold/commands/remote'
16
-
17
- # REMOTE test.
18
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
19
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
20
- # License:: MIT
21
- class TestRemote < Zold::Test
22
- def test_updates_remote
23
- Dir.mktmpdir do |dir|
24
- remotes = Zold::Remotes.new(file: File.join(dir, 'a/b/c/remotes'))
25
- zero = Zold::Score::ZERO
26
- stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
27
- status: 200,
28
- headers: {},
29
- body: {
30
- version: Zold::VERSION,
31
- score: zero.to_h,
32
- all: [
33
- { host: 'localhost', port: 888 },
34
- { host: 'localhost', port: 999 }
35
- ]
36
- }.to_json
37
- )
38
- stub_request(:get, 'http://localhost:2/remotes').to_return(
39
- status: 404
40
- )
41
- stub_request(:get, 'http://localhost:888/remotes').to_return(
42
- status: 404
43
- )
44
- stub_request(:get, 'http://localhost:999/remotes').to_return(
45
- status: 404
46
- )
47
- stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
48
- status: 200,
49
- headers: {},
50
- body: '{"version": "0.0.0"}'
51
- )
52
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
53
- cmd.run(%w[remote clean])
54
- assert_empty(remotes.all)
55
- cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
56
- cmd.run(%w[remote add localhost 2 --skip-ping])
57
- assert_equal(2, remotes.all.count)
58
- cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping'])
59
- assert_equal(4, remotes.all.count, remotes.all)
60
- end
61
- end
62
-
63
- def test_new_version_rubygems
64
- Dir.mktmpdir do |dir|
65
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
66
- zero = Zold::Score::ZERO
67
- stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
68
- status: 200,
69
- body: {
70
- version: Zold::VERSION,
71
- score: zero.to_h,
72
- repo: Zold::REPO,
73
- all: [
74
- { host: zero.host, port: zero.port }
75
- ]
76
- }.to_json
77
- )
78
- stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
79
- status: 200,
80
- body: "{\"version\": \"9.9.9\", \"repo\": \"#{Zold::REPO}\"}"
81
- )
82
- log = TestLogger.new
83
- cmd = Zold::Remote.new(remotes: remotes, log: log)
84
- cmd.run(%w[remote clean])
85
- cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
86
- cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping', '--reboot'])
87
- assert_includes(log.msgs.to_s, ', reboot!')
88
- log.msgs = []
89
- stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
90
- status: 200,
91
- body: "{\"version\": \"#{Zold::VERSION}\"}"
92
- )
93
- cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping', '--reboot'])
94
- refute_includes(log.msgs.to_s, ', reboot!')
95
- end
96
- end
97
-
98
- def test_elects_a_remote
99
- Dir.mktmpdir do |dir|
100
- zero = Zold::Score::ZERO
101
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
102
- remotes.clean
103
- remotes.add(zero.host, zero.port)
104
- stub_request(:get, "http://#{zero.host}:#{zero.port}/").to_return(
105
- status: 200,
106
- body: {
107
- version: Zold::VERSION,
108
- score: zero.to_h
109
- }.to_json
110
- )
111
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
112
- winners = cmd.run(%w[remote elect --ignore-score-value])
113
- assert_equal(1, winners.count)
114
- end
115
- end
116
-
117
- def test_resets_remotes
118
- Dir.mktmpdir do |dir|
119
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
120
- Zold::Remote.new(remotes: remotes, log: fake_log).run(%w[remote reset])
121
- end
122
- end
123
-
124
- def test_remote_trim_with_tolerate
125
- Dir.mktmpdir do |dir|
126
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
127
- score = Zold::Score.new(
128
- host: 'aa1.example.org', port: 9999, invoice: 'NOPREFIX4@ffffffffffffffff'
129
- )
130
- stub_request(:get, 'http://localhost:8883/version').to_return(
131
- status: 200,
132
- body: '0.0.0'
133
- )
134
- stub_request(:get, "http://#{score.host}:#{score.port}/remotes").to_return(
135
- status: 200,
136
- body: {
137
- version: Zold::VERSION,
138
- score: score.to_h,
139
- all: [
140
- { host: 'localhost', port: 8883 }
141
- ]
142
- }.to_json
143
- )
144
- stub_request(:get, 'https://rubygems.org/api/v1/versions/zold/latest.json').to_return(
145
- status: 200,
146
- body: '{"version": "0.0.0"}'
147
- )
148
- stub_request(:get, 'http://localhost:8883/remotes').to_return(status: 404)
149
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
150
- cmd.run(%w[remote clean])
151
- assert_empty(remotes.all)
152
- cmd.run(['remote', 'add', score.host, score.port.to_s, '--skip-ping'])
153
- cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping'])
154
- assert_equal(2, remotes.all.count)
155
- cmd.run(['remote', 'update', '--ignore-score-weakness'])
156
- cmd.run(['remote', 'trim', '--tolerate=0'])
157
- assert_equal(1, remotes.all.count, remotes.all)
158
- end
159
- end
160
-
161
- def test_select_selects_the_strongest_nodes
162
- Dir.mktmpdir do |dir|
163
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
164
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
165
- (1..11).each do |i|
166
- cmd.run(%W[remote add localhost #{i} --skip-ping])
167
- remotes.rescore('localhost', i, i)
168
- i.times { remotes.error('localhost', i) }
169
- end
170
- cmd.run(%w[remote select --max-nodes=5])
171
- assert_equal(5, remotes.all.count)
172
- scores = remotes.all.map { |r| r[:score] }
173
- assert_equal([7, 8, 9, 10, 11], scores.sort)
174
- end
175
- end
176
-
177
- def test_select_respects_max_nodes_option
178
- Dir.mktmpdir do |dir|
179
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
180
- remotes.masters
181
- zero = Zold::Score::ZERO
182
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
183
- (5000..5010).each do |port|
184
- stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
185
- status: 200,
186
- body: {
187
- version: Zold::VERSION,
188
- score: zero.to_h,
189
- all: [
190
- { host: 'localhost', port: port }
191
- ]
192
- }.to_json
193
- )
194
- stub_request(:get, "http://localhost:#{port}/version").to_return(
195
- status: 200,
196
- body: {
197
- version: Zold::VERSION
198
- }.to_json
199
- )
200
- cmd.run(%W[remote add localhost #{port}])
201
- end
202
- assert_equal(11 + File.readlines('resources/masters').count, remotes.all.count)
203
- cmd.run(%w[remote select --max-nodes=5 --masters-too])
204
- assert_equal(5, remotes.all.count)
205
- end
206
- end
207
-
208
- def test_sets_masters
209
- Dir.mktmpdir do |dir|
210
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
211
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
212
- cmd.run(%w[remote masters])
213
- refute_empty(remotes.all)
214
- end
215
- end
216
-
217
- def test_select_doesnt_touch_masters
218
- Dir.mktmpdir do |dir|
219
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
220
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
221
- cmd.run(%w[remote masters])
222
- cmd.run(%w[remote select --max-nodes=0])
223
- refute_empty(remotes.all)
224
- end
225
- end
226
-
227
- def test_updates_just_once
228
- Dir.mktmpdir do |dir|
229
- remotes = Zold::Remotes.new(file: File.join(dir, 'a/b/c/remotes'))
230
- zero = Zold::Score::ZERO
231
- get = stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
232
- status: 200,
233
- headers: {},
234
- body: {
235
- version: Zold::VERSION,
236
- score: zero.to_h,
237
- all: []
238
- }.to_json
239
- )
240
- cmd = Zold::Remote.new(remotes: remotes, log: fake_log)
241
- cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
242
- cmd.run(['remote', 'update', '--ignore-score-weakness', '--depth=10'])
243
- assert_equal(1, remotes.all.count)
244
- assert_requested(get, times: 1)
245
- end
246
- end
247
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require_relative '../fake_home'
7
- require_relative '../test__helper'
8
- require_relative '../../lib/zold/commands/remove'
9
-
10
- # REMOVE test.
11
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
12
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
13
- # License:: MIT
14
- class TestRemove < Zold::Test
15
- def test_removes_one_wallet
16
- FakeHome.new(log: fake_log).run do |home|
17
- wallet = home.create_wallet
18
- assert_equal(1, home.wallets.all.count)
19
- Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove', wallet.id.to_s])
20
- assert_empty(home.wallets.all)
21
- end
22
- end
23
-
24
- def test_removes_wallets
25
- FakeHome.new(log: fake_log).run do |home|
26
- home.create_wallet
27
- home.create_wallet
28
- Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove'])
29
- assert_empty(home.wallets.all)
30
- end
31
- end
32
-
33
- def test_removes_no_wallets
34
- FakeHome.new(log: fake_log).run do |home|
35
- Zold::Remove.new(wallets: home.wallets, log: fake_log).run(['remove'])
36
- assert_empty(home.wallets.all)
37
- end
38
- end
39
-
40
- def test_removes_absent_wallets
41
- FakeHome.new(log: fake_log).run do |home|
42
- Zold::Remove.new(wallets: home.wallets, log: fake_log).run(
43
- ['remove', '7654321076543210', '--force']
44
- )
45
- assert_empty(home.wallets.all)
46
- end
47
- end
48
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'tmpdir'
7
- require_relative '../test__helper'
8
- require_relative '../../lib/zold/wallets'
9
- require_relative '../../lib/zold/wallet'
10
- require_relative '../../lib/zold/key'
11
- require_relative '../../lib/zold/id'
12
- require_relative '../../lib/zold/commands/show'
13
-
14
- # SHOW test.
15
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
16
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
17
- # License:: MIT
18
- class TestShow < Zold::Test
19
- def test_checks_wallet_balance
20
- Dir.mktmpdir do |dir|
21
- id = Zold::Id.new
22
- wallets = Zold::Wallets.new(dir)
23
- wallets.acq(id) do |wallet|
24
- wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
25
- balance = Zold::Show.new(wallets: wallets, copies: File.join(dir, 'c'), log: fake_log).run(['show', id.to_s])
26
- assert_equal(Zold::Amount::ZERO, balance)
27
- end
28
- end
29
- end
30
- end