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.
Files changed (262) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +11 -27
  3. data/Gemfile +21 -33
  4. data/Gemfile.lock +181 -126
  5. data/Guardfile +0 -0
  6. data/INSTALL.md +80 -59
  7. data/LICENSE.txt +1 -1
  8. data/LICENSES/MIT.txt +21 -0
  9. data/README.md +183 -154
  10. data/REUSE.toml +40 -0
  11. data/Rakefile +4 -38
  12. data/bin/zold +7 -37
  13. data/deploy.sh +4 -22
  14. data/lib/zold/age.rb +3 -20
  15. data/lib/zold/amount.rb +3 -20
  16. data/lib/zold/cached_wallets.rb +3 -20
  17. data/lib/zold/commands/alias.rb +4 -21
  18. data/lib/zold/commands/args.rb +4 -21
  19. data/lib/zold/commands/calculate.rb +5 -22
  20. data/lib/zold/commands/clean.rb +6 -23
  21. data/lib/zold/commands/create.rb +5 -22
  22. data/lib/zold/commands/diff.rb +5 -22
  23. data/lib/zold/commands/fetch.rb +6 -23
  24. data/lib/zold/commands/invoice.rb +5 -22
  25. data/lib/zold/commands/list.rb +5 -22
  26. data/lib/zold/commands/merge.rb +7 -24
  27. data/lib/zold/commands/next.rb +5 -22
  28. data/lib/zold/commands/node.rb +4 -21
  29. data/lib/zold/commands/pay.rb +6 -23
  30. data/lib/zold/commands/propagate.rb +5 -22
  31. data/lib/zold/commands/pull.rb +5 -22
  32. data/lib/zold/commands/push.rb +5 -22
  33. data/lib/zold/commands/remote.rb +7 -24
  34. data/lib/zold/commands/remove.rb +5 -22
  35. data/lib/zold/commands/routines/audit.rb +4 -21
  36. data/lib/zold/commands/routines/gc.rb +6 -23
  37. data/lib/zold/commands/routines/reconcile.rb +5 -22
  38. data/lib/zold/commands/routines/reconnect.rb +4 -21
  39. data/lib/zold/commands/routines/retire.rb +4 -21
  40. data/lib/zold/commands/routines/spread.rb +5 -22
  41. data/lib/zold/commands/routines.rb +3 -20
  42. data/lib/zold/commands/show.rb +5 -22
  43. data/lib/zold/commands/taxes.rb +5 -22
  44. data/lib/zold/commands/thread_badge.rb +3 -20
  45. data/lib/zold/copies.rb +6 -25
  46. data/lib/zold/dir_items.rb +3 -20
  47. data/lib/zold/endless.rb +5 -22
  48. data/lib/zold/gem.rb +3 -20
  49. data/lib/zold/hands.rb +6 -23
  50. data/lib/zold/head.rb +4 -21
  51. data/lib/zold/hexnum.rb +3 -20
  52. data/lib/zold/http.rb +3 -20
  53. data/lib/zold/hungry_wallets.rb +6 -23
  54. data/lib/zold/id.rb +3 -20
  55. data/lib/zold/json_page.rb +5 -22
  56. data/lib/zold/key.rb +3 -20
  57. data/lib/zold/metronome.rb +5 -22
  58. data/lib/zold/node/async_entrance.rb +6 -23
  59. data/lib/zold/node/entrance.rb +7 -24
  60. data/lib/zold/node/farm.rb +5 -22
  61. data/lib/zold/node/farmers.rb +15 -32
  62. data/lib/zold/node/front.rb +6 -23
  63. data/lib/zold/node/journaled_pipeline.rb +8 -25
  64. data/lib/zold/node/nodup_entrance.rb +6 -23
  65. data/lib/zold/node/nospam_entrance.rb +6 -23
  66. data/lib/zold/node/pipeline.rb +6 -23
  67. data/lib/zold/node/safe_entrance.rb +4 -22
  68. data/lib/zold/node/soft_error.rb +3 -20
  69. data/lib/zold/node/spread_entrance.rb +5 -22
  70. data/lib/zold/node/sync_entrance.rb +5 -22
  71. data/lib/zold/node/trace.rb +3 -20
  72. data/lib/zold/patch.rb +6 -23
  73. data/lib/zold/prefixes.rb +3 -20
  74. data/lib/zold/remotes.rb +5 -22
  75. data/lib/zold/signature.rb +3 -20
  76. data/lib/zold/size.rb +3 -20
  77. data/lib/zold/sync_wallets.rb +5 -22
  78. data/lib/zold/tax.rb +4 -21
  79. data/lib/zold/thread_pool.rb +4 -21
  80. data/lib/zold/tree_wallets.rb +3 -20
  81. data/lib/zold/txn.rb +4 -21
  82. data/lib/zold/txns.rb +4 -21
  83. data/lib/zold/upgrades.rb +4 -21
  84. data/lib/zold/verbose_thread.rb +5 -22
  85. data/lib/zold/version.rb +4 -21
  86. data/lib/zold/version_file.rb +4 -21
  87. data/lib/zold/wallet.rb +6 -23
  88. data/lib/zold/wallets.rb +5 -23
  89. data/lib/zold.rb +3 -21
  90. data/resources/banned-wallets.log +6 -6
  91. data/upgrades/2.rb +3 -20
  92. data/upgrades/delete_banned_wallets.rb +3 -20
  93. data/upgrades/move_wallets_into_tree.rb +3 -20
  94. data/upgrades/protocol_up.rb +3 -20
  95. data/upgrades/rename_foreign_wallets.rb +3 -20
  96. data/views/journal.haml +25 -0
  97. data/views/layout.haml +25 -0
  98. data/views/wallet.haml +25 -0
  99. data/zold.gemspec +6 -22
  100. metadata +26 -174
  101. data/.0pdd.yml +0 -29
  102. data/.gitattributes +0 -9
  103. data/.github/workflows/actionlint.yml +0 -41
  104. data/.github/workflows/codecov.yml +0 -40
  105. data/.github/workflows/copyrights.yml +0 -30
  106. data/.github/workflows/pdd.yml +0 -34
  107. data/.github/workflows/rake.yml +0 -45
  108. data/.github/workflows/xcop.yml +0 -30
  109. data/.github/workflows/yamllint.yml +0 -34
  110. data/.gitignore +0 -12
  111. data/.pdd +0 -7
  112. data/.rubocop.yml +0 -70
  113. data/.ruby-version +0 -1
  114. data/.rultor.yml +0 -57
  115. data/.simplecov +0 -36
  116. data/cucumber.yml +0 -23
  117. data/features/cli.feature +0 -16
  118. data/features/gem_package.feature +0 -26
  119. data/features/step_definitions/steps.rb +0 -84
  120. data/features/support/env.rb +0 -26
  121. data/fixtures/448b451bc62e8e16.z +0 -1005
  122. data/fixtures/id_rsa +0 -51
  123. data/fixtures/id_rsa-2 +0 -51
  124. data/fixtures/id_rsa-2.pub +0 -1
  125. data/fixtures/id_rsa.pub +0 -1
  126. data/fixtures/keys/1.pub +0 -1
  127. data/fixtures/keys/2 +0 -51
  128. data/fixtures/keys/2.pub +0 -1
  129. data/fixtures/merge/asserts.rb +0 -36
  130. data/fixtures/merge/id_rsa +0 -51
  131. data/fixtures/merge/id_rsa.pub +0 -1
  132. data/fixtures/merge/into_no_wallet/assert.rb +0 -25
  133. data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/1.zc +0 -6
  134. data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/scores.zc +0 -1
  135. data/fixtures/merge/into_no_wallet/opts +0 -1
  136. data/fixtures/merge/legacy_negatives_stay/0123456789abcdef.z +0 -6
  137. data/fixtures/merge/legacy_negatives_stay/assert.rb +0 -25
  138. data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/1.zc +0 -6
  139. data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/scores.zc +0 -1
  140. data/fixtures/merge/legacy_negatives_stay/opts +0 -2
  141. data/fixtures/merge/missed_wallets/0000000000000000.z +0 -6
  142. data/fixtures/merge/missed_wallets/0123456789abcdef.z +0 -6
  143. data/fixtures/merge/missed_wallets/assert.rb +0 -25
  144. data/fixtures/merge/missed_wallets/copies/0123456789abcdef/1.zc +0 -8
  145. data/fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc +0 -1
  146. data/fixtures/merge/missed_wallets/opts +0 -3
  147. data/fixtures/merge/negative_overwriting/0123456789abcdef.z +0 -6
  148. data/fixtures/merge/negative_overwriting/146b852f2d9ad984.z +0 -6
  149. data/fixtures/merge/negative_overwriting/assert.rb +0 -25
  150. data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/1.zc +0 -6
  151. data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/scores.zc +0 -1
  152. data/fixtures/merge/negative_overwriting/opts +0 -2
  153. data/fixtures/merge/negatives_in_between/0000000000000000.z +0 -6
  154. data/fixtures/merge/negatives_in_between/0123456789abcdef.z +0 -5
  155. data/fixtures/merge/negatives_in_between/assert.rb +0 -25
  156. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/1.zc +0 -6
  157. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc +0 -7
  158. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/3.zc +0 -6
  159. data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/scores.zc +0 -3
  160. data/fixtures/merge/negatives_in_between/opts +0 -1
  161. data/fixtures/merge/random_expenses/0000000000000000.z +0 -6
  162. data/fixtures/merge/random_expenses/0123456789abcdef.z +0 -6
  163. data/fixtures/merge/random_expenses/assert.rb +0 -25
  164. data/fixtures/merge/random_expenses/copies/0123456789abcdef/1.zc +0 -7
  165. data/fixtures/merge/random_expenses/copies/0123456789abcdef/2.zc +0 -7
  166. data/fixtures/merge/random_expenses/copies/0123456789abcdef/3.zc +0 -7
  167. data/fixtures/merge/random_expenses/copies/0123456789abcdef/4.zc +0 -7
  168. data/fixtures/merge/random_expenses/copies/0123456789abcdef/5.zc +0 -7
  169. data/fixtures/merge/random_expenses/copies/0123456789abcdef/scores.zc +0 -5
  170. data/fixtures/merge/random_expenses/opts +0 -1
  171. data/fixtures/merge/simple_case/0000000000000000.z +0 -6
  172. data/fixtures/merge/simple_case/0123456789abcdef.z +0 -4
  173. data/fixtures/merge/simple_case/assert.rb +0 -25
  174. data/fixtures/merge/simple_case/copies/0123456789abcdef/1.zc +0 -6
  175. data/fixtures/merge/simple_case/copies/0123456789abcdef/scores.zc +0 -1
  176. data/fixtures/merge/simple_case/opts +0 -1
  177. data/fixtures/merge/unconfirmed_income/0123456789abcdef.z +0 -4
  178. data/fixtures/merge/unconfirmed_income/assert.rb +0 -25
  179. data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/1.zc +0 -6
  180. data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/scores.zc +0 -1
  181. data/fixtures/merge/unconfirmed_income/opts +0 -3
  182. data/fixtures/scripts/_head.sh +0 -89
  183. data/fixtures/scripts/calculate-scores.sh +0 -22
  184. data/fixtures/scripts/distribute-wallet.sh +0 -105
  185. data/fixtures/scripts/print-helps.sh +0 -27
  186. data/fixtures/scripts/pull-on-start.sh +0 -52
  187. data/fixtures/scripts/push-and-pull.sh +0 -63
  188. data/fixtures/scripts/redeploy-on-upgrade.sh +0 -56
  189. data/fixtures/scripts/spread-wallets.sh +0 -72
  190. data/lib/zold/log.rb +0 -139
  191. data/renovate.json +0 -6
  192. data/test/commands/routines/test_audit.rb +0 -41
  193. data/test/commands/routines/test_gc.rb +0 -70
  194. data/test/commands/routines/test_reconcile.rb +0 -51
  195. data/test/commands/routines/test_reconnect.rb +0 -46
  196. data/test/commands/routines/test_retire.rb +0 -40
  197. data/test/commands/test_alias.rb +0 -76
  198. data/test/commands/test_calculate.rb +0 -40
  199. data/test/commands/test_clean.rb +0 -73
  200. data/test/commands/test_create.rb +0 -50
  201. data/test/commands/test_diff.rb +0 -61
  202. data/test/commands/test_fetch.rb +0 -162
  203. data/test/commands/test_invoice.rb +0 -50
  204. data/test/commands/test_list.rb +0 -47
  205. data/test/commands/test_merge.rb +0 -129
  206. data/test/commands/test_node.rb +0 -68
  207. data/test/commands/test_pay.rb +0 -221
  208. data/test/commands/test_propagate.rb +0 -51
  209. data/test/commands/test_pull.rb +0 -70
  210. data/test/commands/test_push.rb +0 -93
  211. data/test/commands/test_remote.rb +0 -265
  212. data/test/commands/test_remove.rb +0 -66
  213. data/test/commands/test_show.rb +0 -48
  214. data/test/commands/test_taxes.rb +0 -76
  215. data/test/fake_home.rb +0 -104
  216. data/test/node/fake_entrance.rb +0 -43
  217. data/test/node/fake_node.rb +0 -105
  218. data/test/node/test_async_entrance.rb +0 -103
  219. data/test/node/test_entrance.rb +0 -82
  220. data/test/node/test_farm.rb +0 -177
  221. data/test/node/test_farmers.rb +0 -76
  222. data/test/node/test_front.rb +0 -399
  223. data/test/node/test_nodup_entrance.rb +0 -49
  224. data/test/node/test_nospam_entrance.rb +0 -49
  225. data/test/node/test_safe_entrance.rb +0 -59
  226. data/test/node/test_spread_entrance.rb +0 -67
  227. data/test/node/test_sync_entrance.rb +0 -41
  228. data/test/node/test_trace.rb +0 -36
  229. data/test/test__helper.rb +0 -112
  230. data/test/test_age.rb +0 -55
  231. data/test/test_amount.rb +0 -81
  232. data/test/test_cached_wallets.rb +0 -73
  233. data/test/test_copies.rb +0 -145
  234. data/test/test_dir_items.rb +0 -90
  235. data/test/test_gem.rb +0 -41
  236. data/test/test_hands.rb +0 -69
  237. data/test/test_hexnum.rb +0 -36
  238. data/test/test_http.rb +0 -225
  239. data/test/test_hungry_wallets.rb +0 -90
  240. data/test/test_id.rb +0 -79
  241. data/test/test_json_page.rb +0 -47
  242. data/test/test_key.rb +0 -99
  243. data/test/test_log.rb +0 -49
  244. data/test/test_metronome.rb +0 -89
  245. data/test/test_patch.rb +0 -178
  246. data/test/test_prefixes.rb +0 -49
  247. data/test/test_remotes.rb +0 -319
  248. data/test/test_signature.rb +0 -49
  249. data/test/test_size.rb +0 -39
  250. data/test/test_sync_wallets.rb +0 -57
  251. data/test/test_tax.rb +0 -171
  252. data/test/test_thread_pool.rb +0 -89
  253. data/test/test_tree_wallets.rb +0 -83
  254. data/test/test_txn.rb +0 -89
  255. data/test/test_upgrades.rb +0 -99
  256. data/test/test_verbose_thread.rb +0 -55
  257. data/test/test_version.rb +0 -35
  258. data/test/test_wallet.rb +0 -318
  259. data/test/test_wallets.rb +0 -85
  260. data/test/test_zold.rb +0 -99
  261. data/test/upgrades/test_delete_banned_wallets.rb +0 -47
  262. data/test/upgrades/test_protocol_up.rb +0 -42
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2024 Zerocracy
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- require 'minitest/autorun'
24
- require_relative 'test__helper'
25
- require_relative '../lib/zold/metronome'
26
-
27
- # Metronome test.
28
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
- # Copyright:: Copyright (c) 2018-2024 Zerocracy
30
- # License:: MIT
31
- class TestMetronome < Zold::Test
32
- def test_start_and_stop
33
- metronome = Zold::Metronome.new(fake_log)
34
- list = []
35
- metronome.add(FakeRoutine.new(list))
36
- metronome.start do
37
- assert_wait { !list.empty? }
38
- end
39
- end
40
-
41
- def test_prints_to_text
42
- metronome = Zold::Metronome.new(fake_log)
43
- metronome.add(FakeRoutine.new([]))
44
- metronome.start do |m|
45
- assert(!m.to_text.nil?)
46
- end
47
- end
48
-
49
- def test_prints_empty_to_text
50
- metronome = Zold::Metronome.new(fake_log)
51
- metronome.start do |m|
52
- assert(!m.to_text.nil?)
53
- end
54
- end
55
-
56
- def test_continues_even_after_error
57
- metronome = Zold::Metronome.new(fake_log)
58
- routine = BrokenRoutine.new
59
- metronome.add(routine)
60
- metronome.start do
61
- assert_wait { routine.count >= 2 }
62
- assert(routine.count > 1)
63
- end
64
- end
65
-
66
- class FakeRoutine
67
- def initialize(list)
68
- @list = list
69
- end
70
-
71
- def exec(i)
72
- @list << i
73
- end
74
- end
75
-
76
- class BrokenRoutine
77
- attr_reader :count
78
-
79
- def initialize
80
- @count = 0
81
- end
82
-
83
- def exec(i)
84
- @count = i
85
- sleep 0.1
86
- raise
87
- end
88
- end
89
- end
data/test/test_patch.rb DELETED
@@ -1,178 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2024 Zerocracy
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- require 'minitest/autorun'
24
- require_relative 'fake_home'
25
- require_relative 'test__helper'
26
- require_relative '../lib/zold/key'
27
- require_relative '../lib/zold/id'
28
- require_relative '../lib/zold/wallet'
29
- require_relative '../lib/zold/prefixes'
30
- require_relative '../lib/zold/amount'
31
- require_relative '../lib/zold/patch'
32
-
33
- # Patch test.
34
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
35
- # Copyright:: Copyright (c) 2018-2024 Zerocracy
36
- # License:: MIT
37
- class TestPatch < Zold::Test
38
- def test_builds_patch
39
- FakeHome.new(log: fake_log).run do |home|
40
- first = home.create_wallet
41
- second = home.create_wallet
42
- third = home.create_wallet
43
- File.write(second.path, File.read(first.path))
44
- key = Zold::Key.new(file: 'fixtures/id_rsa')
45
- first.sub(Zold::Amount.new(zld: 39.0), "NOPREFIX@#{Zold::Id.new}", key)
46
- first.sub(Zold::Amount.new(zld: 11.0), "NOPREFIX@#{Zold::Id.new}", key)
47
- first.sub(Zold::Amount.new(zld: 3.0), "NOPREFIX@#{Zold::Id.new}", key)
48
- second.sub(Zold::Amount.new(zld: 44.0), "NOPREFIX@#{Zold::Id.new}", key)
49
- File.write(third.path, File.read(first.path))
50
- t = third.sub(Zold::Amount.new(zld: 10.0), "NOPREFIX@#{Zold::Id.new}", key)
51
- third.add(t.inverse(Zold::Id.new))
52
- patch = Zold::Patch.new(home.wallets, log: fake_log)
53
- patch.join(first) { false }
54
- patch.join(second) { false }
55
- patch.join(third) { false }
56
- assert_equal(true, patch.save(first.path, overwrite: true, allow_negative_balance: true))
57
- assert_equal(Zold::Amount.new(zld: -53.0), first.balance)
58
- end
59
- end
60
-
61
- def test_rejects_fake_positives
62
- FakeHome.new(log: fake_log).run do |home|
63
- first = home.create_wallet
64
- second = home.create_wallet
65
- File.write(second.path, File.read(first.path))
66
- second.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 11.0), 'NOPREFIX', Zold::Id.new, 'fake'))
67
- patch = Zold::Patch.new(home.wallets, log: fake_log)
68
- patch.join(first) { false }
69
- patch.join(second) { false }
70
- assert_equal(false, patch.save(first.path, overwrite: true))
71
- first.flush
72
- assert_equal(Zold::Amount::ZERO, first.balance)
73
- end
74
- end
75
-
76
- def test_accepts_negative_balance_in_root_wallet
77
- FakeHome.new(log: fake_log).run do |home|
78
- first = home.create_wallet(Zold::Id::ROOT)
79
- second = home.create_wallet
80
- File.write(second.path, File.read(first.path))
81
- amount = Zold::Amount.new(zld: 333.0)
82
- key = Zold::Key.new(file: 'fixtures/id_rsa')
83
- second.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
84
- patch = Zold::Patch.new(home.wallets, log: fake_log)
85
- patch.join(first) { false }
86
- patch.join(second) { false }
87
- assert_equal(true, patch.save(first.path, overwrite: true))
88
- first.flush
89
- assert_equal(amount * -1, first.balance)
90
- end
91
- end
92
-
93
- def test_merges_similar_ids_but_different_signs
94
- FakeHome.new(log: fake_log).run do |home|
95
- first = home.create_wallet(Zold::Id::ROOT)
96
- second = home.create_wallet
97
- File.write(second.path, File.read(first.path))
98
- key = Zold::Key.new(file: 'fixtures/id_rsa')
99
- second.sub(Zold::Amount.new(zld: 7.0), "NOPREFIX@#{Zold::Id.new}", key)
100
- first.add(
101
- Zold::Txn.new(
102
- 1, Time.now, Zold::Amount.new(zld: 9.0),
103
- Zold::Prefixes.new(first).create, Zold::Id.new, 'fake'
104
- )
105
- )
106
- patch = Zold::Patch.new(home.wallets, log: fake_log)
107
- patch.join(first) { false }
108
- patch.join(second) { false }
109
- assert_equal(true, patch.save(first.path, overwrite: true))
110
- first.flush
111
- assert_equal(Zold::Amount.new(zld: 2.0).to_s, first.balance.to_s)
112
- end
113
- end
114
-
115
- def test_merges_fragmented_parts
116
- FakeHome.new(log: fake_log).run do |home|
117
- first = home.create_wallet(Zold::Id::ROOT)
118
- second = home.create_wallet
119
- File.write(second.path, File.read(first.path))
120
- key = Zold::Key.new(file: 'fixtures/id_rsa')
121
- start = Time.parse('2017-07-19T21:24:51Z')
122
- first.add(
123
- Zold::Txn.new(
124
- 1, start, Zold::Amount.new(zld: -2.0),
125
- 'NOPREFIX', Zold::Id.new, 'first payment'
126
- ).signed(key, first.id)
127
- )
128
- second.add(
129
- Zold::Txn.new(
130
- 2, start + 1, Zold::Amount.new(zld: -2.0),
131
- 'NOPREFIX', Zold::Id.new, 'second payment'
132
- ).signed(key, first.id)
133
- )
134
- first.add(
135
- Zold::Txn.new(
136
- 3, start + 2, Zold::Amount.new(zld: -2.0),
137
- 'NOPREFIX', Zold::Id.new, 'third payment'
138
- ).signed(key, first.id)
139
- )
140
- patch = Zold::Patch.new(home.wallets, log: fake_log)
141
- patch.join(first) { false }
142
- patch.join(second) { false }
143
- assert_equal(true, patch.save(first.path, overwrite: true))
144
- first.flush
145
- assert_equal(3, first.txns.count)
146
- assert_equal(Zold::Amount.new(zld: -6.0).to_s, first.balance.to_s)
147
- end
148
- end
149
-
150
- def test_protocols_new_txns
151
- FakeHome.new(log: fake_log).run do |home|
152
- first = home.create_wallet(Zold::Id::ROOT)
153
- second = home.create_wallet
154
- File.write(second.path, File.read(first.path))
155
- amount = Zold::Amount.new(zld: 333.0)
156
- key = Zold::Key.new(file: 'fixtures/id_rsa')
157
- target = Zold::Id.new
158
- second.sub(amount, "NOPREFIX@#{target}", key, 'some details')
159
- second.sub(amount * 2, "NOPREFIX@#{target}", key)
160
- patch = Zold::Patch.new(home.wallets, log: fake_log)
161
- patch.legacy(first)
162
- Tempfile.open do |f|
163
- patch.join(second, ledger: f.path) { false }
164
- lines = File.read(f).split("\n")
165
- assert_equal(2, lines.count)
166
- parts = lines[0].split(';')
167
- assert(!Zold::Txn.parse_time(parts[0]).nil?)
168
- assert_equal(1, parts[1].to_i)
169
- assert(!Zold::Txn.parse_time(parts[2]).nil?)
170
- assert_equal(Zold::Id::ROOT.to_s, parts[3])
171
- assert_equal(target.to_s, parts[4])
172
- assert_equal(amount, Zold::Amount.new(zents: parts[5].to_i))
173
- assert_equal('NOPREFIX', parts[6])
174
- assert_equal('some details', parts[7])
175
- end
176
- end
177
- end
178
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2024 Zerocracy
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- require 'minitest/autorun'
24
- require 'tmpdir'
25
- require_relative 'fake_home'
26
- require_relative '../lib/zold/key'
27
- require_relative '../lib/zold/id'
28
- require_relative '../lib/zold/wallet'
29
- require_relative '../lib/zold/prefixes'
30
-
31
- # Prefixes test.
32
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
- # Copyright:: Copyright (c) 2018-2024 Zerocracy
34
- # License:: MIT
35
- class TestPrefixes < Zold::Test
36
- def test_creates_and_validates
37
- FakeHome.new(log: fake_log).run do |home|
38
- wallet = home.create_wallet
39
- prefixes = Zold::Prefixes.new(wallet)
40
- (8..32).each do |len|
41
- 50.times do
42
- prefix = prefixes.create(len)
43
- assert_equal(len, prefix.length)
44
- assert(wallet.prefix?(prefix), "Prefix '#{prefix}' not found")
45
- end
46
- end
47
- end
48
- end
49
- end
data/test/test_remotes.rb DELETED
@@ -1,319 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2024 Zerocracy
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- require 'minitest/autorun'
24
- require 'tmpdir'
25
- require 'webmock/minitest'
26
- require 'threads'
27
- require_relative 'test__helper'
28
- require_relative '../lib/zold/log'
29
- require_relative '../lib/zold/age'
30
- require_relative '../lib/zold/remotes'
31
- require_relative '../lib/zold/verbose_thread'
32
-
33
- # Remotes test.
34
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
35
- # Copyright:: Copyright (c) 2018-2024 Zerocracy
36
- # License:: MIT
37
- class TestRemotes < Zold::Test
38
- def test_adds_remotes
39
- Dir.mktmpdir do |dir|
40
- file = File.join(dir, 'remotes')
41
- FileUtils.touch(file)
42
- remotes = Zold::Remotes.new(file: file)
43
- remotes.add('127.0.0.1')
44
- assert(1, remotes.all.count)
45
- end
46
- end
47
-
48
- def test_finds_masters
49
- Dir.mktmpdir do |dir|
50
- file = File.join(dir, 'remotes')
51
- FileUtils.touch(file)
52
- remotes = Zold::Remotes.new(file: file)
53
- assert(remotes.master?('b2.zold.io', 4096))
54
- end
55
- end
56
-
57
- def test_reads_broken_file
58
- Dir.mktmpdir do |dir|
59
- file = File.join(dir, 'remotes')
60
- [
61
- ',0,0,0',
62
- 'some garbage',
63
- '',
64
- "\n\n\n\n"
65
- ].each do |t|
66
- File.write(file, t)
67
- remotes = Zold::Remotes.new(file: file)
68
- assert(remotes.all.empty?, remotes.all)
69
- end
70
- end
71
- end
72
-
73
- def test_iterates_and_fails
74
- Dir.mktmpdir do |dir|
75
- file = File.join(dir, 'remotes')
76
- FileUtils.touch(file)
77
- remotes = Zold::Remotes.new(file: file)
78
- ips = (0..50)
79
- ips.each { |i| remotes.add("0.0.0.#{i + 1}", 9999) }
80
- remotes.iterate(Zold::Log::NULL) { raise 'Intended' }
81
- ips.each { |i| assert(1, remotes.all[i][:errors]) }
82
- end
83
- end
84
-
85
- def test_iterates_all_failures
86
- Dir.mktmpdir do |dir|
87
- file = File.join(dir, 'remotes')
88
- FileUtils.touch(file)
89
- remotes = Zold::Remotes.new(file: file)
90
- 5.times { |i| remotes.add("0.0.0.#{i + 1}", 9999) }
91
- total = 0
92
- remotes.iterate(Zold::Log::NULL) do
93
- total += 1
94
- raise 'Intended'
95
- end
96
- assert_equal(5, total)
97
- end
98
- end
99
-
100
- def test_closes_threads_carefully
101
- Dir.mktmpdir do |dir|
102
- file = File.join(dir, 'remotes')
103
- FileUtils.touch(file)
104
- remotes = Zold::Remotes.new(file: file)
105
- 5.times { |i| remotes.add("0.0.0.#{i + 1}", 9999) }
106
- total = 0
107
- remotes.iterate(Zold::Log::NULL) do
108
- sleep 0.25
109
- total += 1
110
- end
111
- assert_equal(5, total)
112
- end
113
- end
114
-
115
- def test_iterates_them_all_even_with_delays
116
- Dir.mktmpdir do |dir|
117
- remotes = Zold::Remotes.new(file: File.join(dir, 'rrr.csv'))
118
- remotes.clean
119
- 5.times { |i| remotes.add("0.0.0.#{i + 1}", 8080) }
120
- total = 0
121
- remotes.iterate(fake_log) do
122
- sleep 0.25
123
- total += 1
124
- end
125
- assert_equal(5, total)
126
- end
127
- end
128
-
129
- def fake_log_msg_of_iterates_when_fail
130
- Dir.mktmpdir do |dir|
131
- file = File.join(dir, 'remotes')
132
- FileUtils.touch(file)
133
- remotes = Zold::Remotes.new(file: file)
134
- remotes.add('0.0.0.1', 9999)
135
- log = TestLogger.new
136
- remotes.iterate(log) { raise 'Intended' }
137
- assert(log.msgs.find { |m| m.include?(' in ') })
138
- end
139
- end
140
-
141
- def fake_log_msg_of_iterates_when_take_too_long
142
- Dir.mktmpdir do |dir|
143
- file = File.join(dir, 'remotes')
144
- FileUtils.touch(file)
145
- remotes = Zold::Remotes.new(file: file, timeout: 1)
146
- remotes.add('127.0.0.1')
147
- log = TestLogger.new
148
- remotes.iterate(log) { sleep(2) }
149
- assert(log.msgs.find { |m| m.include?('Took too long to execute') })
150
- end
151
- end
152
-
153
- def test_removes_remotes
154
- Dir.mktmpdir do |dir|
155
- file = File.join(dir, 'remotes')
156
- FileUtils.touch(file)
157
- remotes = Zold::Remotes.new(file: file)
158
- remotes.add('127.0.0.1')
159
- remotes.add('LOCALHOST', 433)
160
- remotes.remove('localhost', 433)
161
- assert(1, remotes.all.count)
162
- end
163
- end
164
-
165
- def test_resets_remotes
166
- Dir.mktmpdir do |dir|
167
- remotes = Zold::Remotes.new(file: File.join(dir, 'remotes'))
168
- remotes.clean
169
- remotes.masters
170
- remotes.masters
171
- assert(!remotes.all.empty?)
172
- end
173
- end
174
-
175
- def test_modifies_score
176
- Dir.mktmpdir do |dir|
177
- file = File.join(dir, 'remotes')
178
- FileUtils.touch(file)
179
- remotes = Zold::Remotes.new(file: file)
180
- remotes.add('127.0.0.1', 1024)
181
- remotes.rescore('127.0.0.1', 1024, 15)
182
- remotes.all.each do |r|
183
- assert_equal(15, r[:score])
184
- assert_equal('http://127.0.0.1:1024/', r[:home].to_s)
185
- end
186
- end
187
- end
188
-
189
- def test_tolerates_invalid_requests
190
- Dir.mktmpdir do |dir|
191
- file = File.join(dir, 'remotes')
192
- remotes = Zold::Remotes.new(file: file)
193
- remotes.error('127.0.0.1', 1024)
194
- remotes.rescore('127.0.0.1', 1024, 15)
195
- end
196
- end
197
-
198
- def test_modifies_from_many_threads
199
- Dir.mktmpdir do |dir|
200
- remotes = Zold::Remotes.new(file: File.join(dir, 'a.csv'))
201
- remotes.clean
202
- host = '192.168.0.1'
203
- remotes.add(host)
204
- Threads.new(5).assert do
205
- remotes.error(host)
206
- end
207
- assert_equal(0, remotes.all.reject { |r| r[:host] == host }.size)
208
- end
209
- end
210
-
211
- def test_mtime
212
- Dir.mktmpdir 'test' do |dir|
213
- file = File.join(dir, 'remotes')
214
- FileUtils.touch(file)
215
- File.stub :mtime, Time.mktime(2018, 1, 1) do
216
- remotes = Zold::Remotes.new(file: file)
217
- remotes.add('127.0.0.1')
218
- assert_equal(Time.mktime(2018, 1, 1), remotes.mtime)
219
- end
220
- end
221
- end
222
-
223
- def test_read_mtime_from_file
224
- Dir.mktmpdir 'test' do |dir|
225
- file = File.join(dir, 'a/b/c/remotes')
226
- remotes = Zold::Remotes.new(file: file)
227
- remotes.clean
228
- assert_equal(File.mtime(file).to_i, remotes.mtime.to_i)
229
- end
230
- end
231
-
232
- def test_adds_from_many_threads
233
- Dir.mktmpdir do |dir|
234
- remotes = Zold::Remotes.new(file: File.join(dir, 'xx.csv'))
235
- remotes.clean
236
- host = '127.0.0.1'
237
- Threads.new(2).assert(100) do |_, r|
238
- port = 8080 + r
239
- remotes.add(host, port)
240
- remotes.error(host, port)
241
- assert(remotes.all.find { |x| x[:port] == port })
242
- end
243
- assert_equal(100, remotes.all.count)
244
- end
245
- end
246
-
247
- def test_quickly_ads_and_reads
248
- Dir.mktmpdir do |dir|
249
- remotes = Zold::Remotes.new(file: File.join(dir, 'uu-90.csv'))
250
- remotes.clean
251
- start = Time.now
252
- 100.times { |i| remotes.add('192.168.0.1', 8080 + i) }
253
- Threads.new(4).assert(10) do |t|
254
- remotes.add('127.0.0.1', 8080 + t)
255
- remotes.error('127.0.0.1', 8080 + t)
256
- remotes.all
257
- remotes.iterate(fake_log) { remotes.all }
258
- remotes.remove('127.0.0.1', 8080 + t)
259
- end
260
- fake_log.info("Total time: #{Zold::Age.new(start)}")
261
- end
262
- end
263
-
264
- def test_unerror_remote
265
- Dir.mktmpdir do |dir|
266
- remotes = Zold::Remotes.new(file: File.join(dir, 'uu-90.csv'))
267
- remotes.clean
268
- remotes.add('192.168.0.1', 8081)
269
- assert_equal remotes.all.last[:errors], 0
270
- remotes.error('192.168.0.1', 8081)
271
- assert_equal remotes.all.last[:errors], 1
272
- remotes.unerror('192.168.0.1', 8081)
273
- assert_equal remotes.all.last[:errors], 0
274
- end
275
- end
276
-
277
- def test_empty_remotes
278
- Time.stub :now, Time.mktime(2018, 1, 1) do
279
- remotes = Zold::Remotes::Empty.new
280
- assert_equal(Time.mktime(2018, 1, 1), remotes.mtime)
281
- end
282
- end
283
-
284
- def test_reads_mtime_from_empty_file
285
- Dir.mktmpdir do |dir|
286
- assert(!Zold::Remotes.new(file: File.join(dir, 'file/is/absent')).mtime.nil?)
287
- end
288
- end
289
-
290
- def test_reports_zold_error_header
291
- Dir.mktmpdir do |dir|
292
- remotes = Zold::Remotes.new(file: File.join(dir, 'uu-90.csv'))
293
- remotes.clean
294
- remotes.add('11a-example.org', 8080)
295
- stub_request(:get, 'http://11a-example.org:8080/').to_return(
296
- status: 500,
297
- headers: {
298
- 'X-Zold-Error': 'hey you'
299
- }
300
- )
301
- remotes.iterate(fake_log) do |r|
302
- r.assert_code(200, r.http.get)
303
- end
304
- end
305
- end
306
-
307
- def test_manifests_correct_network_name
308
- Dir.mktmpdir do |dir|
309
- remotes = Zold::Remotes.new(file: File.join(dir, 'uu-083.csv'), network: 'x13')
310
- remotes.clean
311
- remotes.add('r5-example.org', 8080)
312
- stub_request(:get, 'http://r5-example.org:8080/').to_return(status: 200)
313
- remotes.iterate(fake_log) do |r|
314
- r.http.get
315
- end
316
- assert_requested(:get, 'http://r5-example.org:8080/', headers: { 'X-Zold-Network' => 'x13' })
317
- end
318
- end
319
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2024 Zerocracy
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- require 'minitest/autorun'
24
- require 'tmpdir'
25
- require_relative 'test__helper'
26
- require_relative '../lib/zold/key'
27
- require_relative '../lib/zold/id'
28
- require_relative '../lib/zold/txn'
29
- require_relative '../lib/zold/amount'
30
- require_relative '../lib/zold/signature'
31
-
32
- # Signature test.
33
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
34
- # Copyright:: Copyright (c) 2018-2024 Zerocracy
35
- # License:: MIT
36
- class TestSignature < Zold::Test
37
- def test_signs_and_validates
38
- pvt = Zold::Key.new(file: 'fixtures/id_rsa')
39
- pub = Zold::Key.new(file: 'fixtures/id_rsa.pub')
40
- txn = Zold::Txn.new(
41
- 123, Time.now, Zold::Amount.new(zld: 14.95),
42
- 'NOPREFIX', Zold::Id.new, 'hello, world!'
43
- )
44
- id = Zold::Id.new
45
- txn = txn.signed(pvt, id)
46
- assert_equal(684, txn.sign.length)
47
- assert(Zold::Signature.new.valid?(pub, id, txn))
48
- end
49
- end