zold 0.16.28 → 0.16.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a58595f5d647efa9b0ff2f58a2d975d299f9dda59ddd938f8f5c2ff4f917f37
4
- data.tar.gz: 86d0ddf04dcbe3301ce6906900f0d02687c3b893702e374dcab7008e99f7fa45
3
+ metadata.gz: c056002cff9a87ffe6f778a5177ffb939b91f06c509755fff6837709085c24db
4
+ data.tar.gz: e8a1593eb1356bc2252ba0b142d335a30b06447de722cecfd0699508689972c2
5
5
  SHA512:
6
- metadata.gz: '09ca8a13aca6b85dd4d1efb6dcfdeeea39b5c9bdf685e0c0d87a2b29c6de081c59e24d59d838ec2d57a20fcb1259fc1fde104aba107c3c33927a0de25638e098'
7
- data.tar.gz: 18bfc9cf728d6d22d9e50287d1031e7340cb8b623ef3249523161e84fa711dba364bed0cbec34950108b4c4c5753719b59f1997813e0548a37c0d576c6d1cf70
6
+ metadata.gz: 4d098da93208df8f1698179e653504cccb907e8392f3fbcd88183e50a8e24cada09f54945cbe9f26fc6821d2555e2b73bcbea16f8fbe6e8ec4af7cc68f3b50d6
7
+ data.tar.gz: 9aaa767e15bf74b011c0c2e07b7e13b2f282fa16802beeafb508ebc045b8f3bc709a3d7ddf8b17b933bfdbb664af655ab2e16348b150086b6ffd4be5fa0cfda3
@@ -55,7 +55,10 @@ module Zold
55
55
 
56
56
  def acq(id, exclusive: false)
57
57
  @wallets.acq(id, exclusive: exclusive) do |wallet|
58
- yield @zache.get(id.to_s, lifetime: 5 * 60) { wallet }
58
+ c = @zache.get(id.to_s, lifetime: 5 * 60) { wallet }
59
+ res = yield c
60
+ c.flush if exclusive
61
+ res
59
62
  end
60
63
  end
61
64
  end
@@ -83,24 +83,23 @@ Available options:"
83
83
  merge_one(opts, patch, wallet, name)
84
84
  score += c[:score]
85
85
  end
86
- @wallets.acq(id, exclusive: true) do |wallet|
87
- start = Time.now
88
- if wallet.exists?
89
- merge_one(opts, patch, wallet, 'localhost')
86
+ start = Time.now
87
+ @wallets.acq(id) do |w|
88
+ if w.exists?
89
+ merge_one(opts, patch, w, 'localhost')
90
90
  @log.debug("Local copy of #{id} merged in #{Age.new(start)}: #{patch}")
91
91
  else
92
92
  @log.debug("Local copy of #{id} is absent, nothing to merge")
93
93
  end
94
- modified = patch.save(wallet.path, overwrite: true)
95
- wallet.flush
96
- if modified
97
- @log.info("#{cps.count} copies with the total score of #{score} successfully merged \
98
- into #{wallet.mnemo} in #{Age.new(start, limit: 0.1 + cps.count * 0.01)}")
99
- else
100
- @log.info("Nothing changed in #{wallet.id} after merge of #{cps.count} copies")
101
- end
102
- modified
103
94
  end
95
+ modified = @wallets.acq(id, exclusive: true) { |w| patch.save(w.path, overwrite: true) }
96
+ if modified
97
+ @log.info("#{cps.count} copies with the total score of #{score} successfully merged \
98
+ into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + cps.count * 0.01)}")
99
+ else
100
+ @log.info("Nothing changed in #{id} after merge of #{cps.count} copies")
101
+ end
102
+ modified
104
103
  end
105
104
 
106
105
  def merge_one(opts, patch, wallet, name)
@@ -87,7 +87,7 @@ module Zold
87
87
  IO.write(file, body)
88
88
  @queue << { id: id, file: file }
89
89
  @log.debug("Added #{id}/#{Size.new(body.length)} to the queue at pos.#{@queue.size} \
90
- in #{Age.new(start, limit: 0.05)}: #{uuid}")
90
+ in #{Age.new(start, limit: 0.05)}")
91
91
  break
92
92
  end
93
93
  [id]
@@ -475,9 +475,5 @@ in #{Age.new(@start, limit: 1)}")
475
475
  yield wallet
476
476
  end
477
477
  end
478
-
479
- def running_server
480
- false
481
- end
482
478
  end
483
479
  end
@@ -49,8 +49,7 @@ module Zold
49
49
  end
50
50
 
51
51
  def acq(id, exclusive: false)
52
- raise 'The flag can\'t be nil' if exclusive.nil?
53
- @wallets.acq(id) do |wallet|
52
+ @wallets.acq(id, exclusive: exclusive) do |wallet|
54
53
  Futex.new(wallet.path, log: @log).open(exclusive) do
55
54
  yield wallet
56
55
  end
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.28'
28
+ VERSION = '0.16.29'
29
29
  PROTOCOL = 2
30
30
  end
@@ -55,9 +55,9 @@ class TestEntrance < Zold::Test
55
55
  target = home.create_wallet(tid)
56
56
  e = Zold::Entrance.new(home.wallets, home.remotes, home.copies(source).root, 'x', log: test_log)
57
57
  modified = e.push(source.id, body)
58
+ assert_equal(2, modified.count)
58
59
  assert_equal(Zold::Amount.new(zld: -19.99), source.balance)
59
60
  assert_equal(Zold::Amount.new(zld: 19.99), target.balance)
60
- assert_equal(2, modified.count)
61
61
  assert(modified.include?(sid))
62
62
  assert(modified.include?(tid))
63
63
  end
@@ -36,8 +36,8 @@ require_relative '../lib/zold/amount'
36
36
  # License:: MIT
37
37
  class TestCachedWallets < Zold::Test
38
38
  def test_adds_wallet
39
- FakeHome.new(log: test_log).run do |home|
40
- wallets = Zold::CachedWallets.new(home.wallets)
39
+ Dir.mktmpdir do |dir|
40
+ wallets = Zold::CachedWallets.new(Zold::Wallets.new(dir))
41
41
  id = Zold::Id.new
42
42
  first = nil
43
43
  wallets.acq(id, exclusive: true) do |wallet|
@@ -50,4 +50,24 @@ class TestCachedWallets < Zold::Test
50
50
  end
51
51
  end
52
52
  end
53
+
54
+ def test_flushes_correctly
55
+ Dir.mktmpdir do |dir|
56
+ wallets = Zold::CachedWallets.new(Zold::Wallets.new(dir))
57
+ id = Zold::Id.new
58
+ key = Zold::Key.new(file: 'fixtures/id_rsa')
59
+ body = wallets.acq(id, exclusive: true) do |wallet|
60
+ wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
61
+ IO.read(wallet.path)
62
+ end
63
+ wallets.acq(id, exclusive: true) do |wallet|
64
+ wallet.sub(Zold::Amount.new(zld: 1.0), "NOPREFIX@#{Zold::Id.new}", key)
65
+ end
66
+ assert_equal(1, wallets.acq(id, &:txns).count)
67
+ wallets.acq(id, exclusive: true) do |wallet|
68
+ IO.write(wallet.path, body)
69
+ end
70
+ assert_equal(0, wallets.acq(id, &:txns).count)
71
+ end
72
+ end
53
73
  end
data/test/test_wallet.rb CHANGED
@@ -21,6 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'minitest/autorun'
24
+ require_relative 'test__helper'
24
25
  require_relative 'fake_home'
25
26
  require_relative '../lib/zold/key'
26
27
  require_relative '../lib/zold/age'
@@ -185,6 +186,25 @@ class TestWallet < Zold::Test
185
186
  end
186
187
  end
187
188
 
189
+ def test_flushes_and_reads_again
190
+ FakeHome.new(log: test_log).run do |home|
191
+ wallet = home.create_wallet
192
+ wallet.add(
193
+ Zold::Txn.new(
194
+ 1,
195
+ Time.now,
196
+ Zold::Amount.new(zld: 1.99),
197
+ 'NOPREFIX', Zold::Id.new, '-'
198
+ )
199
+ )
200
+ assert_equal(1, wallet.txns.count)
201
+ assert_equal('test', wallet.network)
202
+ wallet.flush
203
+ assert_equal(1, wallet.txns.count)
204
+ assert_equal('test', wallet.network)
205
+ end
206
+ end
207
+
188
208
  def test_returns_modified_time
189
209
  FakeHome.new(log: test_log).run do |home|
190
210
  wallet = home.create_wallet
data/zold.gemspec CHANGED
@@ -62,10 +62,10 @@ and suggests a different architecture for digital wallet maintenance.'
62
62
  s.rdoc_options = ['--charset=UTF-8']
63
63
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
64
64
  s.add_runtime_dependency 'backtrace', '0.3.0'
65
- s.add_runtime_dependency 'concurrent-ruby', '1.1.2'
65
+ s.add_runtime_dependency 'concurrent-ruby', '1.1.3'
66
66
  s.add_runtime_dependency 'cucumber', '3.1.2' # has to stay here for Heroku
67
67
  s.add_runtime_dependency 'diffy', '3.2.1'
68
- s.add_runtime_dependency 'futex', '0.4.2'
68
+ s.add_runtime_dependency 'futex', '0.4.3'
69
69
  s.add_runtime_dependency 'get_process_mem', '0.2.3'
70
70
  s.add_runtime_dependency 'json', '2.1.0'
71
71
  s.add_runtime_dependency 'memory_profiler', '0.9.12'
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.16.28
4
+ version: 0.16.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.2
33
+ version: 1.1.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.2
40
+ version: 1.1.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cucumber
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.4.2
75
+ version: 0.4.3
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 0.4.2
82
+ version: 0.4.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: get_process_mem
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -697,7 +697,7 @@ licenses:
697
697
  - MIT
698
698
  metadata: {}
699
699
  post_install_message: |-
700
- Thanks for installing Zold 0.16.28!
700
+ Thanks for installing Zold 0.16.29!
701
701
  Study our White Paper: https://papers.zold.io/wp.pdf
702
702
  Read our blog posts: https://blog.zold.io
703
703
  Try online wallet at: https://wts.zold.io