zold 0.14.44 → 0.14.45
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/age.rb +2 -3
- data/lib/zold/amount.rb +1 -1
- data/lib/zold/commands/clean.rb +2 -1
- data/lib/zold/commands/fetch.rb +3 -2
- data/lib/zold/commands/push.rb +4 -3
- data/lib/zold/commands/taxes.rb +8 -6
- data/lib/zold/copies.rb +2 -1
- data/lib/zold/node/async_entrance.rb +2 -1
- data/lib/zold/node/front.rb +2 -1
- data/lib/zold/node/nodup_entrance.rb +7 -2
- data/lib/zold/score.rb +1 -1
- data/lib/zold/size.rb +49 -0
- data/lib/zold/tax.rb +1 -2
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +2 -2
- data/test/commands/test_taxes.rb +10 -9
- data/test/test_age.rb +37 -0
- data/test/test_size.rb +38 -0
- data/test/test_tax.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc091e61d283ef577ce87d8820b39688a07c57f628992f566ed3fd73845c536
|
4
|
+
data.tar.gz: b521a547e508f4b3d562ab0c166baf686cfca29879c25366bf46325e91e156c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c54c68946531a91b6087f7cfaf311dc0b11f7e20fcf0b6e053792c7d525bb608759f18cbbac16811ae35aa6d0ba79add1ba66848c3b070937d24356370d47437
|
7
|
+
data.tar.gz: ce085d811af804213af2efbd8ced6bec1afa62127fdd3d83c5d0d4463b515bcaad0687037109a6a1770ff7c8c8f4e9c4745a01cf57a6ff628d45963e803d7aaf
|
data/lib/zold/age.rb
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
require 'time'
|
24
24
|
|
25
|
-
# Age
|
25
|
+
# Age in seconds.
|
26
26
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
27
|
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
28
28
|
# License:: MIT
|
@@ -30,8 +30,7 @@ module Zold
|
|
30
30
|
# Age
|
31
31
|
class Age
|
32
32
|
def initialize(time)
|
33
|
-
@time = time
|
34
|
-
@time = Time.parse(@time) unless time.is_a?(Time)
|
33
|
+
@time = time.nil? || time.is_a?(Time) ? time : Time.parse(time)
|
35
34
|
end
|
36
35
|
|
37
36
|
def to_s
|
data/lib/zold/amount.rb
CHANGED
data/lib/zold/commands/clean.rb
CHANGED
@@ -27,6 +27,7 @@ require 'slop'
|
|
27
27
|
require 'rainbow'
|
28
28
|
require_relative 'args'
|
29
29
|
require_relative '../age'
|
30
|
+
require_relative '../size'
|
30
31
|
require_relative '../log'
|
31
32
|
require_relative '../http'
|
32
33
|
require_relative '../score'
|
@@ -64,7 +65,7 @@ Available options:"
|
|
64
65
|
cps.all.each do |c|
|
65
66
|
wallet = Wallet.new(c[:path])
|
66
67
|
@log.debug(" #{c[:name]}: #{c[:score]} #{wallet.balance}/#{wallet.txns.count}t/\
|
67
|
-
#{wallet.digest[0, 6]}/#{File.size(c[:path])}
|
68
|
+
#{wallet.digest[0, 6]}/#{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}")
|
68
69
|
end
|
69
70
|
end
|
70
71
|
end
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -31,6 +31,7 @@ require_relative 'args'
|
|
31
31
|
require_relative '../log'
|
32
32
|
require_relative '../age'
|
33
33
|
require_relative '../http'
|
34
|
+
require_relative '../size'
|
34
35
|
require_relative '../score'
|
35
36
|
require_relative '../json_page'
|
36
37
|
require_relative '../copies'
|
@@ -94,7 +95,7 @@ Available options:"
|
|
94
95
|
cps.all.each do |c|
|
95
96
|
wallet = Wallet.new(c[:path])
|
96
97
|
@log.debug(" #{c[:name]}: #{c[:score]} #{wallet.balance}/#{wallet.txns.count}t/\
|
97
|
-
#{wallet.digest[0, 6]}/#{File.size(c[:path])}
|
98
|
+
#{wallet.digest[0, 6]}/#{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}")
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
@@ -128,7 +129,7 @@ Available options:"
|
|
128
129
|
raise "The balance of #{id} is #{wallet.balance} and it's not a root wallet"
|
129
130
|
end
|
130
131
|
copy = cps.add(File.read(f), score.host, score.port, score.value)
|
131
|
-
@log.info("#{r} returned #{body.length}
|
132
|
+
@log.info("#{r} returned #{Size.new(body.length)}/#{wallet.balance}/#{wallet.txns.count}t/\
|
132
133
|
#{digest(json)}/#{Age.new(json['mtime'])}/#{json['copies']}c \
|
133
134
|
as copy #{copy} of #{id} in #{Age.new(start)}: #{Rainbow(score.value).green} (#{json['version']})")
|
134
135
|
end
|
data/lib/zold/commands/push.rb
CHANGED
@@ -26,6 +26,7 @@ require 'json'
|
|
26
26
|
require 'net/http'
|
27
27
|
require_relative 'args'
|
28
28
|
require_relative '../age'
|
29
|
+
require_relative '../size'
|
29
30
|
require_relative '../log'
|
30
31
|
require_relative '../id'
|
31
32
|
require_relative '../http'
|
@@ -96,7 +97,7 @@ total score for #{id} is #{total}")
|
|
96
97
|
response = r.http(uri).put(content)
|
97
98
|
@wallets.find(id) do |wallet|
|
98
99
|
if response.code == '304'
|
99
|
-
@log.info("#{r}: same version #{content.length}
|
100
|
+
@log.info("#{r}: same version #{Size.new(content.length)}/#{wallet.txns.count}t \
|
100
101
|
of #{wallet.id} there, in #{Age.new(start)}")
|
101
102
|
return 0
|
102
103
|
end
|
@@ -106,8 +107,8 @@ of #{wallet.id} there, in #{Age.new(start)}")
|
|
106
107
|
r.assert_valid_score(score)
|
107
108
|
r.assert_score_ownership(score)
|
108
109
|
r.assert_score_strength(score) unless opts['ignore-score-weakness']
|
109
|
-
@log.info("#{r} accepted #{content.length}
|
110
|
-
in #{Age.new(start)}: #{Rainbow(score.value).green} (#{json['version']})")
|
110
|
+
@log.info("#{r} accepted #{Size.new(content.length)}/#{wallet.digest[0, 6]}/#{wallet.txns.count}t \
|
111
|
+
of #{wallet.id} in #{Age.new(start)}: #{Rainbow(score.value).green} (#{json['version']})")
|
111
112
|
score.value
|
112
113
|
end
|
113
114
|
end
|
data/lib/zold/commands/taxes.rb
CHANGED
@@ -72,6 +72,9 @@ Available options:"
|
|
72
72
|
'The location of RSA private key (default: ~/.ssh/id_rsa)',
|
73
73
|
require: true,
|
74
74
|
default: '~/.ssh/id_rsa'
|
75
|
+
o.bool '--ignore-score-weakness',
|
76
|
+
'Don\'t complain when their score is too weak',
|
77
|
+
default: false
|
75
78
|
o.bool '--help', 'Print instructions'
|
76
79
|
end
|
77
80
|
mine = Args.new(opts, @log).take || return
|
@@ -114,13 +117,12 @@ Available options:"
|
|
114
117
|
@log.debug("No need to pay taxes yet, until the debt is less than #{Tax::TRIAL} (#{Tax::TRIAL.to_i} zents)")
|
115
118
|
return
|
116
119
|
end
|
117
|
-
top = top_scores
|
118
|
-
while debt >
|
120
|
+
top = top_scores(opts)
|
121
|
+
while debt > Tax::TRIAL
|
119
122
|
raise 'No acceptable remote nodes, try later' if top.empty?
|
120
123
|
best = top.shift
|
121
124
|
txn = tax.pay(Zold::Key.new(file: opts['private-key']), best)
|
122
|
-
|
123
|
-
debt -= txn.amount
|
125
|
+
debt += txn.amount
|
124
126
|
@log.info("#{txn.amount} of taxes paid to #{txn.bnf}, #{debt} left to pay")
|
125
127
|
end
|
126
128
|
@log.info('The wallet is in good standing, all taxes paid')
|
@@ -136,7 +138,7 @@ Available options:"
|
|
136
138
|
raise 'Not implemented yet'
|
137
139
|
end
|
138
140
|
|
139
|
-
def top_scores
|
141
|
+
def top_scores(opts)
|
140
142
|
best = []
|
141
143
|
@remotes.iterate(@log) do |r|
|
142
144
|
uri = '/'
|
@@ -145,7 +147,7 @@ Available options:"
|
|
145
147
|
json = JsonPage.new(res.body, uri).to_hash
|
146
148
|
score = Score.parse_json(json['score'])
|
147
149
|
r.assert_valid_score(score)
|
148
|
-
r.assert_score_strength(score)
|
150
|
+
r.assert_score_strength(score) unless opts['ignore-score-weakness']
|
149
151
|
r.assert_score_value(score, Tax::EXACT_SCORE)
|
150
152
|
@log.info("#{r}: #{Rainbow(score.value).green}")
|
151
153
|
best << score
|
data/lib/zold/copies.rb
CHANGED
@@ -24,6 +24,7 @@ require 'time'
|
|
24
24
|
require 'csv'
|
25
25
|
require_relative 'atomic_file'
|
26
26
|
require_relative 'log'
|
27
|
+
require_relative 'size'
|
27
28
|
require_relative 'wallet'
|
28
29
|
require_relative 'backtrace'
|
29
30
|
|
@@ -64,7 +65,7 @@ module Zold
|
|
64
65
|
file = File.join(@dir, f)
|
65
66
|
size = File.size(file)
|
66
67
|
File.delete(file)
|
67
|
-
@log.debug("Copy at #{f} deleted: #{size}
|
68
|
+
@log.debug("Copy at #{f} deleted: #{Size.new(size)}")
|
68
69
|
deleted += 1
|
69
70
|
end
|
70
71
|
files.each do |f|
|
@@ -23,6 +23,7 @@
|
|
23
23
|
require 'concurrent'
|
24
24
|
require_relative '../log'
|
25
25
|
require_relative '../age'
|
26
|
+
require_relative '../size'
|
26
27
|
require_relative '../id'
|
27
28
|
require_relative '../verbose_thread'
|
28
29
|
|
@@ -118,7 +119,7 @@ module Zold
|
|
118
119
|
return if id.empty? || body.empty?
|
119
120
|
start = Time.now
|
120
121
|
@entrance.push(Id.new(id), body)
|
121
|
-
@log.debug("Pushed #{id}/#{body.length}
|
122
|
+
@log.debug("Pushed #{id}/#{Size.new(body.length)} to #{@entrance.class.name} in #{Age.new(start)}")
|
122
123
|
end
|
123
124
|
|
124
125
|
def queue
|
data/lib/zold/node/front.rb
CHANGED
@@ -33,6 +33,7 @@ require 'usagewatch_ext'
|
|
33
33
|
require 'concurrent'
|
34
34
|
require_relative '../backtrace'
|
35
35
|
require_relative '../version'
|
36
|
+
require_relative '../size'
|
36
37
|
require_relative '../wallet'
|
37
38
|
require_relative '../copies'
|
38
39
|
require_relative '../log'
|
@@ -314,7 +315,7 @@ while #{settings.address} is in '#{settings.network}'"
|
|
314
315
|
copies.all.map do |c|
|
315
316
|
w = Wallet.new(c[:path])
|
316
317
|
"#{c[:name]}: #{c[:score]} #{w.balance}/#{w.txns.count}t/\
|
317
|
-
#{w.digest[0, 6]}/#{File.size(c[:path])}
|
318
|
+
#{w.digest[0, 6]}/#{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}"
|
318
319
|
end.join("\n")
|
319
320
|
end
|
320
321
|
end
|
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
require 'tempfile'
|
24
24
|
require_relative '../log'
|
25
|
+
require_relative '../size'
|
25
26
|
require_relative '../wallet'
|
26
27
|
require_relative '../atomic_file'
|
27
28
|
|
@@ -63,10 +64,14 @@ module Zold
|
|
63
64
|
w.exists? ? AtomicFile.new(w.path).read.to_s : ''
|
64
65
|
end
|
65
66
|
if before == after
|
66
|
-
@log.info(
|
67
|
+
@log.info(
|
68
|
+
"Duplicate of #{id}/#{wallet.digest[0, 6]}/#{Size.new(after.length)}/#{wallet.txns.count}t ignored"
|
69
|
+
)
|
67
70
|
return []
|
68
71
|
end
|
69
|
-
@log.info(
|
72
|
+
@log.info(
|
73
|
+
"New content for #{id} arrived, #{Size.new(before.length)} before and #{Size.new(after.length)} after"
|
74
|
+
)
|
70
75
|
@entrance.push(id, body)
|
71
76
|
end
|
72
77
|
end
|
data/lib/zold/score.rb
CHANGED
@@ -34,7 +34,7 @@ module Zold
|
|
34
34
|
# Default strength for the entire system, in production mode.
|
35
35
|
STRENGTH = 6
|
36
36
|
|
37
|
-
attribute :time, Types::Strict::Time
|
37
|
+
attribute :time, Types::Strict::Time.optional.default(Time.now)
|
38
38
|
attribute :host, Types::Strict::String.constrained(
|
39
39
|
format: /^[a-z0-9\.-]+$/
|
40
40
|
)
|
data/lib/zold/size.rb
ADDED
@@ -0,0 +1,49 @@
|
|
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 'time'
|
24
|
+
|
25
|
+
# Size in bytes.
|
26
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
28
|
+
# License:: MIT
|
29
|
+
module Zold
|
30
|
+
# Size
|
31
|
+
class Size
|
32
|
+
def initialize(bytes)
|
33
|
+
@bytes = bytes
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
return '?' if @bytes.nil?
|
38
|
+
if @bytes < 1024
|
39
|
+
"#{@bytes}b"
|
40
|
+
elsif @bytes < 1024 * 1024
|
41
|
+
"#{(@bytes / 1024).round}Kb"
|
42
|
+
elsif @bytes < 1024 * 1024 * 1024
|
43
|
+
"#{(@bytes / (1024 * 1024)).round}Mb"
|
44
|
+
else
|
45
|
+
"#{(@bytes / (1024 * 1024 * 1024)).round}Gb"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/zold/tax.rb
CHANGED
@@ -67,8 +67,7 @@ module Zold
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def pay(pvt, best)
|
70
|
-
|
71
|
-
@wallet.sub(fee, best.invoice, pvt, details(best))
|
70
|
+
@wallet.sub(Tax::MAX_PAYMENT, best.invoice, pvt, details(best))
|
72
71
|
end
|
73
72
|
|
74
73
|
def in_debt?
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallet.rb
CHANGED
@@ -132,8 +132,8 @@ module Zold
|
|
132
132
|
raise 'The txn has to be of type Txn' unless txn.is_a?(Txn)
|
133
133
|
dup = txns.find { |t| t.bnf == txn.bnf && t.id == txn.id }
|
134
134
|
raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id
|
135
|
-
raise "The transaction with the same ID and BNF already exists: #{dup}" unless dup.nil?
|
136
|
-
raise "The tax payment already exists: #{txn}" if Tax.new(self).exists?(txn)
|
135
|
+
raise "The transaction with the same ID and BNF already exists in #{id}: #{dup}" unless dup.nil?
|
136
|
+
raise "The tax payment already exists in #{id}: #{txn}" if Tax.new(self).exists?(txn)
|
137
137
|
File.open(@file, 'a') { |f| f.print "#{txn}\n" }
|
138
138
|
@txns.flush
|
139
139
|
end
|
data/test/commands/test_taxes.rb
CHANGED
@@ -44,24 +44,25 @@ class TestTaxes < Minitest::Test
|
|
44
44
|
wallet.add(
|
45
45
|
Zold::Txn.new(
|
46
46
|
1,
|
47
|
-
Time.now - 24 * 60 * 60 * 365 *
|
47
|
+
Time.now - 24 * 60 * 60 * 365 * 300,
|
48
48
|
Zold::Amount.new(zld: 19.99),
|
49
49
|
'NOPREFIX', Zold::Id.new, '-'
|
50
50
|
)
|
51
51
|
)
|
52
52
|
remotes = home.remotes
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
score = Zold::Score.new(host: 'localhost', port: 80, strength: 1, invoice: 'NOPREFIX@0000000000000000')
|
54
|
+
Zold::Tax::EXACT_SCORE.times { score = score.next }
|
55
|
+
remotes.add(score.host, score.port)
|
56
|
+
stub_request(:get, "http://#{score.host}:#{score.port}/").to_return(
|
56
57
|
status: 200,
|
57
58
|
body: {
|
58
|
-
score:
|
59
|
+
score: score.to_h
|
59
60
|
}.to_json
|
60
61
|
)
|
61
|
-
Zold::Taxes.new(
|
62
|
-
|
63
|
-
)
|
64
|
-
assert_equal(Zold::Amount.new(coins:
|
62
|
+
Zold::Taxes.new(wallets: wallets, remotes: remotes, log: test_log).run(
|
63
|
+
['taxes', '--private-key=fixtures/id_rsa', '--ignore-score-weakness', 'pay', wallet.id.to_s]
|
64
|
+
)
|
65
|
+
assert_equal(Zold::Amount.new(coins: 81_561_428_951), wallet.balance)
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
data/test/test_age.rb
ADDED
@@ -0,0 +1,37 @@
|
|
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 '../lib/zold/age'
|
25
|
+
|
26
|
+
# Age test.
|
27
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
29
|
+
# License:: MIT
|
30
|
+
class TestAge < Minitest::Test
|
31
|
+
def test_prints_age
|
32
|
+
assert_equal('10m', Zold::Age.new(Time.now - 10 * 60).to_s)
|
33
|
+
assert_equal('5.5s', Zold::Age.new(Time.now - 5.5).to_s)
|
34
|
+
assert_equal('?', Zold::Age.new(nil).to_s)
|
35
|
+
assert(!Zold::Age.new(Time.now.utc.iso8601).to_s.nil?)
|
36
|
+
end
|
37
|
+
end
|
data/test/test_size.rb
ADDED
@@ -0,0 +1,38 @@
|
|
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 '../lib/zold/size'
|
25
|
+
|
26
|
+
# Size test.
|
27
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
29
|
+
# License:: MIT
|
30
|
+
class TestSize < Minitest::Test
|
31
|
+
def test_prints_size
|
32
|
+
assert_equal('?', Zold::Size.new(nil).to_s)
|
33
|
+
assert_equal('10b', Zold::Size.new(10).to_s)
|
34
|
+
assert_equal('2Kb', Zold::Size.new(2 * 1024).to_s)
|
35
|
+
assert_equal('9Mb', Zold::Size.new(9 * 1024 * 1024).to_s)
|
36
|
+
assert_equal('7Gb', Zold::Size.new(7 * 1024 * 1024 * 1024).to_s)
|
37
|
+
end
|
38
|
+
end
|
data/test/test_tax.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -525,6 +525,7 @@ files:
|
|
525
525
|
- lib/zold/remotes.rb
|
526
526
|
- lib/zold/score.rb
|
527
527
|
- lib/zold/signature.rb
|
528
|
+
- lib/zold/size.rb
|
528
529
|
- lib/zold/sync_wallets.rb
|
529
530
|
- lib/zold/tax.rb
|
530
531
|
- lib/zold/tree_wallets.rb
|
@@ -571,6 +572,7 @@ files:
|
|
571
572
|
- test/node/test_sync_entrance.rb
|
572
573
|
- test/node/test_trace.rb
|
573
574
|
- test/test__helper.rb
|
575
|
+
- test/test_age.rb
|
574
576
|
- test/test_amount.rb
|
575
577
|
- test/test_atomic_file.rb
|
576
578
|
- test/test_backtrace.rb
|
@@ -587,6 +589,7 @@ files:
|
|
587
589
|
- test/test_remotes.rb
|
588
590
|
- test/test_score.rb
|
589
591
|
- test/test_signature.rb
|
592
|
+
- test/test_size.rb
|
590
593
|
- test/test_sync_wallets.rb
|
591
594
|
- test/test_tax.rb
|
592
595
|
- test/test_tree_wallets.rb
|
@@ -667,6 +670,7 @@ test_files:
|
|
667
670
|
- test/node/test_sync_entrance.rb
|
668
671
|
- test/node/test_trace.rb
|
669
672
|
- test/test__helper.rb
|
673
|
+
- test/test_age.rb
|
670
674
|
- test/test_amount.rb
|
671
675
|
- test/test_atomic_file.rb
|
672
676
|
- test/test_backtrace.rb
|
@@ -683,6 +687,7 @@ test_files:
|
|
683
687
|
- test/test_remotes.rb
|
684
688
|
- test/test_score.rb
|
685
689
|
- test/test_signature.rb
|
690
|
+
- test/test_size.rb
|
686
691
|
- test/test_sync_wallets.rb
|
687
692
|
- test/test_tax.rb
|
688
693
|
- test/test_tree_wallets.rb
|