zold 0.16.7 → 0.16.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a325af91de87bc2bd544f5d92a908eff34f4f114a88fa4cb9248ef286bff9404
4
- data.tar.gz: 6e4fd9790fdcf55a23c206e60635c8fe6d45ad83eee4194697989b1f6bf5e51f
3
+ metadata.gz: 1399da979b61a827097b2b29a04b31920f6da3a65e2af8920fc493bbb52064ba
4
+ data.tar.gz: 255d50d0c687709e5b15f1ce1fc17eec7ab656b24a7c8356aec320d8620d911c
5
5
  SHA512:
6
- metadata.gz: e827fbbefda31c28ad0fe24f23d5694d94997123f5163080a38ca8eee92c2048d4a0245b640896dab6210da8d2f22ac6dc325e3efe962b76cf3a714608534abe
7
- data.tar.gz: 41ab159b3f635916fbb289384796e2fe5000aba409e86180248ec2903c684c86bd42642b357dd6e6d34b65b903df6648b4eda4938683cc9850880e3aaac0230a
6
+ metadata.gz: acf61ff6782dcb26a24f17f2f208cf64d7110c1204ccb048240433541c99978f298f21de0c96974aa7c67321acf800131e80a518d5eef37709c714e7642c1c41
7
+ data.tar.gz: d0816cade1db2f054b08a321aa7bde96a6af4eb3beb8ea42d54ba3d66b88c254464d48809e3a7e1fca80a155653420f21c779f93a2db1b7c255b38e652448187
data/bin/zold CHANGED
@@ -23,11 +23,7 @@
23
23
 
24
24
  STDOUT.sync = true
25
25
 
26
- unless Gem.win_platform?
27
- # For debug in production, see https://github.com/frsyuki/sigdump
28
- ENV['SIGDUMP_PATH'] = File.join(Dir.pwd, "sigdump-#{Process.pid}.log")
29
- require 'sigdump/setup'
30
- end
26
+ start = Time.now
31
27
 
32
28
  require 'slop'
33
29
  require 'rainbow'
@@ -40,6 +36,7 @@ require_relative '../lib/zold/sync_wallets'
40
36
  require_relative '../lib/zold/cached_wallets'
41
37
  require_relative '../lib/zold/log'
42
38
  require_relative '../lib/zold/key'
39
+ require_relative '../lib/zold/age'
43
40
  require_relative '../lib/zold/amount'
44
41
  require_relative '../lib/zold/copies'
45
42
  require_relative '../lib/zold/remotes'
@@ -60,9 +57,6 @@ unless ENV['RACK_ENV'] == 'test' || ARGV.find { |a| a == '--ignore-global-config
60
57
  body = IO.read(config)
61
58
  extra = body.split(/[\r\n]+/).map(&:strip)
62
59
  args += extra
63
- log.debug("Found #{body.split(/\n/).length} lines in #{config}")
64
- else
65
- log.debug("Default config file #{config} not found")
66
60
  end
67
61
  end
68
62
  args += ARGV
@@ -131,6 +125,8 @@ Available options:"
131
125
 
132
126
  log = Zold::Log::Sync.new(log)
133
127
 
128
+ log.debug("Gem location: #{File.dirname(File.dirname(__FILE__))}")
129
+
134
130
  commands = opts.arguments.reject { |a| a.start_with?('-') }
135
131
  command = commands[0]
136
132
 
@@ -147,6 +143,7 @@ Available options:"
147
143
  home = File.expand_path(opts[:home])
148
144
  FileUtils.mkdir_p(home)
149
145
  Dir.chdir(home)
146
+ log.debug("Home directory: #{home}")
150
147
 
151
148
  zoldata = File.join(home, '.zoldata')
152
149
 
@@ -175,10 +172,15 @@ Available options:"
175
172
  )
176
173
  fremotes = File.join(zoldata, 'remotes')
177
174
  remotes = Zold::Remotes.new(file: fremotes, network: opts['network'])
178
- remotes.defaults unless File.exist?(fremotes)
175
+ if File.exist?(fremotes)
176
+ log.debug("Remote nodes: #{remotes.all.count} total")
177
+ else
178
+ remotes.defaults
179
+ log.debug("Default remotes have been set: #{remotes.all.count} total")
180
+ end
179
181
  copies = File.join(zoldata, 'copies')
180
182
 
181
- log.debug("Network: #{opts['network']}")
183
+ log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAIN_NETWORK ? 'main' : 'test'} net)")
182
184
 
183
185
  case command
184
186
  when 'node'
@@ -246,3 +248,5 @@ rescue StandardError => ex
246
248
  puts(ex.backtrace) if opts['trace']
247
249
  exit -1
248
250
  end
251
+
252
+ log.debug("Successfully finished in #{Zold::Age.new(start)}")
@@ -19,7 +19,7 @@ function wait_for_url {
19
19
  echo "URL $1 is not available after ${i} attempts"
20
20
  exit 12
21
21
  fi
22
- sleep 5
22
+ sleep 2
23
23
  done
24
24
  }
25
25
 
@@ -31,7 +31,7 @@ function wait_for_port {
31
31
  echo "Port $1 is not available after ${i} attempts"
32
32
  exit 13
33
33
  fi
34
- sleep 5
34
+ sleep 2
35
35
  done
36
36
  }
37
37
 
@@ -43,7 +43,7 @@ function wait_for_file {
43
43
  echo "File $1 not found, giving up after ${i} attempts"
44
44
  exit 14
45
45
  fi
46
- sleep 5
46
+ sleep 2
47
47
  done
48
48
  }
49
49
 
@@ -59,7 +59,7 @@ function halt_nodes {
59
59
  exit 15
60
60
  fi
61
61
  echo "Still waiting for process ${pid} to die, attempt no.${i}"
62
- sleep 5
62
+ sleep 2
63
63
  done
64
64
  echo "Process ${pid} is dead!"
65
65
  fi
@@ -53,7 +53,7 @@ until zold fetch 0000000000000000 --ignore-score-weakness; do
53
53
  echo "The wallet has not been distributed, after ${i} attempts"
54
54
  exit 9
55
55
  fi
56
- sleep 5
56
+ sleep 2
57
57
  done
58
58
 
59
59
  # Here we check the JSON of the first node to make sure all status
@@ -81,6 +81,6 @@ until zold fetch 0000000000000000 --ignore-score-weakness; do
81
81
  cat ${first}/log.txt
82
82
  exit 8
83
83
  fi
84
- sleep 5
84
+ sleep 2
85
85
  done
86
86
 
data/lib/zold/amount.rb CHANGED
@@ -35,28 +35,28 @@ module Zold
35
35
  # Maximum amount of zents
36
36
  MAX = 2**63
37
37
 
38
- def initialize(coins: nil, zld: nil)
39
- if !coins.nil?
40
- raise "Integer is required, while #{coins.class} provided: #{coins}" unless coins.is_a?(Integer)
41
- @coins = coins
38
+ def initialize(zents: nil, zld: nil)
39
+ if !zents.nil?
40
+ raise "Integer is required, while #{zents.class} provided: #{zents}" unless zents.is_a?(Integer)
41
+ @zents = zents
42
42
  elsif !zld.nil?
43
43
  raise "Float is required, while #{zld.class} provided: #{zld}" unless zld.is_a?(Float)
44
- @coins = (zld * 2**Amount::FRACTION).to_i
44
+ @zents = (zld * 2**Amount::FRACTION).to_i
45
45
  else
46
46
  raise 'You can\'t specify both coints and zld'
47
47
  end
48
- raise "The amount is too big: #{@coins}" if @coins > Amount::MAX
49
- raise "The amount is too small: #{@coins}" if @coins < -Amount::MAX
48
+ raise "The amount is too big: #{@zents}" if @zents > Amount::MAX
49
+ raise "The amount is too small: #{@zents}" if @zents < -Amount::MAX
50
50
  end
51
51
 
52
- ZERO = Amount.new(coins: 0)
52
+ ZERO = Amount.new(zents: 0)
53
53
 
54
54
  def to_i
55
- @coins
55
+ @zents
56
56
  end
57
57
 
58
58
  def to_zld(digits = 2)
59
- format("%0.#{digits}f", @coins.to_f / 2**Amount::FRACTION)
59
+ format("%0.#{digits}f", @zents.to_f / 2**Amount::FRACTION)
60
60
  end
61
61
 
62
62
  def to_s
@@ -72,61 +72,61 @@ module Zold
72
72
 
73
73
  def ==(other)
74
74
  raise "== may only work with Amount: #{other}" unless other.is_a?(Amount)
75
- @coins == other.to_i
75
+ @zents == other.to_i
76
76
  end
77
77
 
78
78
  def >(other)
79
79
  raise '> may only work with Amount' unless other.is_a?(Amount)
80
- @coins > other.to_i
80
+ @zents > other.to_i
81
81
  end
82
82
 
83
83
  def <(other)
84
84
  raise '< may only work with Amount' unless other.is_a?(Amount)
85
- @coins < other.to_i
85
+ @zents < other.to_i
86
86
  end
87
87
 
88
88
  def <=(other)
89
89
  raise '<= may only work with Amount' unless other.is_a?(Amount)
90
- @coins <= other.to_i
90
+ @zents <= other.to_i
91
91
  end
92
92
 
93
93
  def <=>(other)
94
94
  raise '<= may only work with Amount' unless other.is_a?(Amount)
95
- @coins <=> other.to_i
95
+ @zents <=> other.to_i
96
96
  end
97
97
 
98
98
  def +(other)
99
99
  raise '+ may only work with Amount' unless other.is_a?(Amount)
100
- Amount.new(coins: @coins + other.to_i)
100
+ Amount.new(zents: @zents + other.to_i)
101
101
  end
102
102
 
103
103
  def -(other)
104
104
  raise '- may only work with Amount' unless other.is_a?(Amount)
105
- Amount.new(coins: @coins - other.to_i)
105
+ Amount.new(zents: @zents - other.to_i)
106
106
  end
107
107
 
108
108
  def zero?
109
- @coins.zero?
109
+ @zents.zero?
110
110
  end
111
111
 
112
112
  def negative?
113
- @coins.negative?
113
+ @zents.negative?
114
114
  end
115
115
 
116
116
  def positive?
117
- @coins.positive?
117
+ @zents.positive?
118
118
  end
119
119
 
120
120
  def *(other)
121
121
  raise '* may only work with a number' unless other.is_a?(Integer) || other.is_a?(Float)
122
- c = (@coins * other).to_i
123
- raise "Overflow, can't multiply #{@coins} by #{m}" if c > Amount::MAX
124
- Amount.new(coins: c)
122
+ c = (@zents * other).to_i
123
+ raise "Overflow, can't multiply #{@zents} by #{m}" if c > Amount::MAX
124
+ Amount.new(zents: c)
125
125
  end
126
126
 
127
127
  def /(other)
128
128
  raise '/ may only work with a number' unless other.is_a?(Integer) || other.is_a?(Float)
129
- Amount.new(coins: (@coins / other).to_i)
129
+ Amount.new(zents: (@zents / other).to_i)
130
130
  end
131
131
  end
132
132
  end
@@ -114,18 +114,26 @@ Available options:"
114
114
  def pay(wallet, opts)
115
115
  raise 'The wallet is absent' unless wallet.exists?
116
116
  tax = Tax.new(wallet)
117
- debt = tax.debt
117
+ debt = total = tax.debt
118
118
  @log.info("The current debt of #{wallet.id}/#{wallet.txns.count}t is #{debt} (#{debt.to_i} zents), \
119
119
  the balance is #{wallet.balance}: #{tax.to_text}")
120
120
  unless tax.in_debt?
121
121
  @log.debug("No need to pay taxes yet, while the debt is less than #{Tax::TRIAL} (#{Tax::TRIAL.to_i} zents)")
122
122
  return
123
123
  end
124
- top = top_scores(opts)
124
+ top = everybody = top_scores(opts)
125
+ paid = 0
125
126
  while debt > Tax::TRIAL
126
127
  if top.empty?
127
- raise 'No acceptable remote nodes, try later' unless opts['ignore-nodes-absence']
128
- @log.info('Not enough strong nodes in the network, try later')
128
+ msg = [
129
+ "There were #{everybody.count} remote nodes as tax collecting candidates;",
130
+ "#{paid} payments have been made",
131
+ "there was not enough score power to pay the total debt of #{total} for #{wallet.id};",
132
+ "the residual amount to pay is #{debt} (trial amount is #{Tax::TRIAL});",
133
+ "the formula ingredients are #{tax.to_text}"
134
+ ].join(' ')
135
+ raise msg unless opts['ignore-nodes-absence']
136
+ @log.info(msg)
129
137
  break
130
138
  end
131
139
  best = top.shift
@@ -135,7 +143,8 @@ the balance is #{wallet.balance}: #{tax.to_text}")
135
143
  end
136
144
  txn = tax.pay(Zold::Key.new(file: opts['private-key']), best)
137
145
  debt += txn.amount
138
- @log.info("#{txn.amount} of taxes paid to #{txn.bnf}, #{debt} left to pay")
146
+ paid += 1
147
+ @log.info("#{txn.amount} of taxes paid to #{txn.bnf} (payment no.#{paid}), #{debt} left to pay")
139
148
  end
140
149
  @log.info('The wallet is in good standing, all taxes paid') unless tax.in_debt?
141
150
  end
@@ -144,6 +153,8 @@ the balance is #{wallet.balance}: #{tax.to_text}")
144
153
  raise 'The wallet is absent' unless wallet.exists?
145
154
  tax = Tax.new(wallet)
146
155
  @log.info(tax.debt)
156
+ @log.debug(tax.to_text)
157
+ @log.debug('Read the White Paper for more details: https://papers.zold.io/wp.pdf')
147
158
  end
148
159
 
149
160
  def show(_, _)
data/lib/zold/http.rb CHANGED
@@ -55,7 +55,7 @@ module Zold
55
55
  PROTOCOL_HEADER = 'X-Zold-Protocol'
56
56
 
57
57
  # Read timeout in seconds
58
- READ_TIMEOUT = 4
58
+ READ_TIMEOUT = 32
59
59
 
60
60
  # Connect timeout in seconds
61
61
  CONNECT_TIMEOUT = 4
@@ -48,7 +48,7 @@ module Zold
48
48
 
49
49
  def limit
50
50
  max = Amount::MAX
51
- Amount.new(coins: (max * quota).to_i)
51
+ Amount.new(zents: (max * quota).to_i)
52
52
  end
53
53
 
54
54
  def check
@@ -31,6 +31,7 @@ require 'diffy'
31
31
  require 'usagewatch_ext'
32
32
  require 'concurrent'
33
33
  require 'backtrace'
34
+ require 'zache'
34
35
  require_relative '../version'
35
36
  require_relative '../size'
36
37
  require_relative '../wallet'
@@ -39,7 +40,6 @@ require_relative '../copies'
39
40
  require_relative '../log'
40
41
  require_relative '../id'
41
42
  require_relative '../http'
42
- require_relative '../cache'
43
43
 
44
44
  # The web front of the node.
45
45
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -77,7 +77,7 @@ module Zold
77
77
  set :remotes, nil? # to be injected at node.rb
78
78
  set :copies, nil? # to be injected at node.rb
79
79
  set :node_alias, nil? # to be injected at node.rb
80
- set :cache, Cache.new
80
+ set :zache, Zache.new
81
81
  end
82
82
  use Rack::Deflater
83
83
 
@@ -187,10 +187,10 @@ in #{Age.new(@start, limit: 1)}")
187
187
  protocol: settings.protocol,
188
188
  score: score.to_h,
189
189
  pid: Process.pid,
190
- cpus: settings.cache.get(:cpus) { Concurrent.processor_count },
190
+ cpus: settings.zache.get(:cpus) { Concurrent.processor_count },
191
191
  memory: GetProcessMem.new.bytes.to_i,
192
192
  platform: RUBY_PLATFORM,
193
- load: settings.cache.get(:load, lifetime: 5 * 60) { Usagewatch.uw_load.to_f },
193
+ load: settings.zache.get(:load, lifetime: 5 * 60) { Usagewatch.uw_load.to_f },
194
194
  threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
195
195
  wallets: total_wallets,
196
196
  remotes: all_remotes.count,
@@ -435,13 +435,13 @@ in #{Age.new(@start, limit: 1)}")
435
435
  end
436
436
 
437
437
  def all_remotes
438
- settings.cache.get(:remotes, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
438
+ settings.zache.get(:remotes, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
439
439
  settings.remotes.all
440
440
  end
441
441
  end
442
442
 
443
443
  def score
444
- settings.cache.get(:score, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
444
+ settings.zache.get(:score, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
445
445
  b = settings.farm.best
446
446
  raise 'Score is empty, there is something wrong with the Farm!' if b.empty?
447
447
  b[0]
data/lib/zold/patch.rb CHANGED
@@ -84,7 +84,7 @@ module Zold
84
84
  balance = @txns.map(&:amount).map(&:to_i).inject(&:+).to_i
85
85
  if balance < txn.amount.to_i * -1 && !wallet.root?
86
86
  @log.error("Transaction ##{txn.id} attempts to make the balance of \
87
- #{wallet.id}/#{Amount.new(coins: balance).to_zld}/#{@txns.size} negative: #{txn.to_text}")
87
+ #{wallet.id}/#{Amount.new(zents: balance).to_zld}/#{@txns.size} negative: #{txn.to_text}")
88
88
  next
89
89
  end
90
90
  unless Signature.new.valid?(@key, wallet.id, txn)
data/lib/zold/tax.rb CHANGED
@@ -45,7 +45,9 @@ module Zold
45
45
  # This is how much we charge per one transaction per hour
46
46
  # of storage. A wallet of 4096 transactions will pay
47
47
  # approximately 16ZLD per year.
48
- FEE_TXN_HOUR = Amount.new(zld: 16.0 / (365 * 24) / 4096)
48
+ # Here is the formula: 16.0 / (365 * 24) / 4096 = 1915
49
+ # But I like the 1917 number better.
50
+ FEE = Amount.new(zents: 1917)
49
51
 
50
52
  # The maximum debt we can tolerate at the wallet. If the debt
51
53
  # is bigger than this threshold, nodes must stop accepting PUSH.
@@ -77,10 +79,14 @@ module Zold
77
79
  end
78
80
 
79
81
  def to_text
80
- "A=#{@wallet.age}, F=#{Tax::FEE_TXN_HOUR}, T=#{@wallet.txns.count}"
82
+ "A=#{@wallet.age.round} hours, F=#{Tax::FEE.to_i}z/th, T=#{@wallet.txns.count}t, Paid=#{paid}"
81
83
  end
82
84
 
83
85
  def debt
86
+ Tax::FEE * @wallet.txns.count * @wallet.age - paid
87
+ end
88
+
89
+ def paid
84
90
  txns = @wallet.txns
85
91
  scored = txns.map do |t|
86
92
  pfx, body = t.details.split(' ', 2)
@@ -91,9 +97,7 @@ module Zold
91
97
  next if t.amount > Tax::MAX_PAYMENT
92
98
  t
93
99
  end.compact.uniq(&:details)
94
- paid = scored.empty? ? Amount::ZERO : scored.map(&:amount).inject(&:+)
95
- owned = Tax::FEE_TXN_HOUR * txns.count * @wallet.age
96
- owned - paid
100
+ scored.empty? ? Amount::ZERO : scored.map(&:amount).inject(&:+)
97
101
  end
98
102
  end
99
103
  end
data/lib/zold/txn.rb CHANGED
@@ -133,7 +133,7 @@ module Zold
133
133
  txn = Txn.new(
134
134
  Hexnum.parse(parts[:id]).to_i,
135
135
  Time.parse(parts[:date]),
136
- Amount.new(coins: Hexnum.parse(parts[:amount]).to_i),
136
+ Amount.new(zents: Hexnum.parse(parts[:amount]).to_i),
137
137
  parts[:prefix],
138
138
  Id.new(parts[:bnf]),
139
139
  parts[:details]
data/lib/zold/version.rb CHANGED
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.16.7'
28
+ VERSION = '0.16.8'
29
29
  PROTOCOL = 2
30
30
  end
@@ -326,7 +326,7 @@ class FrontTest < Minitest::Test
326
326
  assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code }
327
327
  cycles = 50
328
328
  cycles.times do
329
- wallet.sub(Zold::Amount.new(coins: 10), "NOPREFIX@#{Zold::Id.new}", key)
329
+ wallet.sub(Zold::Amount.new(zents: 10), "NOPREFIX@#{Zold::Id.new}", key)
330
330
  Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
331
331
  assert_equal('200', Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code)
332
332
  end
data/test/test_amount.rb CHANGED
@@ -52,8 +52,8 @@ class TestAmount < Minitest::Test
52
52
  assert(amount != Zold::Amount::ZERO)
53
53
  end
54
54
 
55
- def test_parses_coins
56
- amount = Zold::Amount.new(coins: 900_000_000)
55
+ def test_parses_zents
56
+ amount = Zold::Amount.new(zents: 900_000_000)
57
57
  assert(
58
58
  amount.to_s.include?('0.21ZLD'),
59
59
  "#{amount} is not equal to '0.21ZLD'"
@@ -61,7 +61,7 @@ class TestAmount < Minitest::Test
61
61
  end
62
62
 
63
63
  def test_compares_amounts
64
- amount = Zold::Amount.new(coins: 700_000_000)
64
+ amount = Zold::Amount.new(zents: 700_000_000)
65
65
  assert(
66
66
  amount > Zold::Amount::ZERO,
67
67
  "#{amount} is not greater than zero"
data/test/test_tax.rb CHANGED
@@ -39,23 +39,23 @@ require_relative '../lib/zold/score'
39
39
  # License:: MIT
40
40
  class TestTax < Minitest::Test
41
41
  def test_print_fee
42
- test_log.info("Fee in zents: #{Zold::Tax::FEE_TXN_HOUR.to_i}")
42
+ test_log.info("Fee in zents: #{Zold::Tax::FEE.to_i}")
43
43
  end
44
44
 
45
45
  def test_calculates_tax_for_one_year
46
46
  FakeHome.new(log: test_log).run do |home|
47
47
  wallet = home.create_wallet
48
+ a = 10_000
48
49
  wallet.add(
49
50
  Zold::Txn.new(
50
51
  1,
51
- Time.now - 24 * 60 * 60 * 365,
52
+ Time.now - a * 60 * 60,
52
53
  Zold::Amount.new(zld: 19.99),
53
54
  'NOPREFIX', Zold::Id.new, '-'
54
55
  )
55
56
  )
56
57
  tax = Zold::Tax.new(wallet)
57
- assert(tax.debt > Zold::Amount.new(coins: 16_770_000))
58
- assert(tax.debt < Zold::Amount.new(coins: 16_790_000))
58
+ assert_equal(Zold::Tax::FEE * a, tax.debt, tax.to_text)
59
59
  end
60
60
  end
61
61
 
@@ -97,7 +97,7 @@ class TestTax < Minitest::Test
97
97
  Zold::Txn.new(
98
98
  1,
99
99
  Time.now,
100
- Zold::Amount.new(coins: 95_596_800),
100
+ Zold::Amount.new(zents: 95_596_800),
101
101
  'NOPREFIX', Zold::Id.new('912ecc24b32dbe74'),
102
102
  "TAXES 6 5b5a21a9 b2.zold.io 1000 DCexx0hG 912ecc24b32dbe74 \
103
103
  386d4a ec9eae 306e3d 119d073 1c00dba 1376703 203589 5b55f7"
data/test/test_wallet.rb CHANGED
@@ -132,10 +132,10 @@ class TestWallet < Minitest::Test
132
132
  wallet = home.create_wallet
133
133
  time = Time.now
134
134
  key = Zold::Key.new(file: 'fixtures/id_rsa')
135
- wallet.add(Zold::Txn.new(1, time, Zold::Amount.new(coins: 1), 'NOPREFIX', Zold::Id.new, '-'))
136
- wallet.sub(Zold::Amount.new(coins: 2), "NOPREFIX@#{Zold::Id.new}", key, time: time)
137
- wallet.add(Zold::Txn.new(2, time, Zold::Amount.new(coins: 3), 'NOPREFIX', Zold::Id.new, '-'))
138
- wallet.sub(Zold::Amount.new(coins: 4), "NOPREFIX@#{Zold::Id.new}", key, time: time)
135
+ wallet.add(Zold::Txn.new(1, time, Zold::Amount.new(zents: 1), 'NOPREFIX', Zold::Id.new, '-'))
136
+ wallet.sub(Zold::Amount.new(zents: 2), "NOPREFIX@#{Zold::Id.new}", key, time: time)
137
+ wallet.add(Zold::Txn.new(2, time, Zold::Amount.new(zents: 3), 'NOPREFIX', Zold::Id.new, '-'))
138
+ wallet.sub(Zold::Amount.new(zents: 4), "NOPREFIX@#{Zold::Id.new}", key, time: time)
139
139
  assert_equal('3, 1, -2, -4', wallet.txns.map(&:amount).map(&:to_i).join(', '))
140
140
  end
141
141
  end
@@ -219,7 +219,7 @@ class TestWallet < Minitest::Test
219
219
  sum += t.amount
220
220
  end
221
221
  assert(
222
- sum == Zold::Amount.new(coins: 235_965_503_242),
222
+ sum == Zold::Amount.new(zents: 235_965_503_242),
223
223
  "#{sum} (#{sum.to_i}) is not equal to #{Zold::Amount.new(zld: 54.94)}"
224
224
  )
225
225
  end
data/test/test_zold.rb CHANGED
@@ -35,6 +35,8 @@ class TestZold < Minitest::Test
35
35
  def test_all_scripts
36
36
  Dir.new('fixtures/scripts').select { |f| f =~ /\.sh$/ && !f.start_with?('_') }.each do |f|
37
37
  # next unless f == 'push-and-pull.sh'
38
+ start = Time.now
39
+ test_log.debug("\n\n#{f} running...")
38
40
  Dir.mktmpdir do |dir|
39
41
  FileUtils.cp('fixtures/id_rsa.pub', dir)
40
42
  FileUtils.cp('fixtures/id_rsa', dir)
@@ -55,6 +57,7 @@ class TestZold < Minitest::Test
55
57
  end
56
58
  end
57
59
  end
60
+ test_log.debug("\n\n#{f} done in #{Zold::Age.new(start)}")
58
61
  end
59
62
  end
60
63
 
data/zold.gemspec CHANGED
@@ -68,7 +68,6 @@ and suggests a different architecture for digital wallet maintenance.'
68
68
  s.add_runtime_dependency 'rubocop', '0.58.1' # has to stay here for Heroku
69
69
  s.add_runtime_dependency 'rubocop-rspec', '~>1' # has to stay here for Heroku
70
70
  s.add_runtime_dependency 'semantic', '~>1'
71
- s.add_runtime_dependency 'sigdump', '~>0'
72
71
  s.add_runtime_dependency 'sinatra', '~>2'
73
72
  s.add_runtime_dependency 'slop', '~>4'
74
73
  s.add_runtime_dependency 'sys-proctable', '~>1'
@@ -76,6 +75,7 @@ and suggests a different architecture for digital wallet maintenance.'
76
75
  s.add_runtime_dependency 'threads', '~>0'
77
76
  s.add_runtime_dependency 'usagewatch_ext', '~>0'
78
77
  s.add_runtime_dependency 'xcop', '~>0'
78
+ s.add_runtime_dependency 'zache', '~>0'
79
79
  s.add_development_dependency 'codecov', '~>0'
80
80
  s.add_development_dependency 'minitest', '~>5'
81
81
  s.add_development_dependency 'random-port', '~>0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.7
4
+ version: 0.16.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -206,20 +206,6 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: '1'
209
- - !ruby/object:Gem::Dependency
210
- name: sigdump
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :runtime
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: '0'
223
209
  - !ruby/object:Gem::Dependency
224
210
  name: sinatra
225
211
  requirement: !ruby/object:Gem::Requirement
@@ -318,6 +304,20 @@ dependencies:
318
304
  - - "~>"
319
305
  - !ruby/object:Gem::Version
320
306
  version: '0'
307
+ - !ruby/object:Gem::Dependency
308
+ name: zache
309
+ requirement: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - "~>"
312
+ - !ruby/object:Gem::Version
313
+ version: '0'
314
+ type: :runtime
315
+ prerelease: false
316
+ version_requirements: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - "~>"
319
+ - !ruby/object:Gem::Version
320
+ version: '0'
321
321
  - !ruby/object:Gem::Dependency
322
322
  name: codecov
323
323
  requirement: !ruby/object:Gem::Requirement
@@ -482,13 +482,11 @@ files:
482
482
  - fixtures/scripts/pull-on-start.sh
483
483
  - fixtures/scripts/push-and-pull.sh
484
484
  - fixtures/scripts/redeploy-on-upgrade.sh
485
- - fixtures/scripts/sigdump.sh
486
485
  - fixtures/scripts/spread-wallets.sh
487
486
  - heroku-run.sh
488
487
  - lib/zold.rb
489
488
  - lib/zold/age.rb
490
489
  - lib/zold/amount.rb
491
- - lib/zold/cache.rb
492
490
  - lib/zold/cached_wallets.rb
493
491
  - lib/zold/commands/alias.rb
494
492
  - lib/zold/commands/args.rb
@@ -590,7 +588,6 @@ files:
590
588
  - test/test__helper.rb
591
589
  - test/test_age.rb
592
590
  - test/test_amount.rb
593
- - test/test_cache.rb
594
591
  - test/test_cached_wallets.rb
595
592
  - test/test_copies.rb
596
593
  - test/test_dir_items.rb
@@ -691,7 +688,6 @@ test_files:
691
688
  - test/test__helper.rb
692
689
  - test/test_age.rb
693
690
  - test/test_amount.rb
694
- - test/test_cache.rb
695
691
  - test/test_cached_wallets.rb
696
692
  - test/test_copies.rb
697
693
  - test/test_dir_items.rb
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
-
3
- port=$(reserve_port)
4
-
5
- zold node --trace --invoice=NOPREFIX@ffffffffffffffff \
6
- --host=localhost --port=${port} --bind-port=${port} \
7
- --threads=0 --standalone &
8
- pid=$!
9
- trap "halt_nodes ${port}" EXIT
10
-
11
- wait_for_port ${port}
12
-
13
- kill -CONT ${pid}
14
-
15
- wait_for_file sigdump-${pid}.log
data/lib/zold/cache.rb DELETED
@@ -1,50 +0,0 @@
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
- # Cache.
24
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
- # License:: MIT
27
- module Zold
28
- # Cache
29
- class Cache
30
- def initialize
31
- @hash = {}
32
- @mutex = Mutex.new
33
- end
34
-
35
- def get(key, lifetime: 60 * 60)
36
- @mutex.synchronize do
37
- rec = @hash[key]
38
- rec = nil if !rec.nil? && rec[:start] < Time.now - rec[:lifetime]
39
- if rec.nil?
40
- @hash[key] = {
41
- value: yield,
42
- start: Time.now,
43
- lifetime: lifetime
44
- }
45
- end
46
- @hash[key][:value]
47
- end
48
- end
49
- end
50
- end
data/test/test_cache.rb DELETED
@@ -1,53 +0,0 @@
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 'threads'
25
- require_relative '../lib/zold/cache'
26
-
27
- # Cache test.
28
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
30
- # License:: MIT
31
- class TestCache < Minitest::Test
32
- def test_caches
33
- cache = Zold::Cache.new
34
- first = cache.get(:hey, lifetime: 5) { Random.rand }
35
- second = cache.get(:hey) { Random.rand }
36
- assert(first == second)
37
- end
38
-
39
- def test_caches_and_expires
40
- cache = Zold::Cache.new
41
- first = cache.get(:hey, lifetime: 0.01) { Random.rand }
42
- sleep 0.1
43
- second = cache.get(:hey) { Random.rand }
44
- assert(first != second)
45
- end
46
-
47
- def test_caches_in_threads
48
- cache = Zold::Cache.new
49
- Threads.new(10).assert(100) do
50
- cache.get(:hey, lifetime: 0.0001) { Random.rand }
51
- end
52
- end
53
- end