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
data/test/test_txn.rb DELETED
@@ -1,71 +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 'time'
8
- require_relative 'test__helper'
9
- require_relative '../lib/zold/id'
10
- require_relative '../lib/zold/txn'
11
- require_relative '../lib/zold/amount'
12
-
13
- # Txn test.
14
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
15
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
16
- # License:: MIT
17
- class TestTxn < Zold::Test
18
- def test_prints_and_parses
19
- time = Time.now
20
- txn = Zold::Txn.parse(
21
- Zold::Txn.new(
22
- 123, time, Zold::Amount.new(zld: -99.95),
23
- 'NOPREFIX', Zold::Id.new,
24
- 'Some details to see 123. Works, or not.'
25
- ).to_s
26
- )
27
- assert_equal(123, txn.id)
28
- assert_equal('-99.95', txn.amount.to_zld)
29
- assert_equal('NOPREFIX', txn.prefix)
30
- end
31
-
32
- def test_converts_to_json
33
- time = Time.now
34
- txn = Zold::Txn.new(
35
- 123, time, Zold::Amount.new(zld: -99.95),
36
- 'NOPREFIX', Zold::Id.new('0123012301230123'),
37
- 'Some details to see'
38
- )
39
- json = txn.to_json
40
- assert_equal(123, json[:id])
41
- assert_equal(-429_281_981_235, json[:amount])
42
- assert_equal('NOPREFIX', json[:prefix])
43
- assert_equal('0123012301230123', json[:bnf])
44
- assert_equal('Some details to see', json[:details])
45
- end
46
-
47
- def test_accepts_text_as_details
48
- [
49
- 'How are you, dude?! I\'m @yegor256: *_hello_',
50
- 'For a pizza to my friend: John! Good? Works.',
51
- 'ZLD exchange to 0.00104 BTC at 3NimQKG2kuseH3cz3hdbdEHbqai9kj, rate is 0.00026, fee is 0.08'
52
- ].each do |details|
53
- txn = Zold::Txn.parse(
54
- Zold::Txn.new(
55
- 123, Time.now, Zold::Amount.new(zld: -99.95),
56
- 'NOPREFIX', Zold::Id.new,
57
- details
58
- ).to_s
59
- )
60
- assert_equal(details, txn.details)
61
- end
62
- end
63
-
64
- def test_prints_and_parses_time
65
- 10.times do |i|
66
- time = Time.now + (i * 12_345)
67
- iso = time.utc.iso8601
68
- assert_equal(time.to_s, Zold::Txn.parse_time(iso).to_s)
69
- end
70
- end
71
- end
@@ -1,81 +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 '../lib/zold/upgrades'
8
- require_relative '../lib/zold/version_file'
9
-
10
- # Upgrade test.
11
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
12
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
13
- # License:: MIT
14
- class TestUpgrades < Zold::Test
15
- # @todo #327:30min Uncomment, when you're ready to work on upgrade manager's
16
- # test case of absent version file. Start with running the test first.
17
- def test_no_version_file_is_ok
18
- skip
19
- Dir.mktmpdir do |dir|
20
- script_version = '0.0.1'
21
- create_upgrade_file(dir, script_version)
22
- assert_output(/#{expected_upgrade_script_output(script_version)}/) do
23
- run_upgrades(dir)
24
- end
25
- end
26
- end
27
-
28
- # @todo #327:30min Uncomment, when you're ready to work on upgrade manager's
29
- # test case of running only pending upgrade scripts (i.e. the scripts with
30
- # versions greater than those in the version file).
31
- def test_pending_scripts_run
32
- skip
33
- Dir.mktmpdir do |dir|
34
- %w[1 2].each do |script_version|
35
- create_upgrade_file(dir, script_version)
36
- end
37
- create_version_file(dir, '1')
38
- assert_output(/#{expected_upgrade_script_output('2')}/) do
39
- run_upgrades(dir)
40
- end
41
- end
42
- end
43
-
44
- def test_already_ran_scripts_dont_run
45
- Dir.mktmpdir do |dir|
46
- %w[1 2].each do |script_version|
47
- create_upgrade_file(dir, script_version)
48
- end
49
- create_version_file(dir, '1')
50
- out, _err = capture_io do
51
- run_upgrades(dir)
52
- end
53
- refute_match(/#{expected_upgrade_script_output('1')}/, out)
54
- end
55
- end
56
-
57
- private
58
-
59
- def run_upgrades(dir)
60
- Zold::Upgrades.new(version_file(dir), dir, { network: 'test' }).run
61
- end
62
-
63
- def version_file(dir)
64
- Zold::VersionFile.new(File.join(dir, 'version'))
65
- end
66
-
67
- def create_version_file(dir, version)
68
- File.write(File.join(dir, 'version'), version)
69
- end
70
-
71
- def create_upgrade_file(dir, version)
72
- File.write(
73
- File.join(dir, "#{version}.rb"),
74
- "puts \"#{expected_upgrade_script_output(version)}\""
75
- )
76
- end
77
-
78
- def expected_upgrade_script_output(version)
79
- "upgrading to #{version}"
80
- end
81
- end
@@ -1,37 +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 '../lib/zold/verbose_thread'
8
-
9
- # VerboseThread test.
10
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
12
- # License:: MIT
13
- class TestVerboseThread < Zold::Test
14
- def test_exceptions_are_logged
15
- assert_raises RuntimeError do
16
- Zold::VerboseThread.new(Loog::NULL).run do
17
- raise 'Intentional'
18
- end
19
- end
20
- end
21
-
22
- def test_syntax_exceptions_are_logged
23
- assert_raises NoMethodError do
24
- Zold::VerboseThread.new(Loog::NULL).run do
25
- this_method_doesnt_exist(1)
26
- end
27
- end
28
- end
29
-
30
- def test_grammar_exceptions_are_logged
31
- assert_raises NameError do
32
- Zold::VerboseThread.new(Loog::NULL).run do
33
- the syntax is broken here
34
- end
35
- end
36
- end
37
- end
data/test/test_version.rb DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'semantic'
7
- require 'zold/version'
8
-
9
- class TestVersion < Zold::Test
10
- def test_has_version
11
- assert Semantic::Version.new(Zold::VERSION)
12
- end
13
-
14
- def test_has_protocol
15
- assert Zold::PROTOCOL
16
- end
17
- end
data/test/test_wallet.rb DELETED
@@ -1,300 +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 'fake_home'
9
- require_relative '../lib/zold/key'
10
- require_relative '../lib/zold/age'
11
- require_relative '../lib/zold/id'
12
- require_relative '../lib/zold/wallet'
13
- require_relative '../lib/zold/txn'
14
- require_relative '../lib/zold/thread_pool'
15
- require_relative '../lib/zold/amount'
16
- require_relative '../lib/zold/commands/pay'
17
-
18
- # Wallet test.
19
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
20
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
21
- # License:: MIT
22
- class TestWallet < Zold::Test
23
- def test_reads_empty_wallet
24
- FakeHome.new(log: fake_log).run do |home|
25
- wallet = home.create_wallet
26
- assert_empty(wallet.txns)
27
- assert_equal(Zold::Amount::ZERO, wallet.balance)
28
- end
29
- end
30
-
31
- def test_generates_memo
32
- FakeHome.new(log: fake_log).run do |home|
33
- wallet = home.create_wallet
34
- refute_nil(wallet.mnemo)
35
- end
36
- end
37
-
38
- def test_reads_large_wallet
39
- key = Zold::Key.new(file: 'fixtures/id_rsa')
40
- FakeHome.new(log: fake_log).run do |home|
41
- wallet = home.create_wallet(Zold::Id.new('448b451bc62e8e16'))
42
- FileUtils.cp('fixtures/448b451bc62e8e16.z', wallet.path)
43
- start = Time.now
44
- wallet.txns
45
- wallet.sub(Zold::Amount.new(zld: 39.99), "NOPREFIX@#{Zold::Id.new}", key)
46
- time = Time.now - start
47
- assert_operator(time, :<, 0.5, "Too slow: #{Zold::Age.new(start)} seconds")
48
- end
49
- end
50
-
51
- def test_adds_transaction
52
- FakeHome.new(log: fake_log).run do |home|
53
- wallet = home.create_wallet
54
- amount = Zold::Amount.new(zld: 39.99)
55
- key = Zold::Key.new(file: 'fixtures/id_rsa')
56
- wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
57
- wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
58
- wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
59
- assert_equal(
60
- wallet.balance, amount * -3,
61
- "#{wallet.balance} is not equal to #{amount * -3}"
62
- )
63
- end
64
- end
65
-
66
- def test_adds_similar_transaction
67
- FakeHome.new(log: fake_log).run do |home|
68
- wallet = home.create_wallet
69
- amount = Zold::Amount.new(zld: 39.99)
70
- key = Zold::Key.new(file: 'fixtures/id_rsa')
71
- id = Zold::Id.new
72
- wallet.sub(amount, "NOPREFIX@#{id}", key)
73
- wallet.add(Zold::Txn.new(1, Time.now, amount, 'NOPREFIX', id, '-'))
74
- assert_raises do
75
- wallet.add(Zold::Txn.new(1, Time.now, amount, 'NOPREFIX', id, '-'))
76
- end
77
- assert_raises do
78
- wallet.add(Zold::Txn.new(1, Time.now, amount * -1, 'NOPREFIX', id, '-'))
79
- end
80
- assert_predicate(wallet.balance, :zero?)
81
- end
82
- end
83
-
84
- def test_checks_similar_transaction
85
- FakeHome.new(log: fake_log).run do |home|
86
- wallet = home.create_wallet
87
- amount = Zold::Amount.new(zld: 39.99)
88
- key = Zold::Key.new(file: 'fixtures/id_rsa')
89
- id = Zold::Id.new
90
- wallet.sub(amount, "NOPREFIX@#{id}", key)
91
- wallet.add(Zold::Txn.new(1, Time.now, amount, 'NOPREFIX', id, '-'))
92
- assert(wallet.includes_negative?(1))
93
- assert(wallet.includes_positive?(1, id))
94
- end
95
- end
96
-
97
- def test_refurbishes_wallet
98
- FakeHome.new(log: fake_log).run do |home|
99
- wallet = home.create_wallet
100
- amount = Zold::Amount.new(zld: 5.99)
101
- key = Zold::Key.new(file: 'fixtures/id_rsa')
102
- wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
103
- wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
104
- before = File.read(wallet.path)
105
- File.write(wallet.path, "#{File.read(wallet.path)}\n\n\n")
106
- wallet.refurbish
107
- assert_equal(amount * -2, wallet.balance)
108
- assert_equal(before, File.read(wallet.path))
109
- end
110
- end
111
-
112
- def test_refurbishes_empty_wallet
113
- FakeHome.new(log: fake_log).run do |home|
114
- wallet = home.create_wallet
115
- before = File.read(wallet.path)
116
- File.write(wallet.path, "#{File.read(wallet.path)}\n\n\n")
117
- wallet.refurbish
118
- assert_equal(before, File.read(wallet.path))
119
- end
120
- end
121
-
122
- def test_positive_transactions_go_first
123
- FakeHome.new(log: fake_log).run do |home|
124
- wallet = home.create_wallet
125
- time = Time.now
126
- key = Zold::Key.new(file: 'fixtures/id_rsa')
127
- wallet.add(Zold::Txn.new(1, time, Zold::Amount.new(zents: 1), 'NOPREFIX', Zold::Id.new, '-'))
128
- wallet.sub(Zold::Amount.new(zents: 2), "NOPREFIX@#{Zold::Id.new}", key, time: time)
129
- wallet.add(Zold::Txn.new(2, time, Zold::Amount.new(zents: 3), 'NOPREFIX', Zold::Id.new, '-'))
130
- wallet.sub(Zold::Amount.new(zents: 4), "NOPREFIX@#{Zold::Id.new}", key, time: time)
131
- assert_equal('3, 1, -2, -4', wallet.txns.map { |t| t.amount.to_i }.join(', '))
132
- end
133
- end
134
-
135
- def test_validate_key_on_payment
136
- FakeHome.new(log: fake_log).run do |home|
137
- wallet = home.create_wallet
138
- amount = Zold::Amount.new(zld: 39.99)
139
- key = Zold::Key.new(file: 'fixtures/id_rsa-2')
140
- assert_raises RuntimeError do
141
- wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
142
- end
143
- end
144
- end
145
-
146
- def test_adds_transaction_and_reads_back
147
- FakeHome.new(log: fake_log).run do |home|
148
- wallet = home.create_wallet
149
- amount = Zold::Amount.new(zld: 39.99)
150
- key = Zold::Key.new(file: 'fixtures/id_rsa')
151
- txn = wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
152
- wallet.add(txn.inverse(Zold::Id.new))
153
- refute(Zold::Wallet.new(wallet.path).txns[1].sign.end_with?("\n"))
154
- end
155
- end
156
-
157
- def test_calculates_wallet_age_in_hours
158
- FakeHome.new(log: fake_log).run do |home|
159
- wallet = home.create_wallet
160
- hours = 100
161
- wallet.add(
162
- Zold::Txn.new(
163
- 1,
164
- Time.now - (100 * 60 * 60),
165
- Zold::Amount.new(zld: 1.99),
166
- 'NOPREFIX', Zold::Id.new, '-'
167
- )
168
- )
169
- assert_equal(hours, wallet.age.round)
170
- end
171
- end
172
-
173
- def test_flushes_and_reads_again
174
- FakeHome.new(log: fake_log).run do |home|
175
- wallet = home.create_wallet
176
- wallet.add(
177
- Zold::Txn.new(
178
- 1,
179
- Time.now,
180
- Zold::Amount.new(zld: 1.99),
181
- 'NOPREFIX', Zold::Id.new, '-'
182
- )
183
- )
184
- assert_equal(1, wallet.txns.count)
185
- assert_equal('test', wallet.network)
186
- wallet.flush
187
- assert_equal(1, wallet.txns.count)
188
- assert_equal('test', wallet.network)
189
- end
190
- end
191
-
192
- def test_returns_modified_time
193
- FakeHome.new(log: fake_log).run do |home|
194
- wallet = home.create_wallet
195
- assert_operator(wallet.mtime, :>, Time.now - (60 * 60))
196
- end
197
- end
198
-
199
- def test_returns_digest
200
- FakeHome.new(log: fake_log).run do |home|
201
- wallet = home.create_wallet
202
- assert_equal(64, wallet.digest.length)
203
- end
204
- end
205
-
206
- def test_raises_when_broken_format
207
- Dir.mktmpdir do |dir|
208
- file = File.join(dir, "0123456701234567#{Zold::Wallet::EXT}")
209
- File.write(file, 'broken head')
210
- assert_raises(Zold::Head::CantParse) do
211
- Zold::Wallet.new(file).id
212
- end
213
- assert_raises(Zold::Txns::CantParse) do
214
- Zold::Wallet.new(file).txns
215
- end
216
- end
217
- end
218
-
219
- def test_returns_protocol
220
- FakeHome.new(log: fake_log).run do |home|
221
- wallet = home.create_wallet
222
- assert_equal(Zold::PROTOCOL, wallet.protocol)
223
- end
224
- end
225
-
226
- def test_iterates_income_transactions
227
- FakeHome.new(log: fake_log).run do |home|
228
- wallet = home.create_wallet
229
- wallet.add(
230
- Zold::Txn.new(
231
- 1, Time.now, Zold::Amount.new(zld: 39.99),
232
- 'NOPREFIX', Zold::Id.new, '-'
233
- )
234
- )
235
- wallet.add(
236
- Zold::Txn.new(
237
- 2, Time.now, Zold::Amount.new(zld: 14.95),
238
- 'NOPREFIX', Zold::Id.new, '-'
239
- )
240
- )
241
- sum = Zold::Amount::ZERO
242
- wallet.txns.each do |t|
243
- sum += t.amount unless t.amount.negative?
244
- end
245
- assert_equal(
246
- sum, Zold::Amount.new(zents: 235_965_503_242),
247
- "#{sum} (#{sum.to_i}) is not equal to #{Zold::Amount.new(zld: 54.94)}"
248
- )
249
- end
250
- end
251
-
252
- def test_sorts_them_always_right
253
- FakeHome.new(log: fake_log).run do |home|
254
- time = Time.now
255
- txns = []
256
- 50.times do
257
- txns << Zold::Txn.new(
258
- 1,
259
- time,
260
- Zold::Amount.new(zld: 1.99),
261
- 'NOPREFIX', Zold::Id.new, '-'
262
- )
263
- end
264
- wallet = home.create_wallet
265
- empty = File.read(wallet.path)
266
- text = ''
267
- 10.times do
268
- File.write(wallet.path, empty)
269
- txns.shuffle!
270
- txns.each { |t| wallet.add(t) }
271
- wallet.refurbish
272
- if text.empty?
273
- text = File.read(wallet.path)
274
- next
275
- end
276
- assert_equal(text, File.read(wallet.path))
277
- end
278
- end
279
- end
280
-
281
- def test_collects_memory_garbage
282
- skip
283
- require 'get_process_mem'
284
- start = GetProcessMem.new.bytes.to_i
285
- Zold::Hands.exec(20) do
286
- 40.times do |i|
287
- wallet = Zold::Wallet.new('fixtures/448b451bc62e8e16.z')
288
- GC.start
289
- wallet.id
290
- wallet.txns.count
291
- fake_log.debug("Memory: #{GetProcessMem.new.bytes.to_i}") if (i % 5).zero?
292
- end
293
- end
294
- GC.stress = true
295
- diff = GetProcessMem.new.bytes.to_i - start
296
- GC.stress = false
297
- fake_log.debug("Memory diff is #{diff}")
298
- assert_operator(diff, :<, 20_000_000)
299
- end
300
- end
data/test/test_wallets.rb DELETED
@@ -1,67 +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 'fake_home'
9
- require_relative '../lib/zold/key'
10
- require_relative '../lib/zold/id'
11
- require_relative '../lib/zold/wallets'
12
- require_relative '../lib/zold/amount'
13
-
14
- # Wallets test.
15
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
16
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
17
- # License:: MIT
18
- class TestWallets < Zold::Test
19
- def test_adds_wallet
20
- FakeHome.new(log: fake_log).run do |home|
21
- wallets = home.wallets
22
- id = Zold::Id.new
23
- wallets.acq(id) do |wallet|
24
- wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
25
- assert_equal(1, wallets.all.count)
26
- end
27
- end
28
- end
29
-
30
- def test_lists_wallets_and_ignores_garbage
31
- FakeHome.new(log: fake_log).run do |home|
32
- wallets = home.wallets
33
- FileUtils.touch(File.join(home.dir, '0xaaaaaaaaaaaaaaaaaaahello'))
34
- FileUtils.mkdir_p(File.join(home.dir, 'a/b/c'))
35
- FileUtils.touch(File.join(home.dir, 'a/b/c/0000111122223333.z'))
36
- id = Zold::Id.new
37
- wallets.acq(id) do |wallet|
38
- wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
39
- assert_equal(1, wallets.all.count)
40
- end
41
- end
42
- end
43
-
44
- def test_subtracts_dir_path_from_full_path
45
- Dir.mktmpdir do |dir|
46
- Dir.chdir(dir) do
47
- wallets = Zold::Wallets.new(Dir.pwd)
48
- assert_equal('.', wallets.to_s)
49
- end
50
- end
51
- end
52
-
53
- def test_count_wallets
54
- Dir.mktmpdir do |dir|
55
- Dir.chdir(dir) do
56
- 5.times { |i| FileUtils.touch("wallet_#{i}#{Zold::Wallet::EXT}") }
57
- wallets = Zold::Wallets.new(Dir.pwd)
58
- assert_equal(5, wallets.count)
59
- end
60
- end
61
- FakeHome.new(log: fake_log).run do |home|
62
- wallets = home.wallets
63
- home.create_wallet
64
- assert_equal(1, wallets.count)
65
- end
66
- end
67
- end
data/test/test_zold.rb DELETED
@@ -1,81 +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 'open3'
8
- require 'English'
9
- require_relative 'test__helper'
10
- require_relative '../lib/zold/version'
11
- require_relative '../lib/zold/age'
12
-
13
- # Zold main module test.
14
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
15
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
16
- # License:: MIT
17
- class TestZold < Zold::Test
18
- Dir.new('fixtures/scripts').select { |f| f =~ /\.sh$/ && !f.start_with?('_') }.each do |f|
19
- method = "test_#{f.gsub(/\.sh$/, '').gsub(/[^a-z]/, '_')}"
20
- define_method(method) do
21
- start = Time.now
22
- fake_log.info("\n\n#{method} running (script at #{f})...")
23
- Dir.mktmpdir do |dir|
24
- FileUtils.cp('fixtures/id_rsa.pub', dir)
25
- FileUtils.cp('fixtures/id_rsa', dir)
26
- script = File.join(dir, f)
27
- File.write(script, File.read('fixtures/scripts/_head.sh') + File.read(File.join('fixtures/scripts', f)))
28
- bin = File.join(Dir.pwd, 'bin/zold')
29
- out = []
30
- Dir.chdir(dir) do
31
- Open3.popen2e("/bin/bash #{f} #{bin} 2>&1") do |stdin, stdout, thr|
32
- stdin.close
33
- until stdout.eof?
34
- line = stdout.gets
35
- fake_log.info(line)
36
- out << line
37
- end
38
- code = thr.value.to_i
39
- assert_equal(0, code, "#{f}\n#{out.join}")
40
- end
41
- end
42
- sleep 1 # It's a workaround, I can't fix the bug (tests crash sporadically)
43
- end
44
- fake_log.info("\n\n#{f} done in #{Zold::Age.new(start)}")
45
- end
46
- end
47
-
48
- def test_help
49
- stdout = exec('--help')
50
- assert_includes(stdout, 'Usage: zold')
51
- end
52
-
53
- def test_show_version
54
- stdout = exec('--version')
55
- assert_includes(stdout, Zold::VERSION)
56
- end
57
-
58
- def test_create_new_wallet
59
- Dir.mktmpdir do |dir|
60
- FileUtils.cp('fixtures/id_rsa.pub', dir)
61
- FileUtils.cp('fixtures/id_rsa', dir)
62
- stdout = exec(
63
- '--verbose --trace create --public-key=id_rsa.pub',
64
- dir
65
- )
66
- assert_includes(stdout, 'created at')
67
- end
68
- end
69
-
70
- private
71
-
72
- def exec(tail, dir = Dir.pwd)
73
- bin = File.expand_path(File.join(Dir.pwd, 'bin/zold'))
74
- stdout = `cd #{dir} && #{bin} #{tail} 2>&1`
75
- unless $CHILD_STATUS.exitstatus.zero?
76
- puts stdout
77
- assert_equal(0, $CHILD_STATUS.exitstatus)
78
- end
79
- stdout
80
- end
81
- end
@@ -1,29 +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 '../../lib/zold/id'
8
- require_relative '../../upgrades/delete_banned_wallets'
9
- require_relative '../fake_home'
10
-
11
- # Delete banned wallets.
12
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
13
- # Copyright:: Copyright (c) 2018-2025 Zerocracy
14
- # License:: MIT
15
- class TestDeleteBannedWallets < Zold::Test
16
- def test_delete_them
17
- id = Zold::Id.new(Zold::Id::BANNED[0])
18
- FakeHome.new(log: fake_log).run do |home|
19
- home.create_wallet(id)
20
- FileUtils.mkdir_p(File.join(home.dir, 'a/b/c'))
21
- File.rename(
22
- File.join(home.dir, "#{id}#{Zold::Wallet::EXT}"),
23
- File.join(home.dir, "a/b/c/#{id}#{Zold::Wallet::EXT}")
24
- )
25
- Zold::DeleteBannedWallets.new(home.dir, fake_log).exec
26
- assert_path_exists(File.join(home.dir, "a/b/c/#{id}#{Zold::Wallet::EXT}-banned"))
27
- end
28
- end
29
- end