zold 0.16.24 → 0.16.25
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/.rultor.yml +1 -0
- data/.travis.yml +1 -0
- data/README.md +1 -1
- data/bin/zold +121 -117
- data/lib/zold/cached_wallets.rb +2 -2
- data/lib/zold/commands/create.rb +1 -1
- data/lib/zold/commands/diff.rb +1 -1
- data/lib/zold/commands/fetch.rb +3 -2
- data/lib/zold/commands/invoice.rb +2 -2
- data/lib/zold/commands/list.rb +9 -1
- data/lib/zold/commands/merge.rb +1 -1
- data/lib/zold/commands/pay.rb +2 -2
- data/lib/zold/commands/propagate.rb +3 -3
- data/lib/zold/commands/push.rb +3 -3
- data/lib/zold/commands/remote.rb +3 -3
- data/lib/zold/commands/remove.rb +1 -1
- data/lib/zold/commands/show.rb +1 -1
- data/lib/zold/commands/taxes.rb +3 -3
- data/lib/zold/http.rb +22 -19
- data/lib/zold/hungry_wallets.rb +2 -2
- data/lib/zold/node/entrance.rb +1 -1
- data/lib/zold/node/front.rb +3 -6
- data/lib/zold/node/nodup_entrance.rb +1 -1
- data/lib/zold/node/sync_entrance.rb +1 -1
- data/lib/zold/patch.rb +3 -5
- data/lib/zold/remotes.rb +7 -6
- data/lib/zold/sync_wallets.rb +3 -2
- data/lib/zold/tree_wallets.rb +2 -1
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallets.rb +2 -1
- data/test/commands/test_create.rb +1 -1
- data/test/commands/test_invoice.rb +1 -1
- data/test/commands/test_list.rb +1 -1
- data/test/commands/test_pull.rb +1 -1
- data/test/commands/test_show.rb +1 -1
- data/test/fake_home.rb +1 -1
- data/test/node/fake_node.rb +2 -2
- data/test/node/test_front.rb +30 -30
- data/test/test__helper.rb +1 -0
- data/test/test_cached_wallets.rb +2 -2
- data/test/test_http.rb +9 -9
- data/test/test_sync_wallets.rb +2 -2
- data/test/test_tree_wallets.rb +2 -2
- data/test/test_wallets.rb +2 -2
- data/test/upgrades/test_protocol_up.rb +1 -1
- data/zold.gemspec +7 -0
- metadata +36 -3
data/lib/zold/commands/push.rb
CHANGED
@@ -87,14 +87,14 @@ total score for #{id} is #{total}")
|
|
87
87
|
return 0
|
88
88
|
end
|
89
89
|
start = Time.now
|
90
|
-
content = @wallets.
|
90
|
+
content = @wallets.acq(id) do |wallet|
|
91
91
|
raise "The wallet #{id} is absent" unless wallet.exists?
|
92
92
|
IO.read(wallet.path)
|
93
93
|
end
|
94
94
|
uri = "/wallet/#{id}"
|
95
95
|
response = r.http(uri).put(content, timeout: 2 + content.length * 0.01 / 1024)
|
96
|
-
@wallets.
|
97
|
-
if response.
|
96
|
+
@wallets.acq(id) do |wallet|
|
97
|
+
if response.status == 304
|
98
98
|
@log.info("#{r}: same version of #{wallet.mnemo} there, in #{Age.new(start, limit: 0.5)}")
|
99
99
|
return 0
|
100
100
|
end
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -157,7 +157,7 @@ Available options:"
|
|
157
157
|
def show
|
158
158
|
@remotes.all.each do |r|
|
159
159
|
score = Rainbow("/#{r[:score]}").color(r[:score].positive? ? :green : :red)
|
160
|
-
@log.info(r[:host]
|
160
|
+
@log.info("#{r[:host]}:#{r[:port]}#{score} #{r[:errors]} errors#{r[:default] ? ' default' : ''}")
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -183,12 +183,12 @@ Available options:"
|
|
183
183
|
return
|
184
184
|
end
|
185
185
|
if opts['ignore-if-exists'] && @remotes.exists?(host, port)
|
186
|
-
@log.
|
186
|
+
@log.debug("#{host}:#{port} already exists, won't add because of --ignore-if-exists")
|
187
187
|
return
|
188
188
|
end
|
189
189
|
unless opts['skip-ping']
|
190
190
|
res = Http.new(uri: "http://#{host}:#{port}/version", network: opts['network']).get
|
191
|
-
raise "The node #{host}:#{port} is not responding, #{res.
|
191
|
+
raise "The node #{host}:#{port} is not responding, #{res.status}:#{res.status_line}" unless res.status == 200
|
192
192
|
end
|
193
193
|
@remotes.add(host, port)
|
194
194
|
@log.info("#{host}:#{port} added to the list, #{@remotes.all.count} total")
|
data/lib/zold/commands/remove.rb
CHANGED
data/lib/zold/commands/show.rb
CHANGED
data/lib/zold/commands/taxes.rb
CHANGED
@@ -86,21 +86,21 @@ Available options:"
|
|
86
86
|
when 'show'
|
87
87
|
raise 'At least one wallet ID is required' unless mine[1]
|
88
88
|
mine[1..-1].each do |id|
|
89
|
-
@wallets.
|
89
|
+
@wallets.acq(Id.new(id)) do |w|
|
90
90
|
show(w, opts)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
when 'debt'
|
94
94
|
raise 'At least one wallet ID is required' unless mine[1]
|
95
95
|
mine[1..-1].each do |id|
|
96
|
-
@wallets.
|
96
|
+
@wallets.acq(Id.new(id)) do |w|
|
97
97
|
debt(w, opts)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
when 'pay'
|
101
101
|
raise 'At least one wallet ID is required' unless mine[1]
|
102
102
|
mine[1..-1].each do |id|
|
103
|
-
@wallets.
|
103
|
+
@wallets.acq(Id.new(id), exclusive: true) do |w|
|
104
104
|
pay(w, opts)
|
105
105
|
end
|
106
106
|
end
|
data/lib/zold/http.rb
CHANGED
@@ -22,8 +22,8 @@
|
|
22
22
|
|
23
23
|
require 'rainbow'
|
24
24
|
require 'uri'
|
25
|
-
require 'net/http'
|
26
25
|
require 'backtrace'
|
26
|
+
require 'patron'
|
27
27
|
require 'zold/score'
|
28
28
|
require_relative 'version'
|
29
29
|
|
@@ -68,31 +68,34 @@ module Zold
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def get(timeout: READ_TIMEOUT + CONNECT_TIMEOUT)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
base_url = "#{@uri.scheme}://#{@uri.host}:#{@uri.port}"
|
72
|
+
session = Patron::Session.new(
|
73
|
+
timeout: timeout,
|
74
|
+
connect_timeout: CONNECT_TIMEOUT,
|
75
|
+
base_url: base_url,
|
76
|
+
headers: headers
|
77
|
+
)
|
75
78
|
path = @uri.path
|
76
79
|
path += '?' + @uri.query if @uri.query
|
77
|
-
|
80
|
+
session.get(path)
|
78
81
|
rescue StandardError => e
|
79
82
|
Error.new(e)
|
80
83
|
end
|
81
84
|
|
82
85
|
def put(body, timeout: READ_TIMEOUT + CONNECT_TIMEOUT)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
http.request_put(
|
90
|
-
path, body,
|
91
|
-
headers.merge(
|
86
|
+
base_url = "#{@uri.scheme}://#{@uri.host}:#{@uri.port}"
|
87
|
+
session = Patron::Session.new(
|
88
|
+
timeout: timeout,
|
89
|
+
connect_timeout: CONNECT_TIMEOUT,
|
90
|
+
base_url: base_url,
|
91
|
+
headers: headers.merge(
|
92
92
|
'Content-Type': 'text/plain',
|
93
93
|
'Content-Length': body.length.to_s
|
94
94
|
)
|
95
95
|
)
|
96
|
+
path = @uri.path
|
97
|
+
path += '?' + @uri.query if @uri.query
|
98
|
+
session.put(path, body)
|
96
99
|
rescue StandardError => e
|
97
100
|
Error.new(e)
|
98
101
|
end
|
@@ -113,15 +116,15 @@ module Zold
|
|
113
116
|
Backtrace.new(@ex).to_s
|
114
117
|
end
|
115
118
|
|
116
|
-
def
|
117
|
-
|
119
|
+
def status
|
120
|
+
599
|
118
121
|
end
|
119
122
|
|
120
|
-
def
|
123
|
+
def status_line
|
121
124
|
@ex.message
|
122
125
|
end
|
123
126
|
|
124
|
-
def
|
127
|
+
def headers
|
125
128
|
{}
|
126
129
|
end
|
127
130
|
end
|
data/lib/zold/hungry_wallets.rb
CHANGED
@@ -27,8 +27,8 @@ module Zold
|
|
27
27
|
class HungryWallets < SimpleDelegator
|
28
28
|
# @todo #280:30min Add to the queue. Once in there, try
|
29
29
|
# to pull it as soon as possible as is described in #280.
|
30
|
-
def
|
31
|
-
yield super(id)
|
30
|
+
def acq(id, exclusive: false)
|
31
|
+
yield super(id, exclusive: exclusive)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -91,7 +91,7 @@ module Zold
|
|
91
91
|
@mutex.synchronize do
|
92
92
|
@history.shift if @history.length >= 16
|
93
93
|
@speed.shift if @speed.length >= 64
|
94
|
-
@wallets.
|
94
|
+
@wallets.acq(id) do |wallet|
|
95
95
|
@history << "#{sec}/#{modified.count}/#{wallet.mnemo}"
|
96
96
|
end
|
97
97
|
@speed << sec
|
data/lib/zold/node/front.rb
CHANGED
@@ -467,12 +467,9 @@ in #{Age.new(@start, limit: 1)}")
|
|
467
467
|
end
|
468
468
|
|
469
469
|
def copy_of(id)
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
IO.write(f, IO.read(wallet.path))
|
474
|
-
end
|
475
|
-
yield Wallet.new(f.path)
|
470
|
+
settings.wallets.acq(id) do |wallet|
|
471
|
+
error(404, "Wallet ##{id} doesn't exist on the node") unless wallet.exists?
|
472
|
+
yield wallet
|
476
473
|
end
|
477
474
|
end
|
478
475
|
|
@@ -50,7 +50,7 @@ module Zold
|
|
50
50
|
|
51
51
|
# Returns a list of modifed wallets (as Zold::Id)
|
52
52
|
def push(id, body)
|
53
|
-
before = @wallets.
|
53
|
+
before = @wallets.acq(id) { |w| w.exists? ? w.digest : '' }
|
54
54
|
after = OpenSSL::Digest::SHA256.new(body).hexdigest
|
55
55
|
if before == after
|
56
56
|
@log.debug("Duplicate of #{id} ignored (#{Size.new(body.length)} bytes)")
|
@@ -53,7 +53,7 @@ module Zold
|
|
53
53
|
|
54
54
|
# Always returns an array with a single ID of the pushed wallet
|
55
55
|
def push(id, body)
|
56
|
-
Futex.new(File.join(@dir, id), log: @log).open do
|
56
|
+
Futex.new(File.join(@dir, id), log: @log, timeout: 60 * 60).open do
|
57
57
|
@entrance.push(id, body)
|
58
58
|
end
|
59
59
|
end
|
data/lib/zold/patch.rb
CHANGED
@@ -33,8 +33,6 @@ module Zold
|
|
33
33
|
# A patch
|
34
34
|
class Patch
|
35
35
|
def initialize(wallets, log: Log::Quiet.new)
|
36
|
-
raise 'Wallets can\'t be nil' if wallets.nil?
|
37
|
-
raise 'Wallets must implement the contract of Wallets: method #find is required' unless wallets.respond_to?(:find)
|
38
36
|
@wallets = wallets
|
39
37
|
@txns = []
|
40
38
|
@log = log
|
@@ -101,12 +99,12 @@ module Zold
|
|
101
99
|
@log.error("Payment prefix '#{txn.prefix}' doesn't match with the key of #{wallet.id}: \"#{txn.to_text}\"")
|
102
100
|
next
|
103
101
|
end
|
104
|
-
unless @wallets.
|
102
|
+
unless @wallets.acq(txn.bnf, &:exists?)
|
105
103
|
@log.error("Paying wallet file is absent: #{txn.to_text}")
|
106
104
|
next
|
107
105
|
end
|
108
|
-
unless @wallets.
|
109
|
-
@log.error("
|
106
|
+
unless @wallets.acq(txn.bnf) { |p| p.includes_negative?(txn.id, wallet.id) }
|
107
|
+
@log.error("The beneficiary of #{@id} doesn't have this transaction: \"#{txn.to_text}\"")
|
110
108
|
next
|
111
109
|
end
|
112
110
|
end
|
data/lib/zold/remotes.rb
CHANGED
@@ -92,13 +92,14 @@ module Zold
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def assert_code(code, response)
|
95
|
-
msg = response.
|
96
|
-
return if response.
|
97
|
-
if response.
|
98
|
-
raise "Error ##{response.
|
95
|
+
msg = response.status_line.strip
|
96
|
+
return if response.status.to_i == code
|
97
|
+
if response.headers['X-Zold-Error']
|
98
|
+
raise "Error ##{response.status} \"#{response.headers['X-Zold-Error']}\"
|
99
|
+
at #{response.headers['X-Zold-Path']}"
|
99
100
|
end
|
100
|
-
raise "Unexpected HTTP code #{response.
|
101
|
-
raise "#{msg} (HTTP code #{response.
|
101
|
+
raise "Unexpected HTTP code #{response.status}, instead of #{code}" if msg.empty?
|
102
|
+
raise "#{msg} (HTTP code #{response.status}, instead of #{code})"
|
102
103
|
end
|
103
104
|
|
104
105
|
def assert_valid_score(score)
|
data/lib/zold/sync_wallets.rb
CHANGED
@@ -48,8 +48,9 @@ module Zold
|
|
48
48
|
@wallets.all
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
51
|
+
def acq(id, exclusive: false)
|
52
|
+
raise 'The flag can\'t be nil' if exclusive.nil?
|
53
|
+
@wallets.acq(id) do |wallet|
|
53
54
|
Futex.new(wallet.path, log: @log).open do
|
54
55
|
yield wallet
|
55
56
|
end
|
data/lib/zold/tree_wallets.rb
CHANGED
@@ -57,7 +57,8 @@ module Zold
|
|
57
57
|
end.map { |w| Id.new(File.basename(w, Wallet::EXT)) }
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def acq(id, exclusive: false)
|
61
|
+
raise 'The flag can\'t be nil' if exclusive.nil?
|
61
62
|
raise 'Id can\'t be nil' if id.nil?
|
62
63
|
raise 'Id must be of type Id' unless id.is_a?(Id)
|
63
64
|
yield Wallet.new(
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallets.rb
CHANGED
@@ -61,7 +61,8 @@ module Zold
|
|
61
61
|
end.map { |w| Id.new(File.basename(w, Wallet::EXT)) }
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
64
|
+
def acq(id, exclusive: false)
|
65
|
+
raise 'The flag can\'t be nil' if exclusive.nil?
|
65
66
|
raise 'Id can\'t be nil' if id.nil?
|
66
67
|
raise "Id must be of type Id, #{id.class.name} instead" unless id.is_a?(Id)
|
67
68
|
yield Wallet.new(File.join(path, id.to_s + Wallet::EXT))
|
@@ -38,7 +38,7 @@ class TestCreate < Zold::Test
|
|
38
38
|
id = Zold::Create.new(wallets: wallets, log: test_log).run(
|
39
39
|
['create', '--public-key=fixtures/id_rsa.pub']
|
40
40
|
)
|
41
|
-
wallets.
|
41
|
+
wallets.acq(id) do |wallet|
|
42
42
|
assert(wallet.balance.zero?)
|
43
43
|
assert(
|
44
44
|
File.exist?(File.join(dir, "#{wallet.id}#{Zold::Wallet::EXT}")),
|
@@ -38,7 +38,7 @@ class TestInvoice < Zold::Test
|
|
38
38
|
Dir.mktmpdir do |dir|
|
39
39
|
id = Zold::Id.new
|
40
40
|
wallets = Zold::Wallets.new(dir)
|
41
|
-
wallets.
|
41
|
+
wallets.acq(id) do |source|
|
42
42
|
source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
43
43
|
invoice = Zold::Invoice.new(wallets: wallets, remotes: nil, copies: nil, log: test_log).run(
|
44
44
|
['invoice', id.to_s, '--length=16']
|
data/test/commands/test_list.rb
CHANGED
@@ -37,7 +37,7 @@ class TestList < Zold::Test
|
|
37
37
|
Dir.mktmpdir do |dir|
|
38
38
|
id = Zold::Id.new
|
39
39
|
wallets = Zold::Wallets.new(dir)
|
40
|
-
wallets.
|
40
|
+
wallets.acq(id) do |wallet|
|
41
41
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
42
42
|
Zold::List.new(wallets: wallets, log: test_log).run
|
43
43
|
end
|
data/test/commands/test_pull.rb
CHANGED
@@ -44,7 +44,7 @@ class TestPull < Zold::Test
|
|
44
44
|
Zold::Pull.new(wallets: home.wallets, remotes: remotes, copies: home.copies.root.to_s, log: test_log).run(
|
45
45
|
['--ignore-this-stupid-option', 'pull', id.to_s]
|
46
46
|
)
|
47
|
-
home.wallets.
|
47
|
+
home.wallets.acq(Zold::Id.new(id)) do |wallet|
|
48
48
|
assert(wallet.exists?)
|
49
49
|
end
|
50
50
|
end
|
data/test/commands/test_show.rb
CHANGED
@@ -38,7 +38,7 @@ class TestShow < Zold::Test
|
|
38
38
|
Dir.mktmpdir do |dir|
|
39
39
|
id = Zold::Id.new
|
40
40
|
wallets = Zold::Wallets.new(dir)
|
41
|
-
wallets.
|
41
|
+
wallets.acq(id) do |wallet|
|
42
42
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
43
43
|
balance = Zold::Show.new(wallets: wallets, log: test_log).run(['show', id.to_s])
|
44
44
|
assert_equal(Zold::Amount::ZERO, balance)
|
data/test/fake_home.rb
CHANGED
@@ -55,7 +55,7 @@ class FakeHome
|
|
55
55
|
|
56
56
|
def create_wallet(id = Zold::Id.new, dir = @dir)
|
57
57
|
target = Zold::Wallet.new(File.join(dir, id.to_s + Zold::Wallet::EXT))
|
58
|
-
wallets.
|
58
|
+
wallets.acq(id, exclusive: true) do |w|
|
59
59
|
w.init(id, Zold::Key.new(file: File.expand_path(File.join(__dir__, '../fixtures/id_rsa.pub'))))
|
60
60
|
IO.write(target.path, IO.read(w.path))
|
61
61
|
end
|
data/test/node/fake_node.rb
CHANGED
@@ -66,8 +66,8 @@ class FakeNode
|
|
66
66
|
attempt = 0
|
67
67
|
loop do
|
68
68
|
ping = Zold::Http.new(uri: uri).get
|
69
|
-
break unless ping.
|
70
|
-
@log.debug("Waiting for #{uri} (attempt no.#{attempt}): ##{ping.
|
69
|
+
break unless ping.status == 599 && node.alive?
|
70
|
+
@log.debug("Waiting for #{uri} (attempt no.#{attempt}): ##{ping.status}...")
|
71
71
|
sleep 0.5
|
72
72
|
attempt += 1
|
73
73
|
break if attempt > 10
|
data/test/node/test_front.rb
CHANGED
@@ -74,7 +74,7 @@ class FrontTest < Zold::Test
|
|
74
74
|
def test_renders_public_pages
|
75
75
|
FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--no-metronome', '--threads=0']) do |port|
|
76
76
|
{
|
77
|
-
|
77
|
+
200 => [
|
78
78
|
'/robots.txt',
|
79
79
|
'/',
|
80
80
|
'/remotes',
|
@@ -87,7 +87,7 @@ class FrontTest < Zold::Test
|
|
87
87
|
'/threads',
|
88
88
|
'/ps'
|
89
89
|
],
|
90
|
-
|
90
|
+
404 => [
|
91
91
|
'/this-is-absent',
|
92
92
|
'/wallet/ffffeeeeddddcccc',
|
93
93
|
'/wallet/ffffeeeeddddcccc.bin',
|
@@ -103,8 +103,8 @@ class FrontTest < Zold::Test
|
|
103
103
|
uri = URI("http://localhost:#{port}#{p}")
|
104
104
|
response = Zold::Http.new(uri: uri).get
|
105
105
|
assert_equal(
|
106
|
-
code, response.
|
107
|
-
"Invalid response code for #{uri}: #{response.
|
106
|
+
code, response.status,
|
107
|
+
"Invalid response code for #{uri}: #{response.status_line}"
|
108
108
|
)
|
109
109
|
end
|
110
110
|
end
|
@@ -117,7 +117,7 @@ class FrontTest < Zold::Test
|
|
117
117
|
host: 'localhost', port: port, invoice: 'NOPREFIX@ffffffffffffffff', strength: 1
|
118
118
|
).next.next.next.next
|
119
119
|
response = Zold::Http.new(uri: "http://localhost:#{port}/remotes", score: score).get
|
120
|
-
assert_equal(
|
120
|
+
assert_equal(200, response.status, response.body)
|
121
121
|
assert_equal(1, Zold::JsonPage.new(response.body).to_hash['all'].count, response.body)
|
122
122
|
assert_match(
|
123
123
|
/(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})Z/,
|
@@ -132,7 +132,7 @@ class FrontTest < Zold::Test
|
|
132
132
|
3.times do |i|
|
133
133
|
assert_equal_wait(true) do
|
134
134
|
response = Zold::Http.new(uri: "http://localhost:#{port}/").get
|
135
|
-
assert_equal(
|
135
|
+
assert_equal(200, response.status, response.body)
|
136
136
|
score = Zold::Score.parse_json(Zold::JsonPage.new(response.body).to_hash['score'])
|
137
137
|
score.value >= i
|
138
138
|
end
|
@@ -147,8 +147,8 @@ class FrontTest < Zold::Test
|
|
147
147
|
base = "http://localhost:#{port}"
|
148
148
|
response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}")
|
149
149
|
.put(IO.read(wallet.path))
|
150
|
-
assert_equal(
|
151
|
-
assert_equal_wait(
|
150
|
+
assert_equal(200, response.status, response.body)
|
151
|
+
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
152
152
|
[
|
153
153
|
"/wallet/#{wallet.id}.txt",
|
154
154
|
"/wallet/#{wallet.id}.json",
|
@@ -162,7 +162,7 @@ class FrontTest < Zold::Test
|
|
162
162
|
"/wallet/#{wallet.id}.bin",
|
163
163
|
"/wallet/#{wallet.id}/copies"
|
164
164
|
].each do |u|
|
165
|
-
assert_equal_wait(
|
165
|
+
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}#{u}").get.status }
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
@@ -174,14 +174,14 @@ class FrontTest < Zold::Test
|
|
174
174
|
wallet = home.create_wallet
|
175
175
|
base = "http://localhost:#{port}"
|
176
176
|
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
|
177
|
-
assert_equal_wait(
|
177
|
+
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
178
178
|
threads = []
|
179
179
|
mutex = Mutex.new
|
180
180
|
Threads.new(6).assert(100) do
|
181
|
-
assert_equal_wait(
|
181
|
+
assert_equal_wait(200) do
|
182
182
|
res = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get
|
183
|
-
mutex.synchronize { threads << res.
|
184
|
-
res.
|
183
|
+
mutex.synchronize { threads << res.headers['X-Zold-Thread'] }
|
184
|
+
res.status
|
185
185
|
end
|
186
186
|
end
|
187
187
|
assert(threads.uniq.count > 1)
|
@@ -195,14 +195,14 @@ class FrontTest < Zold::Test
|
|
195
195
|
wallet = home.create_wallet
|
196
196
|
base = "http://localhost:#{port}"
|
197
197
|
assert_equal(
|
198
|
-
|
199
|
-
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path)).
|
198
|
+
200,
|
199
|
+
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path)).status
|
200
200
|
)
|
201
|
-
assert_equal_wait(
|
201
|
+
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
202
202
|
3.times do
|
203
203
|
r = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}")
|
204
204
|
.put(IO.read(wallet.path))
|
205
|
-
assert_equal(
|
205
|
+
assert_equal(304, r.status, r.body)
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
@@ -215,7 +215,7 @@ class FrontTest < Zold::Test
|
|
215
215
|
Threads.new(5).assert do
|
216
216
|
wallet = home.create_wallet
|
217
217
|
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
|
218
|
-
assert_equal_wait(
|
218
|
+
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
@@ -258,11 +258,11 @@ class FrontTest < Zold::Test
|
|
258
258
|
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
259
259
|
response = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
|
260
260
|
assert_equal(
|
261
|
-
|
262
|
-
"Expected HTTP 200 OK: Found #{response.
|
261
|
+
200, response.status,
|
262
|
+
"Expected HTTP 200 OK: Found #{response.status}"
|
263
263
|
)
|
264
264
|
assert_operator(
|
265
|
-
750, :>, response
|
265
|
+
750, :>, response.body.length.to_i,
|
266
266
|
'Expected the content to be smaller than 600 bytes for gzip'
|
267
267
|
)
|
268
268
|
end
|
@@ -286,13 +286,13 @@ class FrontTest < Zold::Test
|
|
286
286
|
Time.stub :now, Time.at(0) do
|
287
287
|
FakeNode.new(log: test_log).run(['--expose-version=9.9.9', '--no-metronome', '--threads=0']) do |port|
|
288
288
|
response = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
|
289
|
-
assert_equal('no-cache', response.
|
290
|
-
assert_equal('close', response.
|
291
|
-
assert_equal('9.9.9', response.
|
292
|
-
assert_equal(app.settings.protocol.to_s, response.
|
293
|
-
assert_equal('*', response.
|
294
|
-
assert(response.
|
295
|
-
assert(!response.
|
289
|
+
assert_equal('no-cache', response.headers['Cache-Control'])
|
290
|
+
assert_equal('close', response.headers['Connection'])
|
291
|
+
assert_equal('9.9.9', response.headers['X-Zold-Version'])
|
292
|
+
assert_equal(app.settings.protocol.to_s, response.headers[Zold::Http::PROTOCOL_HEADER])
|
293
|
+
assert_equal('*', response.headers['Access-Control-Allow-Origin'])
|
294
|
+
assert(response.headers['X-Zold-Milliseconds'])
|
295
|
+
assert(!response.headers[Zold::Http::SCORE_HEADER].nil?)
|
296
296
|
end
|
297
297
|
end
|
298
298
|
end
|
@@ -344,12 +344,12 @@ class FrontTest < Zold::Test
|
|
344
344
|
wallet = home.create_wallet(Zold::Id::ROOT)
|
345
345
|
base = "http://localhost:#{port}"
|
346
346
|
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
|
347
|
-
assert_equal_wait(
|
347
|
+
assert_equal_wait(200) { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status }
|
348
348
|
cycles = 50
|
349
349
|
cycles.times do
|
350
350
|
wallet.sub(Zold::Amount.new(zents: 10), "NOPREFIX@#{Zold::Id.new}", key)
|
351
351
|
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
|
352
|
-
assert_equal(
|
352
|
+
assert_equal(200, Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.status)
|
353
353
|
end
|
354
354
|
assert_equal_wait(-10 * cycles) do
|
355
355
|
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}/balance").get.body.to_i
|