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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/zold/version.rb +1 -1
- data/zold.gemspec +1 -1
- metadata +2 -168
- data/.0pdd.yml +0 -12
- data/.gitattributes +0 -9
- data/.github/typos.toml +0 -11
- data/.github/workflows/actionlint.yml +0 -25
- data/.github/workflows/bashate.yml +0 -25
- data/.github/workflows/codecov.yml +0 -27
- data/.github/workflows/copyrights.yml +0 -15
- data/.github/workflows/hadolint.yml +0 -14
- data/.github/workflows/markdown-lint.yml +0 -19
- data/.github/workflows/pdd.yml +0 -19
- data/.github/workflows/rake.yml +0 -31
- data/.github/workflows/reuse.yml +0 -19
- data/.github/workflows/shellcheck.yml +0 -19
- data/.github/workflows/typos.yml +0 -21
- data/.github/workflows/xcop.yml +0 -15
- data/.github/workflows/yamllint.yml +0 -19
- data/.gitignore +0 -15
- data/.pdd +0 -7
- data/.rubocop.yml +0 -66
- data/.ruby-version +0 -1
- data/.rultor.yml +0 -41
- data/cucumber.yml +0 -6
- data/features/cli.feature +0 -18
- data/features/gem_package.feature +0 -28
- data/features/step_definitions/steps.rb +0 -67
- data/features/support/env.rb +0 -9
- data/fixtures/448b451bc62e8e16.z +0 -1005
- data/fixtures/id_rsa +0 -51
- data/fixtures/id_rsa-2 +0 -51
- data/fixtures/id_rsa-2.pub +0 -1
- data/fixtures/id_rsa.pub +0 -1
- data/fixtures/keys/1.pub +0 -1
- data/fixtures/keys/2 +0 -51
- data/fixtures/keys/2.pub +0 -1
- data/fixtures/merge/asserts.rb +0 -20
- data/fixtures/merge/id_rsa +0 -51
- data/fixtures/merge/id_rsa.pub +0 -1
- data/fixtures/merge/into_no_wallet/assert.rb +0 -8
- data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/into_no_wallet/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/into_no_wallet/opts +0 -1
- data/fixtures/merge/legacy_negatives_stay/0123456789abcdef.z +0 -6
- data/fixtures/merge/legacy_negatives_stay/assert.rb +0 -8
- data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/legacy_negatives_stay/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/legacy_negatives_stay/opts +0 -2
- data/fixtures/merge/missed_wallets/0000000000000000.z +0 -6
- data/fixtures/merge/missed_wallets/0123456789abcdef.z +0 -4
- data/fixtures/merge/missed_wallets/assert.rb +0 -8
- data/fixtures/merge/missed_wallets/copies/0123456789abcdef/1.zc +0 -8
- data/fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/missed_wallets/opts +0 -3
- data/fixtures/merge/negative_overwriting/0123456789abcdef.z +0 -6
- data/fixtures/merge/negative_overwriting/146b852f2d9ad984.z +0 -6
- data/fixtures/merge/negative_overwriting/assert.rb +0 -8
- data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/negative_overwriting/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/negative_overwriting/opts +0 -2
- data/fixtures/merge/negatives_in_between/0000000000000000.z +0 -6
- data/fixtures/merge/negatives_in_between/0123456789abcdef.z +0 -4
- data/fixtures/merge/negatives_in_between/assert.rb +0 -8
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc +0 -6
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/3.zc +0 -6
- data/fixtures/merge/negatives_in_between/copies/0123456789abcdef/scores.zc +0 -3
- data/fixtures/merge/negatives_in_between/opts +0 -1
- data/fixtures/merge/random_expenses/0000000000000000.z +0 -6
- data/fixtures/merge/random_expenses/0123456789abcdef.z +0 -6
- data/fixtures/merge/random_expenses/assert.rb +0 -8
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/1.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/2.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/3.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/4.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/5.zc +0 -7
- data/fixtures/merge/random_expenses/copies/0123456789abcdef/scores.zc +0 -5
- data/fixtures/merge/random_expenses/opts +0 -1
- data/fixtures/merge/simple_case/0000000000000000.z +0 -6
- data/fixtures/merge/simple_case/0123456789abcdef.z +0 -4
- data/fixtures/merge/simple_case/assert.rb +0 -8
- data/fixtures/merge/simple_case/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/simple_case/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/simple_case/opts +0 -1
- data/fixtures/merge/unconfirmed_income/0123456789abcdef.z +0 -4
- data/fixtures/merge/unconfirmed_income/assert.rb +0 -8
- data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/1.zc +0 -6
- data/fixtures/merge/unconfirmed_income/copies/0123456789abcdef/scores.zc +0 -1
- data/fixtures/merge/unconfirmed_income/opts +0 -3
- data/fixtures/scripts/_head.sh +0 -72
- data/fixtures/scripts/calculate-scores.sh +0 -5
- data/fixtures/scripts/distribute-wallet.sh +0 -88
- data/fixtures/scripts/print-helps.sh +0 -9
- data/fixtures/scripts/pull-on-start.sh +0 -35
- data/fixtures/scripts/push-and-pull.sh +0 -46
- data/fixtures/scripts/redeploy-on-upgrade.sh +0 -40
- data/fixtures/scripts/spread-wallets.sh +0 -56
- data/renovate.json +0 -6
- data/test/commands/routines/test_audit.rb +0 -23
- data/test/commands/routines/test_gc.rb +0 -52
- data/test/commands/routines/test_reconcile.rb +0 -33
- data/test/commands/routines/test_reconnect.rb +0 -28
- data/test/commands/routines/test_retire.rb +0 -22
- data/test/commands/test_alias.rb +0 -58
- data/test/commands/test_calculate.rb +0 -22
- data/test/commands/test_clean.rb +0 -55
- data/test/commands/test_create.rb +0 -32
- data/test/commands/test_diff.rb +0 -43
- data/test/commands/test_fetch.rb +0 -144
- data/test/commands/test_invoice.rb +0 -32
- data/test/commands/test_list.rb +0 -29
- data/test/commands/test_merge.rb +0 -106
- data/test/commands/test_node.rb +0 -50
- data/test/commands/test_pay.rb +0 -203
- data/test/commands/test_propagate.rb +0 -33
- data/test/commands/test_pull.rb +0 -52
- data/test/commands/test_push.rb +0 -75
- data/test/commands/test_remote.rb +0 -247
- data/test/commands/test_remove.rb +0 -48
- data/test/commands/test_show.rb +0 -30
- data/test/commands/test_taxes.rb +0 -58
- data/test/fake_home.rb +0 -87
- data/test/node/fake_entrance.rb +0 -26
- data/test/node/fake_node.rb +0 -88
- data/test/node/test_async_entrance.rb +0 -85
- data/test/node/test_entrance.rb +0 -64
- data/test/node/test_farm.rb +0 -159
- data/test/node/test_farmers.rb +0 -58
- data/test/node/test_front.rb +0 -379
- data/test/node/test_nodup_entrance.rb +0 -31
- data/test/node/test_nospam_entrance.rb +0 -31
- data/test/node/test_safe_entrance.rb +0 -41
- data/test/node/test_spread_entrance.rb +0 -49
- data/test/node/test_sync_entrance.rb +0 -23
- data/test/node/test_trace.rb +0 -18
- data/test/test__helper.rb +0 -113
- data/test/test_age.rb +0 -37
- data/test/test_amount.rb +0 -62
- data/test/test_cached_wallets.rb +0 -55
- data/test/test_copies.rb +0 -127
- data/test/test_dir_items.rb +0 -72
- data/test/test_gem.rb +0 -23
- data/test/test_hands.rb +0 -51
- data/test/test_hexnum.rb +0 -18
- data/test/test_http.rb +0 -207
- data/test/test_hungry_wallets.rb +0 -72
- data/test/test_id.rb +0 -61
- data/test/test_json_page.rb +0 -29
- data/test/test_key.rb +0 -81
- data/test/test_metronome.rb +0 -71
- data/test/test_patch.rb +0 -160
- data/test/test_prefixes.rb +0 -31
- data/test/test_remotes.rb +0 -301
- data/test/test_signature.rb +0 -31
- data/test/test_size.rb +0 -21
- data/test/test_sync_wallets.rb +0 -39
- data/test/test_tax.rb +0 -153
- data/test/test_thread_pool.rb +0 -71
- data/test/test_tree_wallets.rb +0 -65
- data/test/test_txn.rb +0 -71
- data/test/test_upgrades.rb +0 -81
- data/test/test_verbose_thread.rb +0 -37
- data/test/test_version.rb +0 -17
- data/test/test_wallet.rb +0 -300
- data/test/test_wallets.rb +0 -67
- data/test/test_zold.rb +0 -81
- data/test/upgrades/test_delete_banned_wallets.rb +0 -29
- data/test/upgrades/test_protocol_up.rb +0 -24
data/test/commands/test_clean.rb
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
-
# SPDX-License-Identifier: MIT
|
|
5
|
-
|
|
6
|
-
require 'time'
|
|
7
|
-
require 'threads'
|
|
8
|
-
require_relative '../fake_home'
|
|
9
|
-
require_relative '../test__helper'
|
|
10
|
-
require_relative '../../lib/zold/copies'
|
|
11
|
-
require_relative '../../lib/zold/commands/clean'
|
|
12
|
-
|
|
13
|
-
# CLEAN test.
|
|
14
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
15
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
16
|
-
# License:: MIT
|
|
17
|
-
class TestClean < Zold::Test
|
|
18
|
-
def test_cleans_copies
|
|
19
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
20
|
-
wallet = home.create_wallet
|
|
21
|
-
copies = home.copies(wallet)
|
|
22
|
-
copies.add('a1', 'host-1', 80, 1, time: Time.now - (26 * 60 * 60))
|
|
23
|
-
copies.add('a2', 'host-2', 80, 2, time: Time.now - (26 * 60 * 60))
|
|
24
|
-
Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: fake_log).run(['clean', wallet.id.to_s])
|
|
25
|
-
assert_empty(copies.all)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_clean_no_copies
|
|
30
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
31
|
-
wallet = home.create_wallet
|
|
32
|
-
copies = home.copies(wallet)
|
|
33
|
-
Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: fake_log).run(['clean'])
|
|
34
|
-
assert_empty(copies.all)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_cleans_empty_wallets
|
|
39
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
40
|
-
Zold::Clean.new(wallets: home.wallets, copies: File.join(home.dir, 'c'), log: fake_log).run(['clean'])
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_cleans_copies_in_threads
|
|
45
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
46
|
-
wallet = home.create_wallet
|
|
47
|
-
copies = home.copies(wallet)
|
|
48
|
-
copies.add(File.read(wallet.path), 'host-2', 80, 2, time: Time.now)
|
|
49
|
-
Threads.new(20).assert do
|
|
50
|
-
Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: fake_log).run(['clean'])
|
|
51
|
-
end
|
|
52
|
-
assert_equal(1, copies.all.count)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,32 +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/key'
|
|
10
|
-
require_relative '../../lib/zold/commands/create'
|
|
11
|
-
|
|
12
|
-
# CREATE test.
|
|
13
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
14
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
15
|
-
# License:: MIT
|
|
16
|
-
class TestCreate < Zold::Test
|
|
17
|
-
def test_creates_wallet
|
|
18
|
-
Dir.mktmpdir do |dir|
|
|
19
|
-
wallets = Zold::Wallets.new(dir)
|
|
20
|
-
id = Zold::Create.new(wallets: wallets, remotes: nil, log: fake_log).run(
|
|
21
|
-
['create', '--public-key=fixtures/id_rsa.pub', '--skip-test']
|
|
22
|
-
)
|
|
23
|
-
wallets.acq(id) do |wallet|
|
|
24
|
-
assert_predicate(wallet.balance, :zero?)
|
|
25
|
-
assert_path_exists(
|
|
26
|
-
File.join(dir, "#{wallet.id}#{Zold::Wallet::EXT}"),
|
|
27
|
-
"Wallet file not found: #{wallet.id}#{Zold::Wallet::EXT}"
|
|
28
|
-
)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
data/test/commands/test_diff.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Zerocracy
|
|
4
|
-
# SPDX-License-Identifier: MIT
|
|
5
|
-
|
|
6
|
-
require 'json'
|
|
7
|
-
require 'time'
|
|
8
|
-
require 'webmock/minitest'
|
|
9
|
-
require_relative '../test__helper'
|
|
10
|
-
require_relative '../fake_home'
|
|
11
|
-
require_relative '../../lib/zold/wallets'
|
|
12
|
-
require_relative '../../lib/zold/wallet'
|
|
13
|
-
require_relative '../../lib/zold/id'
|
|
14
|
-
require_relative '../../lib/zold/copies'
|
|
15
|
-
require_relative '../../lib/zold/key'
|
|
16
|
-
require_relative '../../lib/zold/commands/pay'
|
|
17
|
-
require_relative '../../lib/zold/commands/diff'
|
|
18
|
-
|
|
19
|
-
# DIFF test.
|
|
20
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
21
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
22
|
-
# License:: MIT
|
|
23
|
-
class TestDiff < Zold::Test
|
|
24
|
-
def test_diff_with_copies
|
|
25
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
26
|
-
wallet = home.create_wallet
|
|
27
|
-
first = home.create_wallet
|
|
28
|
-
File.write(first.path, File.read(wallet.path))
|
|
29
|
-
second = home.create_wallet
|
|
30
|
-
File.write(second.path, File.read(wallet.path))
|
|
31
|
-
Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
|
|
32
|
-
['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa']
|
|
33
|
-
)
|
|
34
|
-
copies = home.copies(wallet)
|
|
35
|
-
copies.add(File.read(first.path), 'host-1', 80, 5)
|
|
36
|
-
copies.add(File.read(second.path), 'host-2', 80, 5)
|
|
37
|
-
diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: fake_log).run(
|
|
38
|
-
['diff', wallet.id.to_s]
|
|
39
|
-
)
|
|
40
|
-
assert_includes(diff, '-0001;', diff)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
data/test/commands/test_fetch.rb
DELETED
|
@@ -1,144 +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 'json'
|
|
8
|
-
require 'time'
|
|
9
|
-
require 'webmock/minitest'
|
|
10
|
-
require 'zold/score'
|
|
11
|
-
require_relative '../test__helper'
|
|
12
|
-
require_relative '../fake_home'
|
|
13
|
-
require_relative '../../lib/zold/wallet'
|
|
14
|
-
require_relative '../../lib/zold/wallets'
|
|
15
|
-
require_relative '../../lib/zold/remotes'
|
|
16
|
-
require_relative '../../lib/zold/id'
|
|
17
|
-
require_relative '../../lib/zold/copies'
|
|
18
|
-
require_relative '../../lib/zold/key'
|
|
19
|
-
require_relative '../../lib/zold/commands/fetch'
|
|
20
|
-
|
|
21
|
-
# FETCH test.
|
|
22
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
23
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
24
|
-
# License:: MIT
|
|
25
|
-
class TestFetch < Zold::Test
|
|
26
|
-
def test_fetches_wallet
|
|
27
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
28
|
-
wallet = home.create_wallet
|
|
29
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return(
|
|
30
|
-
status: 200,
|
|
31
|
-
body: {
|
|
32
|
-
score: Zold::Score::ZERO.to_h,
|
|
33
|
-
size: 10_000,
|
|
34
|
-
mtime: Time.now.utc.iso8601
|
|
35
|
-
}.to_json
|
|
36
|
-
)
|
|
37
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}.bin")
|
|
38
|
-
.to_return(status: 200, body: File.read(wallet.path))
|
|
39
|
-
stub_request(:get, "http://localhost:81/wallet/#{wallet.id}").to_return(status: 404)
|
|
40
|
-
remotes = home.remotes
|
|
41
|
-
remotes.add('localhost', 4096)
|
|
42
|
-
remotes.add('localhost', 81)
|
|
43
|
-
copies = home.copies(wallet)
|
|
44
|
-
Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: fake_log).run(
|
|
45
|
-
['fetch', '--tolerate-edges', '--tolerate-quorum=1', '--ignore-score-weakness', wallet.id.to_s]
|
|
46
|
-
)
|
|
47
|
-
assert_equal(1, copies.all.count)
|
|
48
|
-
assert_equal('1', copies.all[0][:name])
|
|
49
|
-
assert_equal(0, copies.all[0][:score])
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_fetches_multiple_wallets
|
|
54
|
-
log = TestLogger.new(fake_log)
|
|
55
|
-
FakeHome.new(log: log).run do |home|
|
|
56
|
-
wallet_a = home.create_wallet
|
|
57
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet_a.id}").to_return(
|
|
58
|
-
status: 200,
|
|
59
|
-
body: {
|
|
60
|
-
score: Zold::Score::ZERO.to_h,
|
|
61
|
-
size: 10_000,
|
|
62
|
-
mtime: Time.now.utc.iso8601
|
|
63
|
-
}.to_json
|
|
64
|
-
)
|
|
65
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet_a.id}.bin")
|
|
66
|
-
.to_return(status: 200, body: File.read(wallet_a.path))
|
|
67
|
-
wallet_b = home.create_wallet
|
|
68
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet_b.id}").to_return(
|
|
69
|
-
status: 200,
|
|
70
|
-
body: {
|
|
71
|
-
score: Zold::Score::ZERO.to_h,
|
|
72
|
-
size: 10_000,
|
|
73
|
-
mtime: Time.now.utc.iso8601
|
|
74
|
-
}.to_json
|
|
75
|
-
)
|
|
76
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet_b.id}.bin")
|
|
77
|
-
.to_return(status: 200, body: File.read(wallet_b.path))
|
|
78
|
-
remotes = home.remotes
|
|
79
|
-
remotes.add('localhost', 4096)
|
|
80
|
-
copies_a = home.copies(wallet_a)
|
|
81
|
-
copies_b = home.copies(wallet_b)
|
|
82
|
-
Zold::Fetch.new(wallets: home.wallets, copies: copies_a.root, remotes: remotes, log: log).run(
|
|
83
|
-
[
|
|
84
|
-
'fetch', '--tolerate-edges', '--tolerate-quorum=1', '--ignore-score-weakness',
|
|
85
|
-
'--threads 2', wallet_a.id.to_s, wallet_b.id.to_s
|
|
86
|
-
]
|
|
87
|
-
)
|
|
88
|
-
assert_equal(1, copies_a.all.count)
|
|
89
|
-
assert_equal('1', copies_a.all[0][:name])
|
|
90
|
-
assert_equal(0, copies_a.all[0][:score])
|
|
91
|
-
assert_equal(1, copies_b.all.count)
|
|
92
|
-
assert_equal('1', copies_b.all[0][:name])
|
|
93
|
-
assert_equal(0, copies_b.all[0][:score])
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def test_fails_when_only_edge_nodes
|
|
98
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
99
|
-
wallet = home.create_wallet
|
|
100
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return(
|
|
101
|
-
status: 200,
|
|
102
|
-
body: {
|
|
103
|
-
score: Zold::Score::ZERO.to_h,
|
|
104
|
-
size: 10_000,
|
|
105
|
-
mtime: Time.now.utc.iso8601
|
|
106
|
-
}.to_json
|
|
107
|
-
)
|
|
108
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}.bin")
|
|
109
|
-
.to_return(status: 200, body: File.read(wallet.path))
|
|
110
|
-
remotes = home.remotes
|
|
111
|
-
remotes.add('localhost', 4096)
|
|
112
|
-
copies = home.copies(wallet)
|
|
113
|
-
assert_raises Zold::Fetch::EdgesOnly do
|
|
114
|
-
Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: fake_log).run(
|
|
115
|
-
['fetch', '--ignore-score-weakness', wallet.id.to_s]
|
|
116
|
-
)
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def test_fails_when_only_one_node
|
|
122
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
123
|
-
wallet = home.create_wallet
|
|
124
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}").to_return(
|
|
125
|
-
status: 200,
|
|
126
|
-
body: {
|
|
127
|
-
score: Zold::Score::ZERO.to_h,
|
|
128
|
-
size: 10_000,
|
|
129
|
-
mtime: Time.now.utc.iso8601
|
|
130
|
-
}.to_json
|
|
131
|
-
)
|
|
132
|
-
stub_request(:get, "http://localhost:4096/wallet/#{wallet.id}.bin")
|
|
133
|
-
.to_return(status: 200, body: File.read(wallet.path))
|
|
134
|
-
remotes = home.remotes
|
|
135
|
-
remotes.add('localhost', 4096)
|
|
136
|
-
copies = home.copies(wallet)
|
|
137
|
-
assert_raises Zold::Fetch::NoQuorum do
|
|
138
|
-
Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: fake_log).run(
|
|
139
|
-
['fetch', '--tolerate-edges', '--ignore-score-weakness', wallet.id.to_s]
|
|
140
|
-
)
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
|
@@ -1,32 +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/amount'
|
|
10
|
-
require_relative '../../lib/zold/key'
|
|
11
|
-
require_relative '../../lib/zold/id'
|
|
12
|
-
require_relative '../../lib/zold/commands/invoice'
|
|
13
|
-
|
|
14
|
-
# INVOICE test.
|
|
15
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
16
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
17
|
-
# License:: MIT
|
|
18
|
-
class TestInvoice < Zold::Test
|
|
19
|
-
def test_generates_invoice
|
|
20
|
-
Dir.mktmpdir do |dir|
|
|
21
|
-
id = Zold::Id.new
|
|
22
|
-
wallets = Zold::Wallets.new(dir)
|
|
23
|
-
wallets.acq(id) do |source|
|
|
24
|
-
source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
|
25
|
-
invoice = Zold::Invoice.new(wallets: wallets, remotes: nil, copies: nil, log: fake_log).run(
|
|
26
|
-
['invoice', id.to_s, '--length=16']
|
|
27
|
-
)
|
|
28
|
-
assert_equal(33, invoice.length)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
data/test/commands/test_list.rb
DELETED
|
@@ -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 'tmpdir'
|
|
7
|
-
require_relative '../test__helper'
|
|
8
|
-
require_relative '../../lib/zold/wallet'
|
|
9
|
-
require_relative '../../lib/zold/wallets'
|
|
10
|
-
require_relative '../../lib/zold/key'
|
|
11
|
-
require_relative '../../lib/zold/id'
|
|
12
|
-
require_relative '../../lib/zold/commands/list'
|
|
13
|
-
|
|
14
|
-
# LIST test.
|
|
15
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
16
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
17
|
-
# License:: MIT
|
|
18
|
-
class TestList < Zold::Test
|
|
19
|
-
def test_lists_wallets_with_balances
|
|
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
|
-
Zold::List.new(wallets: wallets, copies: File.join(dir, 'copies'), log: fake_log).run
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
data/test/commands/test_merge.rb
DELETED
|
@@ -1,106 +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 'webmock/minitest'
|
|
9
|
-
require 'zold/score'
|
|
10
|
-
require 'English'
|
|
11
|
-
require_relative '../test__helper'
|
|
12
|
-
require_relative '../fake_home'
|
|
13
|
-
require_relative '../../lib/zold/wallet'
|
|
14
|
-
require_relative '../../lib/zold/wallets'
|
|
15
|
-
require_relative '../../lib/zold/id'
|
|
16
|
-
require_relative '../../lib/zold/copies'
|
|
17
|
-
require_relative '../../lib/zold/key'
|
|
18
|
-
require_relative '../../lib/zold/patch'
|
|
19
|
-
require_relative '../../lib/zold/commands/merge'
|
|
20
|
-
require_relative '../../lib/zold/commands/pay'
|
|
21
|
-
|
|
22
|
-
# MERGE test.
|
|
23
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
24
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
25
|
-
# License:: MIT
|
|
26
|
-
class TestMerge < Zold::Test
|
|
27
|
-
def test_merges_wallet
|
|
28
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
29
|
-
wallet = home.create_wallet
|
|
30
|
-
Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: fake_log).run(
|
|
31
|
-
['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa']
|
|
32
|
-
)
|
|
33
|
-
copies = home.copies(wallet)
|
|
34
|
-
copies.add(File.read(wallet.path), 'host-1', 80, 5)
|
|
35
|
-
copies.add(File.read(wallet.path), 'host-2', 80, 5)
|
|
36
|
-
modified = Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run(
|
|
37
|
-
['merge', wallet.id.to_s, '--allow-negative-balance']
|
|
38
|
-
)
|
|
39
|
-
assert_empty(modified)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_merges_with_a_broken_copy
|
|
44
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
45
|
-
wallet = home.create_wallet
|
|
46
|
-
copies = home.copies(wallet)
|
|
47
|
-
copies.add(File.read(wallet.path), 'good-host', 80, 5)
|
|
48
|
-
copies.add('some garbage', 'bad-host', 80, 5)
|
|
49
|
-
modified = Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run(
|
|
50
|
-
['merge', wallet.id.to_s]
|
|
51
|
-
)
|
|
52
|
-
assert_empty(modified)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_merges_a_copy_on_top
|
|
57
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
58
|
-
wallet = home.create_wallet(Zold::Id::ROOT)
|
|
59
|
-
copies = home.copies(wallet)
|
|
60
|
-
copies.add(File.read(wallet.path), 'good-host', 80, 5)
|
|
61
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
62
|
-
wallet.sub(Zold::Amount.new(zld: 9.99), "NOPREFIX@#{Zold::Id.new}", key)
|
|
63
|
-
Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run(
|
|
64
|
-
['merge', wallet.id.to_s]
|
|
65
|
-
)
|
|
66
|
-
refute_predicate(wallet.balance, :zero?)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def test_rejects_fake_positives_in_new_wallet
|
|
71
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
72
|
-
main = home.create_wallet
|
|
73
|
-
remote = home.create_wallet
|
|
74
|
-
File.write(remote.path, File.read(main.path))
|
|
75
|
-
remote.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 11.0), 'NOPREFIX', Zold::Id.new, 'fake'))
|
|
76
|
-
copies = home.copies(main)
|
|
77
|
-
copies.add(File.read(remote.path), 'fake-host', 80, 0)
|
|
78
|
-
Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: copies.root, log: fake_log).run(
|
|
79
|
-
['merge', main.id.to_s, '--no-baseline']
|
|
80
|
-
)
|
|
81
|
-
assert_equal(Zold::Amount::ZERO, main.balance)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
BASE_CMD = %w[merge 0123456789abcdef].freeze
|
|
86
|
-
base = 'fixtures/merge'
|
|
87
|
-
Dir.new(base).select { |f| File.directory?(File.join(base, f)) && !f.start_with?('.') }.each do |f|
|
|
88
|
-
method = "test_#{f}"
|
|
89
|
-
define_method(method) do
|
|
90
|
-
Dir.mktmpdir do |dir|
|
|
91
|
-
FileUtils.cp_r(File.join('fixtures/merge', "#{f}/."), dir)
|
|
92
|
-
scores = File.join(dir, "copies/0123456789abcdef/scores#{Zold::Copies::EXT}")
|
|
93
|
-
File.write(scores, File.read(scores).gsub('NOW', Time.now.utc.iso8601))
|
|
94
|
-
FileUtils.cp('fixtures/merge/asserts.rb', dir)
|
|
95
|
-
wallets = Zold::Wallets.new(dir)
|
|
96
|
-
copies = File.join(dir, 'copies')
|
|
97
|
-
remotes = Zold::Remotes.new(file: File.join(dir, 'remotes'))
|
|
98
|
-
cmd = BASE_CMD + File.read(File.join(dir, 'opts')).split("\n")
|
|
99
|
-
Zold::Merge.new(wallets: wallets, remotes: remotes, copies: copies, log: fake_log).run(cmd)
|
|
100
|
-
Dir.chdir(dir) do
|
|
101
|
-
require File.join(dir, 'assert.rb')
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
data/test/commands/test_node.rb
DELETED
|
@@ -1,50 +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_relative '../test__helper'
|
|
9
|
-
require_relative '../../lib/zold/wallet'
|
|
10
|
-
require_relative '../../lib/zold/remotes'
|
|
11
|
-
require_relative '../../lib/zold/id'
|
|
12
|
-
require_relative '../../lib/zold/copies'
|
|
13
|
-
require_relative '../../lib/zold/key'
|
|
14
|
-
require_relative '../../lib/zold/commands/node'
|
|
15
|
-
require_relative '../../lib/zold/commands/fetch'
|
|
16
|
-
require_relative '../../lib/zold/commands/push'
|
|
17
|
-
require_relative '../node/fake_node'
|
|
18
|
-
|
|
19
|
-
# NODE test.
|
|
20
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
21
|
-
# Copyright:: Copyright (c) 2018-2025 Zerocracy
|
|
22
|
-
# License:: MIT
|
|
23
|
-
class TestNode < Zold::Test
|
|
24
|
-
def test_push_and_fetch
|
|
25
|
-
FakeHome.new(log: fake_log).run do |home|
|
|
26
|
-
FakeNode.new(log: fake_log).run do |port|
|
|
27
|
-
wallets = home.wallets
|
|
28
|
-
wallet = home.create_wallet
|
|
29
|
-
remotes = home.remotes
|
|
30
|
-
remotes.add('localhost', port)
|
|
31
|
-
Zold::Push.new(wallets: wallets, remotes: remotes, log: fake_log).run(
|
|
32
|
-
['push', '--ignore-score-weakness', '--tolerate-edges', '--tolerate-quorum=1']
|
|
33
|
-
)
|
|
34
|
-
copies = home.copies(wallet)
|
|
35
|
-
begin
|
|
36
|
-
retries ||= 0
|
|
37
|
-
Zold::Fetch.new(
|
|
38
|
-
wallets: wallets, copies: copies.root,
|
|
39
|
-
remotes: remotes, log: fake_log
|
|
40
|
-
).run(['fetch', '--ignore-score-weakness', '--tolerate-edges', '--tolerate-quorum=1'])
|
|
41
|
-
rescue StandardError => _e
|
|
42
|
-
sleep 1
|
|
43
|
-
retry if (retries += 1) < 3
|
|
44
|
-
end
|
|
45
|
-
assert_equal(1, copies.all.count)
|
|
46
|
-
assert_equal('1', copies.all[0][:name])
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|