zold 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bin/zold +9 -6
- data/features/gem_package.feature +1 -1
- data/features/step_definitions/steps.rb +2 -2
- data/fixtures/merge/into-no-wallet/assert.rb +1 -1
- data/fixtures/merge/random-expenses/assert.rb +1 -1
- data/fixtures/merge/simple-case/assert.rb +1 -1
- data/lib/zold/age.rb +16 -8
- data/lib/zold/amount.rb +4 -2
- data/lib/zold/cached_wallets.rb +5 -6
- data/lib/zold/commands/clean.rb +15 -8
- data/lib/zold/commands/diff.rb +3 -3
- data/lib/zold/commands/fetch.rb +4 -4
- data/lib/zold/commands/list.rb +5 -4
- data/lib/zold/commands/merge.rb +2 -1
- data/lib/zold/commands/node.rb +14 -12
- data/lib/zold/commands/propagate.rb +2 -2
- data/lib/zold/commands/push.rb +3 -3
- data/lib/zold/commands/remove.rb +4 -1
- data/lib/zold/commands/routines/reconnect.rb +1 -0
- data/lib/zold/copies.rb +13 -14
- data/lib/zold/dir_items.rb +44 -0
- data/lib/zold/head.rb +1 -1
- data/lib/zold/key.rb +2 -2
- data/lib/zold/log.rb +2 -0
- data/lib/zold/node/async_entrance.rb +38 -28
- data/lib/zold/node/entrance.rb +4 -11
- data/lib/zold/node/farm.rb +9 -9
- data/lib/zold/node/front.rb +40 -25
- data/lib/zold/node/nodup_entrance.rb +4 -4
- data/lib/zold/node/safe_entrance.rb +2 -2
- data/lib/zold/node/spread_entrance.rb +5 -9
- data/lib/zold/node/sync_entrance.rb +2 -23
- data/lib/zold/patch.rb +2 -2
- data/lib/zold/remotes.rb +10 -6
- data/lib/zold/sync_wallets.rb +3 -22
- data/lib/zold/tree_wallets.rb +11 -6
- data/lib/zold/txns.rb +1 -1
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +14 -5
- data/lib/zold/wallets.rb +5 -4
- data/test/commands/routines/test_spread.rb +1 -1
- data/test/commands/test_alias.rb +4 -4
- data/test/commands/test_clean.rb +14 -1
- data/test/commands/test_create.rb +2 -2
- data/test/commands/test_diff.rb +5 -5
- data/test/commands/test_fetch.rb +2 -2
- data/test/commands/test_merge.rb +19 -19
- data/test/commands/test_node.rb +1 -1
- data/test/commands/test_pay.rb +7 -6
- data/test/commands/test_propagate.rb +2 -1
- data/test/commands/test_pull.rb +1 -1
- data/test/commands/test_push.rb +1 -1
- data/test/commands/test_remove.rb +57 -0
- data/test/commands/test_taxes.rb +1 -1
- data/test/fake_home.rb +11 -8
- data/test/node/fake_node.rb +2 -2
- data/test/node/test_async_entrance.rb +24 -8
- data/test/node/test_emission.rb +2 -2
- data/test/node/test_entrance.rb +8 -6
- data/test/node/test_farm.rb +1 -1
- data/test/node/test_front.rb +42 -33
- data/test/node/test_nodup_entrance.rb +2 -2
- data/test/node/test_safe_entrance.rb +5 -5
- data/test/node/test_spread_entrance.rb +3 -3
- data/test/node/test_sync_entrance.rb +1 -1
- data/test/test__helper.rb +3 -29
- data/test/test_cached_wallets.rb +1 -1
- data/test/test_copies.rb +4 -2
- data/test/test_dir_items.rb +88 -0
- data/test/test_key.rb +2 -2
- data/test/test_log.rb +38 -0
- data/test/test_patch.rb +11 -11
- data/test/test_prefixes.rb +1 -1
- data/test/test_remotes.rb +12 -6
- data/test/test_sync_wallets.rb +6 -6
- data/test/test_tax.rb +4 -4
- data/test/test_tree_wallets.rb +16 -2
- data/test/test_wallet.rb +26 -26
- data/test/test_wallets.rb +5 -2
- data/test/test_zold.rb +2 -2
- data/test/upgrades/test_protocol_up.rb +1 -1
- data/upgrades/move_wallets_into_tree.rb +1 -1
- data/upgrades/protocol_up.rb +3 -3
- data/upgrades/rename_foreign_wallets.rb +1 -1
- data/zold.gemspec +27 -25
- metadata +91 -56
data/test/commands/test_clean.rb
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
require 'minitest/autorun'
|
24
24
|
require 'time'
|
25
|
+
require 'threads'
|
25
26
|
require_relative '../fake_home'
|
26
27
|
require_relative '../test__helper'
|
27
28
|
require_relative '../../lib/zold/copies'
|
@@ -33,7 +34,7 @@ require_relative '../../lib/zold/commands/clean'
|
|
33
34
|
# License:: MIT
|
34
35
|
class TestClean < Minitest::Test
|
35
36
|
def test_cleans_copies
|
36
|
-
FakeHome.new.run do |home|
|
37
|
+
FakeHome.new(log: test_log).run do |home|
|
37
38
|
wallet = home.create_wallet
|
38
39
|
copies = home.copies(wallet)
|
39
40
|
copies.add('a1', 'host-1', 80, 1, Time.now - 26 * 60 * 60)
|
@@ -42,4 +43,16 @@ class TestClean < Minitest::Test
|
|
42
43
|
assert(copies.all.empty?)
|
43
44
|
end
|
44
45
|
end
|
46
|
+
|
47
|
+
def test_cleans_copies_in_threads
|
48
|
+
FakeHome.new(log: test_log).run do |home|
|
49
|
+
wallet = home.create_wallet
|
50
|
+
copies = home.copies(wallet)
|
51
|
+
copies.add(IO.read(wallet.path), 'host-2', 80, 2, Time.now)
|
52
|
+
Threads.new(20).assert do
|
53
|
+
Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean'])
|
54
|
+
end
|
55
|
+
assert_equal(1, copies.all.count)
|
56
|
+
end
|
57
|
+
end
|
45
58
|
end
|
@@ -41,8 +41,8 @@ class TestCreate < Minitest::Test
|
|
41
41
|
wallets.find(id) do |wallet|
|
42
42
|
assert(wallet.balance.zero?)
|
43
43
|
assert(
|
44
|
-
File.exist?(File.join(dir, "#{wallet.id}#{Zold::Wallet::
|
45
|
-
"Wallet file not found: #{wallet.id}#{Zold::Wallet::
|
44
|
+
File.exist?(File.join(dir, "#{wallet.id}#{Zold::Wallet::EXT}")),
|
45
|
+
"Wallet file not found: #{wallet.id}#{Zold::Wallet::EXT}"
|
46
46
|
)
|
47
47
|
end
|
48
48
|
end
|
data/test/commands/test_diff.rb
CHANGED
@@ -40,18 +40,18 @@ require_relative '../../lib/zold/commands/diff'
|
|
40
40
|
# License:: MIT
|
41
41
|
class TestDiff < Minitest::Test
|
42
42
|
def test_diff_with_copies
|
43
|
-
FakeHome.new.run do |home|
|
43
|
+
FakeHome.new(log: test_log).run do |home|
|
44
44
|
wallet = home.create_wallet
|
45
45
|
first = home.create_wallet
|
46
|
-
|
46
|
+
IO.write(first.path, IO.read(wallet.path))
|
47
47
|
second = home.create_wallet
|
48
|
-
|
48
|
+
IO.write(second.path, IO.read(wallet.path))
|
49
49
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
50
50
|
['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa']
|
51
51
|
)
|
52
52
|
copies = home.copies(wallet)
|
53
|
-
copies.add(
|
54
|
-
copies.add(
|
53
|
+
copies.add(IO.read(first.path), 'host-1', 80, 5)
|
54
|
+
copies.add(IO.read(second.path), 'host-2', 80, 5)
|
55
55
|
diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
56
56
|
['diff', wallet.id.to_s]
|
57
57
|
)
|
data/test/commands/test_fetch.rb
CHANGED
@@ -42,13 +42,13 @@ require_relative '../../lib/zold/commands/fetch'
|
|
42
42
|
# License:: MIT
|
43
43
|
class TestFetch < Minitest::Test
|
44
44
|
def test_fetches_wallet
|
45
|
-
FakeHome.new.run do |home|
|
45
|
+
FakeHome.new(log: test_log).run do |home|
|
46
46
|
wallet = home.create_wallet
|
47
47
|
stub_request(:get, "http://localhost:80/wallet/#{wallet.id}").to_return(
|
48
48
|
status: 200,
|
49
49
|
body: {
|
50
50
|
'score': Zold::Score::ZERO.to_h,
|
51
|
-
'body':
|
51
|
+
'body': IO.read(wallet.path),
|
52
52
|
'mtime': Time.now.utc.iso8601
|
53
53
|
}.to_json
|
54
54
|
)
|
data/test/commands/test_merge.rb
CHANGED
@@ -42,18 +42,18 @@ require_relative '../../lib/zold/commands/pay'
|
|
42
42
|
# License:: MIT
|
43
43
|
class TestMerge < Minitest::Test
|
44
44
|
def test_merges_wallet
|
45
|
-
FakeHome.new.run do |home|
|
45
|
+
FakeHome.new(log: test_log).run do |home|
|
46
46
|
wallet = home.create_wallet
|
47
47
|
first = home.create_wallet
|
48
|
-
|
48
|
+
IO.write(first.path, IO.read(wallet.path))
|
49
49
|
second = home.create_wallet
|
50
|
-
|
50
|
+
IO.write(second.path, IO.read(wallet.path))
|
51
51
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
52
52
|
['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa']
|
53
53
|
)
|
54
54
|
copies = home.copies(wallet)
|
55
|
-
copies.add(
|
56
|
-
copies.add(
|
55
|
+
copies.add(IO.read(first.path), 'host-1', 80, 5)
|
56
|
+
copies.add(IO.read(second.path), 'host-2', 80, 5)
|
57
57
|
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
58
58
|
['merge', wallet.id.to_s]
|
59
59
|
)
|
@@ -63,18 +63,18 @@ class TestMerge < Minitest::Test
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_merges_into_empty_wallet
|
66
|
-
FakeHome.new.run do |home|
|
66
|
+
FakeHome.new(log: test_log).run do |home|
|
67
67
|
wallet = home.create_wallet
|
68
68
|
first = home.create_wallet
|
69
|
-
|
69
|
+
IO.write(first.path, IO.read(wallet.path))
|
70
70
|
second = home.create_wallet
|
71
|
-
|
71
|
+
IO.write(second.path, IO.read(wallet.path))
|
72
72
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
73
73
|
['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa']
|
74
74
|
)
|
75
75
|
copies = home.copies(wallet)
|
76
|
-
copies.add(
|
77
|
-
copies.add(
|
76
|
+
copies.add(IO.read(first.path), 'host-1', 80, 5)
|
77
|
+
copies.add(IO.read(second.path), 'host-2', 80, 5)
|
78
78
|
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
79
79
|
['merge', wallet.id.to_s]
|
80
80
|
)
|
@@ -84,10 +84,10 @@ class TestMerge < Minitest::Test
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_merges_with_a_broken_copy
|
87
|
-
FakeHome.new.run do |home|
|
87
|
+
FakeHome.new(log: test_log).run do |home|
|
88
88
|
wallet = home.create_wallet
|
89
89
|
copies = home.copies(wallet)
|
90
|
-
copies.add(
|
90
|
+
copies.add(IO.read(wallet.path), 'good-host', 80, 5)
|
91
91
|
copies.add('some garbage', 'bad-host', 80, 5)
|
92
92
|
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
93
93
|
['merge', wallet.id.to_s]
|
@@ -97,10 +97,10 @@ class TestMerge < Minitest::Test
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_merges_a_copy_on_top
|
100
|
-
FakeHome.new.run do |home|
|
100
|
+
FakeHome.new(log: test_log).run do |home|
|
101
101
|
wallet = home.create_wallet(Zold::Id::ROOT)
|
102
102
|
copies = home.copies(wallet)
|
103
|
-
copies.add(
|
103
|
+
copies.add(IO.read(wallet.path), 'good-host', 80, 5)
|
104
104
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
105
105
|
wallet.sub(Zold::Amount.new(zld: 9.99), "NOPREFIX@#{Zold::Id.new}", key)
|
106
106
|
Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
@@ -111,13 +111,13 @@ class TestMerge < Minitest::Test
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def test_rejects_fake_positives_in_new_wallet
|
114
|
-
FakeHome.new.run do |home|
|
114
|
+
FakeHome.new(log: test_log).run do |home|
|
115
115
|
main = home.create_wallet
|
116
116
|
remote = home.create_wallet
|
117
|
-
|
117
|
+
IO.write(remote.path, IO.read(main.path))
|
118
118
|
remote.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 11.0), 'NOPREFIX', Zold::Id.new, 'fake'))
|
119
119
|
copies = home.copies(main)
|
120
|
-
copies.add(
|
120
|
+
copies.add(IO.read(remote.path), 'fake-host', 80, 0)
|
121
121
|
Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: test_log).run(
|
122
122
|
['merge', main.id.to_s, '--no-baseline']
|
123
123
|
)
|
@@ -126,7 +126,7 @@ class TestMerge < Minitest::Test
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def test_removes_negative_fakes
|
129
|
-
FakeHome.new.run do |home|
|
129
|
+
FakeHome.new(log: test_log).run do |home|
|
130
130
|
wallet = home.create_wallet
|
131
131
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
132
132
|
wallet.sub(Zold::Amount.new(zld: 9.99), "NOPREFIX@#{Zold::Id.new}", key)
|
@@ -143,7 +143,7 @@ class TestMerge < Minitest::Test
|
|
143
143
|
Dir.mktmpdir do |dir|
|
144
144
|
FileUtils.cp_r(File.join('fixtures/merge', "#{f}/."), dir)
|
145
145
|
scores = File.join(dir, "copies/0123456789abcdef/scores#{Zold::Copies::EXT}")
|
146
|
-
|
146
|
+
IO.write(scores, IO.read(scores).gsub(/NOW/, Time.now.utc.iso8601))
|
147
147
|
FileUtils.cp('fixtures/merge/asserts.rb', dir)
|
148
148
|
wallets = Zold::Wallets.new(dir)
|
149
149
|
copies = File.join(dir, 'copies')
|
data/test/commands/test_node.rb
CHANGED
@@ -44,7 +44,7 @@ class TestNode < Minitest::Test
|
|
44
44
|
# are always working
|
45
45
|
def test_push_and_fetch
|
46
46
|
skip
|
47
|
-
FakeHome.new.run do |home|
|
47
|
+
FakeHome.new(log: test_log).run do |home|
|
48
48
|
FakeNode.new(log: test_log).run do |port|
|
49
49
|
wallets = home.wallets
|
50
50
|
wallet = home.create_wallet
|
data/test/commands/test_pay.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'minitest/autorun'
|
24
|
+
require 'threads'
|
24
25
|
require_relative '../test__helper'
|
25
26
|
require_relative '../fake_home'
|
26
27
|
require_relative '../../lib/zold/wallets'
|
@@ -35,7 +36,7 @@ require_relative '../../lib/zold/commands/pay'
|
|
35
36
|
# License:: MIT
|
36
37
|
class TestPay < Minitest::Test
|
37
38
|
def test_sends_from_wallet_to_wallet
|
38
|
-
FakeHome.new.run do |home|
|
39
|
+
FakeHome.new(log: test_log).run do |home|
|
39
40
|
source = home.create_wallet
|
40
41
|
target = home.create_wallet
|
41
42
|
amount = Zold::Amount.new(zld: 14.95)
|
@@ -50,10 +51,10 @@ class TestPay < Minitest::Test
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def test_pay_in_many_threads
|
53
|
-
FakeHome.new.run do |home|
|
54
|
+
FakeHome.new(log: test_log).run do |home|
|
54
55
|
wallet = home.create_wallet
|
55
56
|
amount = Zold::Amount.new(zld: 2.0)
|
56
|
-
|
57
|
+
Threads.new(10).assert do
|
57
58
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
58
59
|
[
|
59
60
|
'pay', '--force', '--private-key=fixtures/id_rsa',
|
@@ -66,7 +67,7 @@ class TestPay < Minitest::Test
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def test_sends_from_root_wallet
|
69
|
-
FakeHome.new.run do |home|
|
70
|
+
FakeHome.new(log: test_log).run do |home|
|
70
71
|
source = home.create_wallet(Zold::Id::ROOT)
|
71
72
|
target = home.create_wallet
|
72
73
|
amount = Zold::Amount.new(zld: 14.95)
|
@@ -81,7 +82,7 @@ class TestPay < Minitest::Test
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def test_sends_from_normal_wallet
|
84
|
-
FakeHome.new.run do |home|
|
85
|
+
FakeHome.new(log: test_log).run do |home|
|
85
86
|
source = home.create_wallet
|
86
87
|
target = home.create_wallet
|
87
88
|
amount = Zold::Amount.new(zld: 14.95)
|
@@ -102,7 +103,7 @@ class TestPay < Minitest::Test
|
|
102
103
|
end
|
103
104
|
|
104
105
|
def test_notifies_about_tax_status
|
105
|
-
FakeHome.new.run do |home|
|
106
|
+
FakeHome.new(log: test_log).run do |home|
|
106
107
|
source = home.create_wallet
|
107
108
|
target = home.create_wallet
|
108
109
|
amount = Zold::Amount.new(zld: 14.95)
|
@@ -33,7 +33,7 @@ require_relative '../../lib/zold/commands/pay'
|
|
33
33
|
# License:: MIT
|
34
34
|
class TestPropagate < Minitest::Test
|
35
35
|
def test_propagates_wallet
|
36
|
-
FakeHome.new.run do |home|
|
36
|
+
FakeHome.new(log: test_log).run do |home|
|
37
37
|
wallet = home.create_wallet
|
38
38
|
friend = home.create_wallet
|
39
39
|
amount = Zold::Amount.new(zld: 14.95)
|
@@ -44,6 +44,7 @@ class TestPropagate < Minitest::Test
|
|
44
44
|
['merge', wallet.id.to_s]
|
45
45
|
)
|
46
46
|
assert(amount, friend.balance)
|
47
|
+
assert(1, friend.txns.count)
|
47
48
|
assert('', friend.txns[0].sign)
|
48
49
|
end
|
49
50
|
end
|
data/test/commands/test_pull.rb
CHANGED
@@ -34,7 +34,7 @@ require_relative '../../lib/zold/commands/pull'
|
|
34
34
|
# License:: MIT
|
35
35
|
class TestPull < Minitest::Test
|
36
36
|
def test_pull_wallet
|
37
|
-
FakeHome.new.run do |home|
|
37
|
+
FakeHome.new(log: test_log).run do |home|
|
38
38
|
remotes = home.remotes
|
39
39
|
remotes.add('localhost', 80)
|
40
40
|
json = home.create_wallet_json
|
data/test/commands/test_push.rb
CHANGED
@@ -37,7 +37,7 @@ require_relative '../../lib/zold/commands/push'
|
|
37
37
|
# License:: MIT
|
38
38
|
class TestPush < Minitest::Test
|
39
39
|
def test_pushes_wallet
|
40
|
-
FakeHome.new.run do |home|
|
40
|
+
FakeHome.new(log: test_log).run do |home|
|
41
41
|
wallet = home.create_wallet
|
42
42
|
remotes = home.remotes
|
43
43
|
remotes.add('localhost', 80)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'minitest/autorun'
|
24
|
+
require_relative '../fake_home'
|
25
|
+
require_relative '../test__helper'
|
26
|
+
require_relative '../../lib/zold/commands/remove'
|
27
|
+
|
28
|
+
# REMOVE test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class TestRemove < Minitest::Test
|
33
|
+
def test_removes_one_wallet
|
34
|
+
FakeHome.new(log: test_log).run do |home|
|
35
|
+
wallet = home.create_wallet
|
36
|
+
assert_equal(1, home.wallets.all.count)
|
37
|
+
Zold::Remove.new(wallets: home.wallets, log: test_log).run(['remove', wallet.id.to_s])
|
38
|
+
assert(home.wallets.all.empty?)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_removes_wallets
|
43
|
+
FakeHome.new(log: test_log).run do |home|
|
44
|
+
home.create_wallet
|
45
|
+
home.create_wallet
|
46
|
+
Zold::Remove.new(wallets: home.wallets, log: test_log).run(['remove'])
|
47
|
+
assert(home.wallets.all.empty?)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_removes_no_wallets
|
52
|
+
FakeHome.new(log: test_log).run do |home|
|
53
|
+
Zold::Remove.new(wallets: home.wallets, log: test_log).run(['remove'])
|
54
|
+
assert(home.wallets.all.empty?)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/test/commands/test_taxes.rb
CHANGED
@@ -38,7 +38,7 @@ require_relative '../../lib/zold/commands/taxes'
|
|
38
38
|
# License:: MIT
|
39
39
|
class TestTaxes < Minitest::Test
|
40
40
|
def test_pays_taxes
|
41
|
-
FakeHome.new.run do |home|
|
41
|
+
FakeHome.new(log: test_log).run do |home|
|
42
42
|
wallets = home.wallets
|
43
43
|
wallet = home.create_wallet
|
44
44
|
wallet.add(
|
data/test/fake_home.rb
CHANGED
@@ -21,10 +21,12 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'tmpdir'
|
24
|
+
require_relative '../lib/zold/log'
|
24
25
|
require_relative '../lib/zold/id'
|
25
26
|
require_relative '../lib/zold/wallet'
|
26
27
|
require_relative '../lib/zold/wallets'
|
27
28
|
require_relative '../lib/zold/sync_wallets'
|
29
|
+
require_relative '../lib/zold/cached_wallets'
|
28
30
|
require_relative '../lib/zold/key'
|
29
31
|
require_relative '../lib/zold/version'
|
30
32
|
require_relative '../lib/zold/remotes'
|
@@ -35,26 +37,27 @@ require_relative '../lib/zold/remotes'
|
|
35
37
|
# License:: MIT
|
36
38
|
class FakeHome
|
37
39
|
attr_reader :dir
|
38
|
-
def initialize(dir = __dir__)
|
40
|
+
def initialize(dir = __dir__, log: Zold::Log::Quiet.new)
|
39
41
|
@dir = dir
|
42
|
+
@log = log
|
40
43
|
end
|
41
44
|
|
42
45
|
def run
|
43
46
|
Dir.mktmpdir do |dir|
|
44
|
-
FileUtils.copy(File.join(__dir__, '../fixtures/id_rsa'), File.join(dir, 'id_rsa'))
|
45
|
-
yield FakeHome.new(dir)
|
47
|
+
FileUtils.copy(File.expand_path(File.join(__dir__, '../fixtures/id_rsa')), File.join(dir, 'id_rsa'))
|
48
|
+
yield FakeHome.new(dir, log: @log)
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
49
52
|
def wallets
|
50
|
-
Zold::SyncWallets.new(Zold::Wallets.new(@dir),
|
53
|
+
Zold::SyncWallets.new(Zold::CachedWallets.new(Zold::Wallets.new(@dir)), log: @log)
|
51
54
|
end
|
52
55
|
|
53
56
|
def create_wallet(id = Zold::Id.new, dir = @dir)
|
54
|
-
target = Zold::Wallet.new(File.join(dir, id.to_s))
|
57
|
+
target = Zold::Wallet.new(File.join(dir, id.to_s + Zold::Wallet::EXT))
|
55
58
|
wallets.find(id) do |w|
|
56
|
-
w.init(id, Zold::Key.new(file: File.join(__dir__, '../fixtures/id_rsa.pub')))
|
57
|
-
|
59
|
+
w.init(id, Zold::Key.new(file: File.expand_path(File.join(__dir__, '../fixtures/id_rsa.pub'))))
|
60
|
+
IO.write(target.path, IO.read(w.path))
|
58
61
|
end
|
59
62
|
target
|
60
63
|
end
|
@@ -73,7 +76,7 @@ class FakeHome
|
|
73
76
|
mtime: wallet.mtime.utc.iso8601,
|
74
77
|
digest: wallet.digest,
|
75
78
|
balance: wallet.balance.to_i,
|
76
|
-
body:
|
79
|
+
body: IO.read(wallet.path)
|
77
80
|
}.to_json
|
78
81
|
end
|
79
82
|
end
|
data/test/node/fake_node.rb
CHANGED
@@ -38,9 +38,9 @@ class FakeNode
|
|
38
38
|
@log = log
|
39
39
|
end
|
40
40
|
|
41
|
-
def run(args = ['--standalone'])
|
41
|
+
def run(args = ['--standalone', '--no-metronome'])
|
42
42
|
WebMock.allow_net_connect!
|
43
|
-
FakeHome.new.run do |home|
|
43
|
+
FakeHome.new(log: @log).run do |home|
|
44
44
|
RandomPort::Pool::SINGLETON.acquire do |port|
|
45
45
|
node = Thread.new do
|
46
46
|
Zold::VerboseThread.new(@log).run do
|
@@ -21,6 +21,7 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'minitest/autorun'
|
24
|
+
require 'threads'
|
24
25
|
require_relative '../fake_home'
|
25
26
|
require_relative '../test__helper'
|
26
27
|
require_relative '../../lib/zold/id'
|
@@ -33,33 +34,48 @@ require_relative 'fake_entrance'
|
|
33
34
|
# License:: MIT
|
34
35
|
class TestAsyncEntrance < Minitest::Test
|
35
36
|
def test_renders_json
|
36
|
-
FakeHome.new.run do |home|
|
37
|
+
FakeHome.new(log: test_log).run do |home|
|
37
38
|
Zold::AsyncEntrance.new(FakeEntrance.new, home.dir, log: test_log).start do |e|
|
38
39
|
assert_equal(true, e.to_json[:'pool.running'])
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
def
|
44
|
-
FakeHome.new.run do |home|
|
44
|
+
def test_sends_through_once
|
45
|
+
FakeHome.new(log: test_log).run do |home|
|
45
46
|
wallet = home.create_wallet
|
46
47
|
amount = Zold::Amount.new(zld: 39.99)
|
47
48
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
48
49
|
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
49
50
|
basic = CountingEntrance.new
|
50
51
|
Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log).start do |e|
|
51
|
-
|
52
|
-
assert_equal_wait(
|
53
|
-
|
52
|
+
e.push(wallet.id, IO.read(wallet.path))
|
53
|
+
assert_equal_wait(1) { basic.count }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_sends_through
|
59
|
+
FakeHome.new(log: test_log).run do |home|
|
60
|
+
basic = CountingEntrance.new
|
61
|
+
Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log).start do |e|
|
62
|
+
Threads.new(20).assert do
|
63
|
+
wallet = home.create_wallet
|
64
|
+
amount = Zold::Amount.new(zld: 39.99)
|
65
|
+
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
66
|
+
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
67
|
+
5.times { e.push(wallet.id, IO.read(wallet.path)) }
|
68
|
+
end
|
54
69
|
end
|
70
|
+
assert_equal_wait(true) { basic.count >= 20 }
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
58
74
|
def test_handles_broken_entrance_gracefully
|
59
|
-
FakeHome.new.run do |home|
|
75
|
+
FakeHome.new(log: test_log).run do |home|
|
60
76
|
wallet = home.create_wallet
|
61
77
|
Zold::AsyncEntrance.new(BrokenEntrance.new, home.dir, log: test_log).start do |e|
|
62
|
-
e.push(wallet.id,
|
78
|
+
e.push(wallet.id, IO.read(wallet.path))
|
63
79
|
end
|
64
80
|
end
|
65
81
|
end
|