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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/appveyor.yml +9 -8
- data/bin/zold +8 -4
- data/fixtures/scripts/distribute-wallet.sh +4 -3
- data/lib/zold/commands/create.rb +6 -5
- data/lib/zold/commands/diff.rb +5 -7
- data/lib/zold/commands/fetch.rb +3 -2
- data/lib/zold/commands/invoice.rb +4 -3
- data/lib/zold/commands/merge.rb +14 -13
- data/lib/zold/commands/node.rb +40 -17
- data/lib/zold/commands/pay.rb +16 -9
- data/lib/zold/commands/propagate.rb +24 -21
- data/lib/zold/commands/push.rb +23 -22
- data/lib/zold/commands/remote.rb +16 -23
- data/lib/zold/commands/routines/reconnect.rb +5 -1
- data/lib/zold/commands/show.rb +3 -1
- data/lib/zold/commands/taxes.rb +9 -3
- data/lib/zold/copies.rb +2 -2
- data/lib/zold/hungry_wallets.rb +21 -1
- data/lib/zold/node/async_entrance.rb +5 -6
- data/lib/zold/node/entrance.rb +3 -2
- data/lib/zold/node/front.rb +119 -88
- data/lib/zold/node/nodup_entrance.rb +3 -2
- data/lib/zold/node/sync_entrance.rb +81 -0
- data/lib/zold/node/trace.rb +75 -0
- data/lib/zold/patch.rb +2 -3
- data/lib/zold/remotes.rb +1 -1
- data/lib/zold/sync_wallets.rb +78 -0
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +1 -0
- data/lib/zold/wallets.rb +5 -5
- data/test/commands/test_create.rb +9 -6
- data/test/commands/test_diff.rb +1 -1
- data/test/commands/test_invoice.rb +7 -6
- data/test/commands/test_list.rb +4 -3
- data/test/commands/test_merge.rb +2 -2
- data/test/commands/test_pull.rb +3 -1
- data/test/commands/test_remote.rb +4 -0
- data/test/commands/test_show.rb +5 -4
- data/test/fake_home.rb +2 -1
- data/test/node/test_async_entrance.rb +1 -1
- data/test/node/test_farm.rb +2 -2
- data/test/node/test_front.rb +63 -17
- data/test/node/test_sync_entrance.rb +41 -0
- data/test/node/test_trace.rb +36 -0
- data/test/test__helper.rb +18 -0
- data/test/test_copies.rb +1 -1
- data/test/test_metronome.rb +2 -3
- data/test/test_patch.rb +1 -1
- data/test/test_remotes.rb +3 -3
- data/test/test_sync_wallets.rb +69 -0
- data/test/test_upgrades.rb +0 -0
- data/test/test_wallet.rb +1 -1
- data/test/test_wallets.rb +14 -10
- data/test/test_zold.rb +2 -2
- data/test/upgrades/test_protocol_up.rb +3 -2
- data/zold.gemspec +1 -0
- metadata +25 -2
@@ -59,8 +59,9 @@ module Zold
|
|
59
59
|
wallet = Wallet.new(f.path)
|
60
60
|
wallet.refurbish
|
61
61
|
after = File.read(wallet.path)
|
62
|
-
|
63
|
-
|
62
|
+
before = @wallets.find(id) do |w|
|
63
|
+
w.exists? ? AtomicFile.new(w.path).read.to_s : ''
|
64
|
+
end
|
64
65
|
if before == after
|
65
66
|
@log.info("Duplicate of #{id}/#{wallet.digest[0, 6]}/#{after.length}b/#{wallet.txns.count}t ignored")
|
66
67
|
return []
|
@@ -0,0 +1,81 @@
|
|
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 'concurrent'
|
24
|
+
require_relative '../log'
|
25
|
+
require_relative '../id'
|
26
|
+
require_relative '../verbose_thread'
|
27
|
+
|
28
|
+
# The sync entrance of the web front.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
module Zold
|
33
|
+
# The entrance that makes sure only one thread works with a wallet
|
34
|
+
class SyncEntrance
|
35
|
+
def initialize(entrance, dir, timeout: 30, log: Log::Quiet.new)
|
36
|
+
raise 'Entrance can\'t be nil' if entrance.nil?
|
37
|
+
@entrance = entrance
|
38
|
+
raise 'Dir can\'t be nil' if dir.nil?
|
39
|
+
@dir = dir
|
40
|
+
@timeout = timeout
|
41
|
+
raise 'Log can\'t be nil' if log.nil?
|
42
|
+
@log = log
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_json
|
46
|
+
@entrance.to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
def start
|
50
|
+
@entrance.start do
|
51
|
+
yield(self)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Always returns an array with a single ID of the pushed wallet
|
56
|
+
def push(id, body)
|
57
|
+
f = File.join(@dir, "#{id}.lock")
|
58
|
+
FileUtils.mkdir_p(File.dirname(f))
|
59
|
+
File.open(f, File::RDWR | File::CREAT) do |lock|
|
60
|
+
start = Time.now
|
61
|
+
cycles = 0
|
62
|
+
loop do
|
63
|
+
break if lock.flock(File::LOCK_EX | File::LOCK_NB)
|
64
|
+
sleep 0.1
|
65
|
+
cycles += 1
|
66
|
+
delay = Time.now - start
|
67
|
+
if delay > @timeout
|
68
|
+
raise "##{Process.pid}/#{Thread.current.name} can't get exclusive access to the wallet #{id}/e \
|
69
|
+
because of the lock at #{lock.path}: #{File.read(lock)}"
|
70
|
+
end
|
71
|
+
if (cycles % 20).zero?
|
72
|
+
@log.info("##{Process.pid}/#{Thread.current.name} still waiting for \
|
73
|
+
exclusive access to #{id}/e, #{delay.round}s already")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
File.write(lock, "##{Process.pid}/#{Thread.current.name}/#{Time.now.utc.iso8601}")
|
77
|
+
@entrance.push(id, body)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,75 @@
|
|
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
|
+
# The web front of the node.
|
24
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
25
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
26
|
+
# License:: MIT
|
27
|
+
module Zold
|
28
|
+
# Log that traces everything
|
29
|
+
class Trace
|
30
|
+
def initialize(log, limit = 4096)
|
31
|
+
@log = log
|
32
|
+
@buffer = []
|
33
|
+
@mutex = Mutex.new
|
34
|
+
@limit = limit
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
@mutex.synchronize do
|
39
|
+
@buffer.join("\n")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def debug(msg)
|
44
|
+
@log.debug(msg)
|
45
|
+
append('DBG', msg) if debug?
|
46
|
+
end
|
47
|
+
|
48
|
+
def debug?
|
49
|
+
@log.debug?
|
50
|
+
end
|
51
|
+
|
52
|
+
def info(msg)
|
53
|
+
@log.info(msg)
|
54
|
+
append('INF', msg) if info?
|
55
|
+
end
|
56
|
+
|
57
|
+
def info?
|
58
|
+
@log.info?
|
59
|
+
end
|
60
|
+
|
61
|
+
def error(msg)
|
62
|
+
@log.error(msg)
|
63
|
+
append('ERR', msg)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def append(level, msg)
|
69
|
+
@mutex.synchronize do
|
70
|
+
@buffer << "#{level}: #{msg}"
|
71
|
+
@buffer.shift if @buffer.size > @limit
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/zold/patch.rb
CHANGED
@@ -101,12 +101,11 @@ module Zold
|
|
101
101
|
@log.error("Payment prefix '#{txn.prefix}' doesn't match with the key of #{wallet.id}: #{txn.to_text}")
|
102
102
|
next
|
103
103
|
end
|
104
|
-
|
105
|
-
unless payer.exists?
|
104
|
+
unless @wallets.find(txn.bnf, &:exists?)
|
106
105
|
@log.error("Paying wallet file is absent: #{txn.to_text}")
|
107
106
|
next
|
108
107
|
end
|
109
|
-
unless
|
108
|
+
unless @wallets.find(txn.bnf) { |p| p.has?(txn.id, wallet.id) }
|
110
109
|
@log.error("Paying wallet #{txn.bnf} doesn't have transaction ##{txn.id} \
|
111
110
|
among #{payer.txns.count} transactions: #{txn.to_text}")
|
112
111
|
next
|
data/lib/zold/remotes.rb
CHANGED
@@ -178,7 +178,7 @@ module Zold
|
|
178
178
|
list.each do |r|
|
179
179
|
pool.post do
|
180
180
|
Thread.current.abort_on_exception = true
|
181
|
-
Thread.current.name =
|
181
|
+
Thread.current.name = "remotes@#{r[:host]}:#{r[:port]}"
|
182
182
|
start = Time.now
|
183
183
|
begin
|
184
184
|
yield Remotes::Remote.new(
|
@@ -0,0 +1,78 @@
|
|
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_relative 'log'
|
24
|
+
|
25
|
+
# Sync collection of wallets.
|
26
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
28
|
+
# License:: MIT
|
29
|
+
module Zold
|
30
|
+
# Synchronized collection of wallets
|
31
|
+
class SyncWallets
|
32
|
+
def initialize(wallets, dir, timeout: 30, log: Log::Quiet.new)
|
33
|
+
@wallets = wallets
|
34
|
+
@dir = dir
|
35
|
+
@log = log
|
36
|
+
@timeout = timeout
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
@wallets.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def path
|
44
|
+
@wallets.path
|
45
|
+
end
|
46
|
+
|
47
|
+
def all
|
48
|
+
@wallets.all
|
49
|
+
end
|
50
|
+
|
51
|
+
def find(id)
|
52
|
+
@wallets.find(id) do |wallet|
|
53
|
+
f = File.join(@dir, id)
|
54
|
+
FileUtils.mkdir_p(File.dirname(f))
|
55
|
+
File.open(f, File::RDWR | File::CREAT) do |lock|
|
56
|
+
start = Time.now
|
57
|
+
cycles = 0
|
58
|
+
loop do
|
59
|
+
break if lock.flock(File::LOCK_EX | File::LOCK_NB)
|
60
|
+
sleep 0.1
|
61
|
+
cycles += 1
|
62
|
+
delay = Time.now - start
|
63
|
+
if delay > @timeout
|
64
|
+
raise "##{Process.pid}/#{Thread.current.name} can't get exclusive access to the wallet #{id} \
|
65
|
+
because of the lock at #{lock.path}: #{File.read(lock)}"
|
66
|
+
end
|
67
|
+
if (cycles % 20).zero?
|
68
|
+
@log.info("##{Process.pid}/#{Thread.current.name} still waiting for \
|
69
|
+
exclusive access to #{id}, #{delay.round}s already: #{File.read(lock)}")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
File.write(lock, "##{Process.pid}/#{Thread.current.name}")
|
73
|
+
yield wallet
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallet.rb
CHANGED
@@ -126,6 +126,7 @@ module Zold
|
|
126
126
|
def add(txn)
|
127
127
|
raise 'The txn has to be of type Txn' unless txn.is_a?(Txn)
|
128
128
|
dup = txns.find { |t| t.bnf == txn.bnf && t.id == txn.id }
|
129
|
+
raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id
|
129
130
|
raise "The transaction with the same ID and BNF already exists: #{dup}" unless dup.nil?
|
130
131
|
raise "The tax payment already exists: #{txn}" if Tax.new(self).exists?(txn)
|
131
132
|
File.open(@file, 'a') { |f| f.print "#{txn}\n" }
|
data/lib/zold/wallets.rb
CHANGED
@@ -37,10 +37,10 @@ module Zold
|
|
37
37
|
# @todo #70:30min Let's make it smarter. Instead of returning
|
38
38
|
# the full path let's substract the prefix from it if it's equal
|
39
39
|
# to the current directory in Dir.pwd.
|
40
|
-
def to_s
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def to_s
|
41
|
+
mine = Pathname.new(File.expand_path(@dir))
|
42
|
+
home = Pathname.new(File.expand_path(Dir.pwd))
|
43
|
+
mine.relative_path_from(home).to_s
|
44
44
|
end
|
45
45
|
|
46
46
|
def path
|
@@ -63,7 +63,7 @@ module Zold
|
|
63
63
|
def find(id)
|
64
64
|
raise 'Id can\'t be nil' if id.nil?
|
65
65
|
raise 'Id must be of type Id' unless id.is_a?(Id)
|
66
|
-
Zold::Wallet.new(File.join(path, id.to_s))
|
66
|
+
yield Zold::Wallet.new(File.join(path, id.to_s))
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -34,14 +34,17 @@ require_relative '../../lib/zold/commands/create'
|
|
34
34
|
class TestCreate < Minitest::Test
|
35
35
|
def test_creates_wallet
|
36
36
|
Dir.mktmpdir do |dir|
|
37
|
-
|
37
|
+
wallets = Zold::Wallets.new(dir)
|
38
|
+
id = Zold::Create.new(wallets: wallets, log: test_log).run(
|
38
39
|
['create', '--public-key=fixtures/id_rsa.pub']
|
39
40
|
)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
wallets.find(id) do |wallet|
|
42
|
+
assert(wallet.balance.zero?)
|
43
|
+
assert(
|
44
|
+
File.exist?(File.join(dir, "#{wallet.id}#{Zold::Wallet::EXTENSION}")),
|
45
|
+
"Wallet file not found: #{wallet.id}#{Zold::Wallet::EXTENSION}"
|
46
|
+
)
|
47
|
+
end
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
data/test/commands/test_diff.rb
CHANGED
@@ -47,7 +47,7 @@ class TestDiff < Minitest::Test
|
|
47
47
|
second = home.create_wallet
|
48
48
|
File.write(second.path, File.read(wallet.path))
|
49
49
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
50
|
-
['pay', wallet.id.to_s,
|
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
53
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
@@ -38,12 +38,13 @@ class TestInvoice < Minitest::Test
|
|
38
38
|
Dir.mktmpdir do |dir|
|
39
39
|
id = Zold::Id.new
|
40
40
|
wallets = Zold::Wallets.new(dir)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
wallets.find(id) do |source|
|
42
|
+
source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
43
|
+
invoice = Zold::Invoice.new(wallets: wallets, log: test_log).run(
|
44
|
+
['invoice', id.to_s, '--length=16']
|
45
|
+
)
|
46
|
+
assert_equal(33, invoice.length)
|
47
|
+
end
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
data/test/commands/test_list.rb
CHANGED
@@ -37,9 +37,10 @@ class TestList < Minitest::Test
|
|
37
37
|
Dir.mktmpdir do |dir|
|
38
38
|
id = Zold::Id.new
|
39
39
|
wallets = Zold::Wallets.new(dir)
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
wallets.find(id) do |wallet|
|
41
|
+
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
42
|
+
Zold::List.new(wallets: wallets, log: test_log).run
|
43
|
+
end
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
data/test/commands/test_merge.rb
CHANGED
@@ -49,7 +49,7 @@ class TestMerge < Minitest::Test
|
|
49
49
|
second = home.create_wallet
|
50
50
|
File.write(second.path, File.read(wallet.path))
|
51
51
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
52
|
-
['pay', wallet.id.to_s,
|
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
55
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
@@ -70,7 +70,7 @@ class TestMerge < Minitest::Test
|
|
70
70
|
second = home.create_wallet
|
71
71
|
File.write(second.path, File.read(wallet.path))
|
72
72
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
73
|
-
['pay', wallet.id.to_s,
|
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
76
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
data/test/commands/test_pull.rb
CHANGED
@@ -43,7 +43,9 @@ class TestPull < Minitest::Test
|
|
43
43
|
Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: test_log).run(
|
44
44
|
['--ignore-this-stupid-option', 'pull', id.to_s]
|
45
45
|
)
|
46
|
-
|
46
|
+
home.wallets.find(Zold::Id.new(id)) do |wallet|
|
47
|
+
assert(wallet.exists?)
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -97,6 +97,10 @@ class TestRemote < Minitest::Test
|
|
97
97
|
score = Zold::Score.new(
|
98
98
|
time: Time.now, host: 'aa1.example.org', port: 9999, invoice: 'NOPREFIX4@ffffffffffffffff'
|
99
99
|
)
|
100
|
+
stub_request(:get, 'http://localhost:8883/version').to_return(
|
101
|
+
status: 200,
|
102
|
+
body: '0.0.0'
|
103
|
+
)
|
100
104
|
stub_request(:get, "http://#{score.host}:#{score.port}/remotes").to_return(
|
101
105
|
status: 200,
|
102
106
|
body: {
|
data/test/commands/test_show.rb
CHANGED
@@ -38,10 +38,11 @@ class TestShow < Minitest::Test
|
|
38
38
|
Dir.mktmpdir do |dir|
|
39
39
|
id = Zold::Id.new
|
40
40
|
wallets = Zold::Wallets.new(dir)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
wallets.find(id) do |wallet|
|
42
|
+
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
43
|
+
balance = Zold::Show.new(wallets: wallets, log: test_log).run(['show', id.to_s])
|
44
|
+
assert_equal(Zold::Amount::ZERO, balance)
|
45
|
+
end
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
data/test/fake_home.rb
CHANGED
@@ -24,6 +24,7 @@ require 'tmpdir'
|
|
24
24
|
require_relative '../lib/zold/id'
|
25
25
|
require_relative '../lib/zold/wallet'
|
26
26
|
require_relative '../lib/zold/wallets'
|
27
|
+
require_relative '../lib/zold/sync_wallets'
|
27
28
|
require_relative '../lib/zold/key'
|
28
29
|
require_relative '../lib/zold/version'
|
29
30
|
require_relative '../lib/zold/remotes'
|
@@ -47,7 +48,7 @@ class FakeHome
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def wallets
|
50
|
-
Zold::Wallets.new(@dir)
|
51
|
+
Zold::SyncWallets.new(Zold::Wallets.new(@dir), File.join(@dir, 'locks'))
|
51
52
|
end
|
52
53
|
|
53
54
|
def create_wallet(id = Zold::Id.new, dir = @dir)
|