zold 0.14.28 → 0.14.29

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/appveyor.yml +9 -8
  4. data/bin/zold +8 -4
  5. data/fixtures/scripts/distribute-wallet.sh +4 -3
  6. data/lib/zold/commands/create.rb +6 -5
  7. data/lib/zold/commands/diff.rb +5 -7
  8. data/lib/zold/commands/fetch.rb +3 -2
  9. data/lib/zold/commands/invoice.rb +4 -3
  10. data/lib/zold/commands/merge.rb +14 -13
  11. data/lib/zold/commands/node.rb +40 -17
  12. data/lib/zold/commands/pay.rb +16 -9
  13. data/lib/zold/commands/propagate.rb +24 -21
  14. data/lib/zold/commands/push.rb +23 -22
  15. data/lib/zold/commands/remote.rb +16 -23
  16. data/lib/zold/commands/routines/reconnect.rb +5 -1
  17. data/lib/zold/commands/show.rb +3 -1
  18. data/lib/zold/commands/taxes.rb +9 -3
  19. data/lib/zold/copies.rb +2 -2
  20. data/lib/zold/hungry_wallets.rb +21 -1
  21. data/lib/zold/node/async_entrance.rb +5 -6
  22. data/lib/zold/node/entrance.rb +3 -2
  23. data/lib/zold/node/front.rb +119 -88
  24. data/lib/zold/node/nodup_entrance.rb +3 -2
  25. data/lib/zold/node/sync_entrance.rb +81 -0
  26. data/lib/zold/node/trace.rb +75 -0
  27. data/lib/zold/patch.rb +2 -3
  28. data/lib/zold/remotes.rb +1 -1
  29. data/lib/zold/sync_wallets.rb +78 -0
  30. data/lib/zold/version.rb +1 -1
  31. data/lib/zold/wallet.rb +1 -0
  32. data/lib/zold/wallets.rb +5 -5
  33. data/test/commands/test_create.rb +9 -6
  34. data/test/commands/test_diff.rb +1 -1
  35. data/test/commands/test_invoice.rb +7 -6
  36. data/test/commands/test_list.rb +4 -3
  37. data/test/commands/test_merge.rb +2 -2
  38. data/test/commands/test_pull.rb +3 -1
  39. data/test/commands/test_remote.rb +4 -0
  40. data/test/commands/test_show.rb +5 -4
  41. data/test/fake_home.rb +2 -1
  42. data/test/node/test_async_entrance.rb +1 -1
  43. data/test/node/test_farm.rb +2 -2
  44. data/test/node/test_front.rb +63 -17
  45. data/test/node/test_sync_entrance.rb +41 -0
  46. data/test/node/test_trace.rb +36 -0
  47. data/test/test__helper.rb +18 -0
  48. data/test/test_copies.rb +1 -1
  49. data/test/test_metronome.rb +2 -3
  50. data/test/test_patch.rb +1 -1
  51. data/test/test_remotes.rb +3 -3
  52. data/test/test_sync_wallets.rb +69 -0
  53. data/test/test_upgrades.rb +0 -0
  54. data/test/test_wallet.rb +1 -1
  55. data/test/test_wallets.rb +14 -10
  56. data/test/test_zold.rb +2 -2
  57. data/test/upgrades/test_protocol_up.rb +3 -2
  58. data/zold.gemspec +1 -0
  59. metadata +25 -2
@@ -49,7 +49,7 @@ class TestAsyncEntrance < Minitest::Test
49
49
  basic = CountingEntrance.new
50
50
  Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log).start do |e|
51
51
  5.times { e.push(wallet.id, File.read(wallet.path)) }
52
- sleep 0.1 while basic.count.zero?
52
+ assert_equal_wait(false) { basic.count.zero? }
53
53
  assert(!basic.count.zero?)
54
54
  end
55
55
  end
@@ -41,7 +41,7 @@ class FarmTest < Minitest::Test
41
41
  Dir.mktmpdir do |dir|
42
42
  farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
43
43
  farm.start('localhost', 80, threads: 4, strength: 2) do
44
- sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
44
+ assert_wait { !farm.best.empty? && !farm.best[0].value.zero? }
45
45
  count = 0
46
46
  100.times { count += farm.to_json[:best].length }
47
47
  assert(count.positive?)
@@ -62,7 +62,7 @@ class FarmTest < Minitest::Test
62
62
  Dir.mktmpdir do |dir|
63
63
  farm = Zold::Farm.new('NOPREFIX1@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
64
64
  farm.start('localhost', 80, threads: 4, strength: 3) do
65
- sleep 0.1 while farm.best.empty? || farm.best[0].value < 3
65
+ assert_wait { !farm.best.empty? && farm.best[0].value >= 3 }
66
66
  score = farm.best[0]
67
67
  assert(!score.expired?)
68
68
  assert(score.value >= 3)
@@ -42,7 +42,8 @@ class FrontTest < Minitest::Test
42
42
  '/version',
43
43
  '/farm',
44
44
  '/metronome',
45
- '/score'
45
+ '/score',
46
+ '/trace'
46
47
  ],
47
48
  '404' => [
48
49
  '/this-is-absent',
@@ -76,12 +77,11 @@ class FrontTest < Minitest::Test
76
77
  FakeHome.new.run do |home|
77
78
  FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--standalone']) do |port|
78
79
  wallet = home.create_wallet
79
- test_log.debug("Wallet created: #{wallet.id}")
80
- home = "http://localhost:#{port}"
81
- response = Zold::Http.new(uri: "#{home}/wallet/#{wallet.id}?sync=true", score: nil)
80
+ base = "http://localhost:#{port}"
81
+ response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil)
82
82
  .put(File.read(wallet.path))
83
83
  assert_equal('200', response.code, response.body)
84
- sleep 0.1 until Zold::Http.new(uri: "#{home}/wallet/#{wallet.id}", score: nil).get.code == '200'
84
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
85
85
  [
86
86
  "/wallet/#{wallet.id}.txt",
87
87
  "/wallet/#{wallet.id}.json",
@@ -92,27 +92,24 @@ class FrontTest < Minitest::Test
92
92
  "/wallet/#{wallet.id}.bin",
93
93
  "/wallet/#{wallet.id}/copies"
94
94
  ].each do |u|
95
- res = Zold::Http.new(uri: "#{home}#{u}", score: nil).get
96
- assert_equal('200', res.code, res.body)
95
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}#{u}", score: nil).get.code }
97
96
  end
98
97
  end
99
98
  end
100
99
  end
101
100
 
102
- # @todo #239:30min This tests is skipped since it crashes sporadically.
103
- # Let's investigate and make it stable. I don't really know what's going
104
- # on, but suspect some collision between threads:
105
- # http://www.rultor.com/t/14940-397702802
106
101
  def test_pushes_twice
107
- skip
108
102
  FakeNode.new(log: test_log).run do |port|
109
103
  FakeHome.new.run do |home|
110
104
  wallet = home.create_wallet
111
- response = Zold::Http.new(uri: "http://localhost:#{port}/wallet/#{wallet.id}?sync=true", score: nil)
112
- .put(File.read(wallet.path))
113
- assert_equal('200', response.code, response.body)
105
+ base = "http://localhost:#{port}"
106
+ assert_equal(
107
+ '200',
108
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(File.read(wallet.path)).code
109
+ )
110
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
114
111
  3.times do
115
- r = Zold::Http.new(uri: "http://localhost:#{port}/wallet/#{wallet.id}?sync=true", score: nil)
112
+ r = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil)
116
113
  .put(File.read(wallet.path))
117
114
  assert_equal('304', r.code, r.body)
118
115
  end
@@ -120,6 +117,34 @@ class FrontTest < Minitest::Test
120
117
  end
121
118
  end
122
119
 
120
+ def test_pushes_many_wallets
121
+ FakeNode.new(log: test_log).run do |port|
122
+ base = "http://localhost:#{port}"
123
+ FakeHome.new.run do |home|
124
+ threads = 20
125
+ done = Concurrent::AtomicFixnum.new
126
+ pool = Concurrent::FixedThreadPool.new(threads)
127
+ latch = Concurrent::CountDownLatch.new(1)
128
+ threads.times do |i|
129
+ pool.post do
130
+ Thread.current.name = "thread-#{i}"
131
+ Zold::VerboseThread.new(test_log).run(true) do
132
+ latch.wait(10)
133
+ wallet = home.create_wallet
134
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(File.read(wallet.path))
135
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
136
+ done.increment
137
+ end
138
+ end
139
+ end
140
+ latch.count_down
141
+ pool.shutdown
142
+ pool.wait_for_termination
143
+ assert_equal(threads, done.value)
144
+ end
145
+ end
146
+ end
147
+
123
148
  def test_different_logos
124
149
  {
125
150
  '0' => 'https://www.zold.io/images/logo-red.png',
@@ -257,6 +282,27 @@ class FrontTest < Minitest::Test
257
282
  Zold::Http.new(uri: uri, score: nil).get
258
283
  end
259
284
  end
260
- assert_equal('--alias should be a 4 to 16 char long alphanumeric string', exception.message)
285
+ assert(exception.message.include?('should be a 4 to 16 char long alphanumeric string'))
286
+ end
287
+
288
+ def test_push_fetch_in_multiple_threads
289
+ key = Zold::Key.new(text: File.read('fixtures/id_rsa'))
290
+ FakeNode.new(log: test_log).run do |port|
291
+ FakeHome.new.run do |home|
292
+ wallet = home.create_wallet(Zold::Id::ROOT)
293
+ base = "http://localhost:#{port}"
294
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(File.read(wallet.path))
295
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
296
+ cycles = 50
297
+ cycles.times do
298
+ wallet.sub(Zold::Amount.new(coins: 10), "NOPREFIX@#{Zold::Id.new}", key)
299
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(File.read(wallet.path))
300
+ assert_equal('200', Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code)
301
+ end
302
+ assert_equal_wait(-10 * cycles) do
303
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}/balance", score: nil).get.body.to_i
304
+ end
305
+ end
306
+ end
261
307
  end
262
308
  end
@@ -0,0 +1,41 @@
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/node/sync_entrance'
27
+ require_relative 'fake_entrance'
28
+
29
+ # SyncEntrance test.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestSyncEntrance < Minitest::Test
34
+ def test_renders_json
35
+ FakeHome.new.run do
36
+ Zold::SyncEntrance.new(FakeEntrance.new, log: test_log).start do |e|
37
+ assert(!e.to_json.nil?)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,36 @@
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 '../test__helper'
25
+ require_relative '../../lib/zold/node/trace'
26
+
27
+ class TraceTest < Minitest::Test
28
+ def test_records_log_lines
29
+ trace = Zold::Trace.new(test_log, 2)
30
+ trace.error('This should not be visible')
31
+ trace.error('How are you, друг?')
32
+ trace.error('Works?')
33
+ assert(!trace.to_s.include?('visible'))
34
+ assert(trace.to_s.include?('друг'))
35
+ end
36
+ end
@@ -37,6 +37,24 @@ end
37
37
 
38
38
  module Minitest
39
39
  class Test
40
+ def assert_wait(max: 30)
41
+ assert_equal_wait(true, max: max) { yield }
42
+ end
43
+
44
+ def assert_equal_wait(expected, max: 30)
45
+ start = Time.now
46
+ loop do
47
+ actual = yield
48
+ if expected == actual
49
+ assert_equal(expected, actual)
50
+ break
51
+ end
52
+ sleep 1
53
+ sec = Time.now - start
54
+ raise "'#{actual}' is not equal to '#{expected}' even after #{sec.round}s of waiting" if sec > max
55
+ end
56
+ end
57
+
40
58
  def test_log
41
59
  require_relative '../lib/zold/log'
42
60
  @test_log = Zold::Log::Verbose.new
@@ -125,7 +125,7 @@ class TestCopies < Minitest::Test
125
125
  wallet = home.create_wallet(id)
126
126
  amount = Zold::Amount.new(zld: 1.99)
127
127
  key = Zold::Key.new(file: 'fixtures/id_rsa')
128
- wallet.sub(amount, "NOPREFIX@#{id}", key, text, time: Time.parse('2018-01-01T01:01:01Z'))
128
+ wallet.sub(amount, 'NOPREFIX@0000111122223333', key, text, time: Time.parse('2018-01-01T01:01:01Z'))
129
129
  File.read(wallet.path)
130
130
  end
131
131
  end
@@ -34,8 +34,7 @@ class TestMetronome < Minitest::Test
34
34
  list = []
35
35
  metronome.add(FakeRoutine.new(list))
36
36
  metronome.start do
37
- sleep 0.1 while list.empty?
38
- assert_equal(1, list.count)
37
+ assert_wait { !list.empty? }
39
38
  end
40
39
  end
41
40
 
@@ -52,7 +51,7 @@ class TestMetronome < Minitest::Test
52
51
  routine = BrokenRoutine.new
53
52
  metronome.add(routine)
54
53
  metronome.start do
55
- sleep 0.1 while routine.count < 2
54
+ assert_wait { routine.count >= 2 }
56
55
  assert(routine.count > 1)
57
56
  end
58
57
  end
@@ -47,7 +47,7 @@ class TestPatch < Minitest::Test
47
47
  second.sub(Zold::Amount.new(zld: 44.0), "NOPREFIX@#{Zold::Id.new}", key)
48
48
  File.write(third.path, File.read(first.path))
49
49
  t = third.sub(Zold::Amount.new(zld: 10.0), "NOPREFIX@#{Zold::Id.new}", key)
50
- third.add(t.inverse(first.id))
50
+ third.add(t.inverse(Zold::Id.new))
51
51
  patch = Zold::Patch.new(home.wallets, log: test_log)
52
52
  patch.join(first)
53
53
  patch.join(second)
@@ -183,7 +183,7 @@ class TestRemotes < Minitest::Test
183
183
  end
184
184
  end
185
185
  end
186
- sleep 0.1 while cycles.value < 50
186
+ assert_wait { cycles.value >= 50 }
187
187
  alive = false
188
188
  pool.shutdown
189
189
  pool.wait_for_termination
@@ -210,7 +210,7 @@ class TestRemotes < Minitest::Test
210
210
  end
211
211
  end
212
212
  latch.count_down
213
- sleep 0.1 until done.value == threads
213
+ assert_equal_wait(threads) { done.value }
214
214
  assert_equal(threads, remotes.all.count)
215
215
  end
216
216
  end
@@ -239,7 +239,7 @@ class TestRemotes < Minitest::Test
239
239
  end
240
240
  end
241
241
  end
242
- sleep 0.1 while done.value < 1000
242
+ assert_wait { done.value >= 1000 }
243
243
  alive = false
244
244
  pool.shutdown
245
245
  pool.wait_for_termination(10)
@@ -0,0 +1,69 @@
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 'concurrent'
25
+ require_relative 'test__helper'
26
+ require_relative 'fake_home'
27
+ require_relative '../lib/zold/key'
28
+ require_relative '../lib/zold/id'
29
+ require_relative '../lib/zold/wallets'
30
+ require_relative '../lib/zold/sync_wallets'
31
+ require_relative '../lib/zold/amount'
32
+
33
+ # SyncWallets test.
34
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
35
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
36
+ # License:: MIT
37
+ class TestSyncWallets < Minitest::Test
38
+ def test_adds_wallet
39
+ FakeHome.new.run do |home|
40
+ wallets = home.wallets
41
+ id = Zold::Id.new
42
+ home.create_wallet(id)
43
+ key = Zold::Key.new(file: 'fixtures/id_rsa')
44
+ amount = Zold::Amount.new(zld: 5.0)
45
+ threads = 10
46
+ pool = Concurrent::FixedThreadPool.new(threads)
47
+ latch = Concurrent::CountDownLatch.new(1)
48
+ threads.times do |i|
49
+ pool.post do
50
+ Thread.current.name = "thread-#{i}"
51
+ Zold::VerboseThread.new(test_log).run(true) do
52
+ latch.wait(10)
53
+ wallets.find(id) do |wallet|
54
+ wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
55
+ wallet.refurbish
56
+ end
57
+ end
58
+ end
59
+ end
60
+ latch.count_down
61
+ pool.shutdown
62
+ pool.wait_for_termination
63
+ assert_equal_wait(amount * threads * -1, max: 4) do
64
+ wallets.find(id, &:balance)
65
+ end
66
+ assert_equal(5, Dir.new(wallets.path).count)
67
+ end
68
+ end
69
+ end
File without changes
@@ -112,7 +112,7 @@ class TestWallet < Minitest::Test
112
112
  amount = Zold::Amount.new(zld: 39.99)
113
113
  key = Zold::Key.new(file: 'fixtures/id_rsa')
114
114
  txn = wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
115
- wallet.add(txn.inverse(wallet.id))
115
+ wallet.add(txn.inverse(Zold::Id.new))
116
116
  assert(!Zold::Wallet.new(wallet.path).txns[1].sign.end_with?("\n"))
117
117
  end
118
118
  end
@@ -21,6 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'minitest/autorun'
24
+ require 'tmpdir'
24
25
  require_relative 'fake_home'
25
26
  require_relative '../lib/zold/key'
26
27
  require_relative '../lib/zold/id'
@@ -36,9 +37,10 @@ class TestWallets < Minitest::Test
36
37
  FakeHome.new.run do |home|
37
38
  wallets = home.wallets
38
39
  id = Zold::Id.new
39
- wallet = wallets.find(id)
40
- wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
41
- assert_equal(1, wallets.all.count)
40
+ wallets.find(id) do |wallet|
41
+ wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
42
+ assert_equal(1, wallets.all.count)
43
+ end
42
44
  end
43
45
  end
44
46
 
@@ -47,17 +49,19 @@ class TestWallets < Minitest::Test
47
49
  wallets = home.wallets
48
50
  FileUtils.touch(File.join(home.dir, '0xaaaaaaaaaaaaaaaaaaahello'))
49
51
  id = Zold::Id.new
50
- wallet = wallets.find(id)
51
- wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
52
- assert_equal(1, wallets.all.count)
52
+ wallets.find(id) do |wallet|
53
+ wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
54
+ assert_equal(1, wallets.all.count)
55
+ end
53
56
  end
54
57
  end
55
58
 
56
59
  def test_substracts_dir_path_from_full_path
57
- FakeHome.new.run do |home|
58
- wallets = home.wallets
59
- path = wallets.path
60
- assert_equal('.', wallets.to_s(path))
60
+ Dir.mktmpdir do |dir|
61
+ Dir.chdir(dir) do
62
+ wallets = Zold::Wallets.new(Dir.pwd)
63
+ assert_equal('.', wallets.to_s)
64
+ end
61
65
  end
62
66
  end
63
67
  end