zold 0.13.46 → 0.14.0
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/.ruby-version +1 -0
- data/.rultor.yml +2 -2
- data/.simplecov +1 -1
- data/.travis.yml +3 -1
- data/INSTALL.md +4 -1
- data/README.md +98 -3
- data/Rakefile +1 -0
- data/bin/zold +10 -1
- data/fixtures/merge/into-no-wallet/assert.rb +23 -0
- data/fixtures/merge/{random-expenses/0123456789abcdef → into-no-wallet/copies/0123456789abcdef/1.z} +0 -0
- data/fixtures/merge/into-no-wallet/copies/0123456789abcdef/scores.z +1 -0
- data/fixtures/merge/random-expenses/{0000000000000000 → 0000000000000000.z} +0 -0
- data/fixtures/merge/{simple-case/copies/0123456789abcdef/1 → random-expenses/0123456789abcdef.z} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{1 → 1.z} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{2 → 2.z} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{3 → 3.z} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{4 → 4.z} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{5 → 5.z} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/scores.z +5 -0
- data/fixtures/merge/simple-case/{0000000000000000 → 0000000000000000.z} +0 -0
- data/fixtures/merge/simple-case/{0123456789abcdef → 0123456789abcdef.z} +0 -1
- data/fixtures/merge/simple-case/copies/0123456789abcdef/1.z +6 -0
- data/fixtures/merge/simple-case/copies/0123456789abcdef/scores.z +1 -0
- data/fixtures/scripts/push-and-pull.sh +1 -0
- data/lib/zold/atomic_file.rb +7 -6
- data/lib/zold/commands/alias.rb +37 -0
- data/lib/zold/commands/calculate.rb +5 -2
- data/lib/zold/commands/diff.rb +2 -2
- data/lib/zold/commands/fetch.rb +23 -3
- data/lib/zold/commands/merge.rb +12 -7
- data/lib/zold/commands/node.rb +5 -2
- data/lib/zold/commands/pay.rb +11 -0
- data/lib/zold/commands/push.rb +1 -1
- data/lib/zold/commands/remote.rb +28 -2
- data/lib/zold/commands/taxes.rb +14 -2
- data/lib/zold/copies.rb +9 -8
- data/lib/zold/hungry_wallets.rb +12 -0
- data/lib/zold/log.rb +17 -2
- data/lib/zold/node/async_entrance.rb +48 -9
- data/lib/zold/node/entrance.rb +1 -1
- data/lib/zold/node/front.rb +28 -3
- data/lib/zold/node/safe_entrance.rb +3 -3
- data/lib/zold/node/spread_entrance.rb +1 -1
- data/lib/zold/patch.rb +8 -4
- data/lib/zold/remotes.rb +7 -0
- data/lib/zold/score.rb +2 -2
- data/lib/zold/tax.rb +0 -1
- data/lib/zold/upgrades.rb +57 -0
- data/lib/zold/version.rb +2 -1
- data/lib/zold/version_file.rb +39 -0
- data/lib/zold/wallet.rb +17 -4
- data/lib/zold/wallets.rb +9 -6
- data/test/commands/routines/test_spread.rb +1 -0
- data/test/commands/test_alias.rb +7 -0
- data/test/commands/test_create.rb +2 -2
- data/test/commands/test_fetch.rb +2 -1
- data/test/commands/test_merge.rb +2 -0
- data/test/commands/test_node.rb +1 -0
- data/test/commands/test_pay.rb +24 -0
- data/test/commands/test_remote.rb +28 -0
- data/test/node/test_async_entrance.rb +6 -13
- data/test/node/test_front.rb +2 -1
- data/test/test__helper.rb +3 -2
- data/test/test_atomic_file.rb +0 -5
- data/test/test_copies.rb +14 -2
- data/test/test_remotes.rb +12 -0
- data/test/test_score.rb +14 -0
- data/test/test_tax.rb +5 -0
- data/test/test_upgrades.rb +97 -0
- data/test/test_version.rb +13 -0
- data/test/test_wallet.rb +21 -1
- data/test/test_wallets.rb +8 -0
- data/upgrades/2.rb +20 -0
- data/zold.gemspec +3 -3
- metadata +38 -23
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/scores +0 -5
- data/fixtures/merge/simple-case/copies/0123456789abcdef/scores +0 -1
data/lib/zold/wallets.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
19
|
# SOFTWARE.
|
20
|
-
|
20
|
+
require 'pathname'
|
21
21
|
require_relative 'id'
|
22
22
|
require_relative 'wallet'
|
23
23
|
|
@@ -35,8 +35,10 @@ module Zold
|
|
35
35
|
# @todo #70:30min Let's make it smarter. Instead of returning
|
36
36
|
# the full path let's substract the prefix from it if it's equal
|
37
37
|
# to the current directory in Dir.pwd.
|
38
|
-
def to_s
|
39
|
-
path
|
38
|
+
def to_s(curr_dir = Dir.pwd)
|
39
|
+
curr_path = Pathname.new(path)
|
40
|
+
dir_path = Pathname.new(curr_dir)
|
41
|
+
curr_path.relative_path_from(dir_path).to_s
|
40
42
|
end
|
41
43
|
|
42
44
|
def path
|
@@ -48,11 +50,12 @@ module Zold
|
|
48
50
|
def all
|
49
51
|
Dir.new(path).select do |f|
|
50
52
|
file = File.join(@dir, f)
|
53
|
+
basename = File.basename(f, Wallet::EXTENSION)
|
51
54
|
File.file?(file) &&
|
52
55
|
!File.directory?(file) &&
|
53
|
-
|
54
|
-
Id.new(
|
55
|
-
end
|
56
|
+
basename =~ /^[0-9a-fA-F]{16}$/ &&
|
57
|
+
Id.new(basename).to_s == basename
|
58
|
+
end.map { |w| File.basename(w, Wallet::EXTENSION) }
|
56
59
|
end
|
57
60
|
|
58
61
|
def find(id)
|
@@ -24,6 +24,7 @@ require_relative '../../test__helper'
|
|
24
24
|
require_relative '../../fake_home'
|
25
25
|
require_relative '../../node/fake_node'
|
26
26
|
require_relative '../../../lib/zold/commands/routines/spread.rb'
|
27
|
+
require_relative '../../../lib/zold/node/entrance.rb'
|
27
28
|
|
28
29
|
# Spread test.
|
29
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -37,8 +37,8 @@ class TestCreate < Minitest::Test
|
|
37
37
|
)
|
38
38
|
assert wallet.balance.zero?
|
39
39
|
assert(
|
40
|
-
File.exist?(File.join(dir, wallet.id
|
41
|
-
"Wallet file not found: #{wallet.id}"
|
40
|
+
File.exist?(File.join(dir, "#{wallet.id}#{Zold::Wallet::EXTENSION}")),
|
41
|
+
"Wallet file not found: #{wallet.id}#{Zold::Wallet::EXTENSION}"
|
42
42
|
)
|
43
43
|
end
|
44
44
|
end
|
data/test/commands/test_fetch.rb
CHANGED
@@ -46,7 +46,8 @@ class TestFetch < Minitest::Test
|
|
46
46
|
status: 200,
|
47
47
|
body: {
|
48
48
|
'score': Zold::Score::ZERO.to_h,
|
49
|
-
'body': File.read(wallet.path)
|
49
|
+
'body': File.read(wallet.path),
|
50
|
+
'mtime': Time.now.utc.iso8601
|
50
51
|
}.to_json
|
51
52
|
)
|
52
53
|
stub_request(:get, "http://localhost:81/wallet/#{wallet.id}").to_return(
|
data/test/commands/test_merge.rb
CHANGED
@@ -140,6 +140,8 @@ class TestMerge < Minitest::Test
|
|
140
140
|
Dir.new(base).select { |f| File.directory?(File.join(base, f)) && !f.start_with?('.') }.each do |f|
|
141
141
|
Dir.mktmpdir 'test' do |dir|
|
142
142
|
FileUtils.cp_r(File.join('fixtures/merge', "#{f}/."), dir)
|
143
|
+
scores = File.join(dir, 'copies/0123456789abcdef/scores.z')
|
144
|
+
File.write(scores, File.read(scores).gsub(/NOW/, Time.now.utc.iso8601))
|
143
145
|
FileUtils.cp('fixtures/merge/asserts.rb', dir)
|
144
146
|
wallets = Zold::Wallets.new(dir)
|
145
147
|
copies = File.join(dir, 'copies')
|
data/test/commands/test_node.rb
CHANGED
data/test/commands/test_pay.rb
CHANGED
@@ -82,4 +82,28 @@ class TestPay < Minitest::Test
|
|
82
82
|
assert_equal(Zold::Amount::ZERO, source.balance)
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
def test_notifies_about_tax_status
|
87
|
+
FakeHome.new.run do |home|
|
88
|
+
source = home.create_wallet
|
89
|
+
target = home.create_wallet
|
90
|
+
amount = Zold::Amount.new(zld: 14.95)
|
91
|
+
accumulating_log = test_log.dup
|
92
|
+
class << accumulating_log
|
93
|
+
attr_accessor :info_messages
|
94
|
+
|
95
|
+
def info(message)
|
96
|
+
(@info_messages ||= []) << message
|
97
|
+
end
|
98
|
+
end
|
99
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: accumulating_log).run(
|
100
|
+
[
|
101
|
+
'pay', '--force', '--private-key=fixtures/id_rsa',
|
102
|
+
source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
|
103
|
+
]
|
104
|
+
)
|
105
|
+
assert_equal accumulating_log.info_messages.grep(/^The tax debt/).size, 1,
|
106
|
+
'No info_messages notified user of tax debt'
|
107
|
+
end
|
108
|
+
end
|
85
109
|
end
|
@@ -88,4 +88,32 @@ class TestRemote < Minitest::Test
|
|
88
88
|
assert_equal(1, winners.count)
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
def test_remote_trim_with_tolerate
|
93
|
+
Dir.mktmpdir 'test' do |dir|
|
94
|
+
remotes = Zold::Remotes.new(File.join(dir, 'remotes.txt'))
|
95
|
+
zero = Zold::Score::ZERO
|
96
|
+
stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
|
97
|
+
status: 200,
|
98
|
+
body: {
|
99
|
+
version: Zold::VERSION,
|
100
|
+
score: zero.to_h,
|
101
|
+
all: [
|
102
|
+
{ host: 'localhost', port: 888 }
|
103
|
+
]
|
104
|
+
}.to_json
|
105
|
+
)
|
106
|
+
stub_request(:get, 'http://localhost:888/remotes').to_return(
|
107
|
+
status: 404
|
108
|
+
)
|
109
|
+
cmd = Zold::Remote.new(remotes: remotes, log: test_log)
|
110
|
+
cmd.run(%w[remote clean])
|
111
|
+
assert(remotes.all.empty?)
|
112
|
+
cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
|
113
|
+
cmd.run(%w[remote add localhost 888 --skip-ping])
|
114
|
+
cmd.run(['remote', 'update', '--ignore-score-weakness'])
|
115
|
+
cmd.run(['remote', 'trim', '--tolerate=0'])
|
116
|
+
assert_equal(1, remotes.all.count)
|
117
|
+
end
|
118
|
+
end
|
91
119
|
end
|
@@ -31,8 +31,8 @@ require_relative 'fake_entrance'
|
|
31
31
|
# License:: MIT
|
32
32
|
class TestAsyncEntrance < Minitest::Test
|
33
33
|
def test_renders_json
|
34
|
-
FakeHome.new.run do
|
35
|
-
Zold::AsyncEntrance.new(FakeEntrance.new, log: test_log).start do |e|
|
34
|
+
FakeHome.new.run do |home|
|
35
|
+
Zold::AsyncEntrance.new(FakeEntrance.new, home.dir, log: test_log).start do |e|
|
36
36
|
assert_equal(true, e.to_json[:'pool.running'])
|
37
37
|
end
|
38
38
|
end
|
@@ -45,13 +45,10 @@ class TestAsyncEntrance < Minitest::Test
|
|
45
45
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
46
46
|
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
47
47
|
basic = CountingEntrance.new
|
48
|
-
Zold::AsyncEntrance.new(basic, log: test_log).start do |e|
|
48
|
+
Zold::AsyncEntrance.new(basic, File.join(home.dir, 'a/b/c'), log: test_log).start do |e|
|
49
49
|
5.times { e.push(wallet.id, File.read(wallet.path)) }
|
50
|
-
sleep 0.1
|
51
|
-
|
52
|
-
assert_equal(0, e.to_json[:'pool.queue_length'])
|
53
|
-
assert_equal(5, e.to_json[:'pool.length'])
|
54
|
-
assert_equal(5, e.to_json[:'pool.largest_length'])
|
50
|
+
sleep 0.1 while basic.count.zero?
|
51
|
+
assert(!basic.count.zero?)
|
55
52
|
end
|
56
53
|
end
|
57
54
|
end
|
@@ -59,12 +56,8 @@ class TestAsyncEntrance < Minitest::Test
|
|
59
56
|
def test_handles_broken_entrance_gracefully
|
60
57
|
FakeHome.new.run do |home|
|
61
58
|
wallet = home.create_wallet
|
62
|
-
Zold::AsyncEntrance.new(BrokenEntrance.new, log: test_log).start do |e|
|
59
|
+
Zold::AsyncEntrance.new(BrokenEntrance.new, home.dir, log: test_log).start do |e|
|
63
60
|
e.push(wallet.id, File.read(wallet.path))
|
64
|
-
sleep 0.1 while e.to_json[:'pool.length'].zero?
|
65
|
-
assert_equal(0, e.to_json[:'pool.queue_length'])
|
66
|
-
assert_equal(1, e.to_json[:'pool.length'])
|
67
|
-
assert_equal(1, e.to_json[:'pool.largest_length'])
|
68
61
|
end
|
69
62
|
end
|
70
63
|
end
|
data/test/node/test_front.rb
CHANGED
@@ -84,7 +84,8 @@ class FrontTest < Minitest::Test
|
|
84
84
|
"/wallet/#{wallet.id}",
|
85
85
|
"/wallet/#{wallet.id}.txt",
|
86
86
|
"/wallet/#{wallet.id}/balance",
|
87
|
-
"/wallet/#{wallet.id}/key"
|
87
|
+
"/wallet/#{wallet.id}/key",
|
88
|
+
"/wallet/#{wallet.id}/mtime"
|
88
89
|
].each do |u|
|
89
90
|
res = Zold::Http.new(u).get
|
90
91
|
assert_equal('200', res.code, res.body)
|
data/test/test__helper.rb
CHANGED
@@ -37,8 +37,9 @@ module Minitest
|
|
37
37
|
class Test
|
38
38
|
def test_log
|
39
39
|
require_relative '../lib/zold/log'
|
40
|
-
|
41
|
-
@test_log
|
40
|
+
@test_log = Zold::Log::Verbose.new
|
41
|
+
@test_log = Zold::Log::Quiet.new if ENV['TEST_QUIET_LOG']
|
42
|
+
@test_log
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
data/test/test_atomic_file.rb
CHANGED
@@ -42,12 +42,7 @@ class TestAtomicFile < Minitest::Test
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
# @todo #262:30min This test is skipped because it doesn't work. I can't
|
46
|
-
# understand why. It seems that File.open() creates an empty file first
|
47
|
-
# which is then being read by File.read() in another thread. Let's find
|
48
|
-
# out and make AtomicFile truly thread-safe.
|
49
45
|
def test_writes_from_many_threads
|
50
|
-
skip
|
51
46
|
Dir.mktmpdir 'test' do |dir|
|
52
47
|
file = Zold::AtomicFile.new(File.join(dir, 'a.txt'))
|
53
48
|
threads = 10
|
data/test/test_copies.rb
CHANGED
@@ -22,6 +22,7 @@ require 'minitest/autorun'
|
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'time'
|
24
24
|
require_relative '../lib/zold/copies'
|
25
|
+
require_relative '../lib/zold/wallet'
|
25
26
|
|
26
27
|
# Copies test.
|
27
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -66,10 +67,10 @@ class TestCopies < Minitest::Test
|
|
66
67
|
copies = Zold::Copies.new(dir)
|
67
68
|
copies.add('h1', 'zold.io', 50, 80, Time.now - 25 * 60 * 60)
|
68
69
|
copies.add('h1', 'zold.io', 33, 80, Time.now - 26 * 60 * 60)
|
69
|
-
assert(File.exist?(File.join(dir,
|
70
|
+
assert(File.exist?(File.join(dir, "1#{Zold::Wallet::EXTENSION}")))
|
70
71
|
copies.clean
|
71
72
|
assert(copies.all.empty?, "#{copies.all.count} is not empty")
|
72
|
-
assert(!File.exist?(File.join(dir,
|
73
|
+
assert(!File.exist?(File.join(dir, "1#{Zold::Wallet::EXTENSION}")))
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
@@ -82,6 +83,17 @@ class TestCopies < Minitest::Test
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
86
|
+
def test_sorts_them_by_score
|
87
|
+
Dir.mktmpdir 'test' do |dir|
|
88
|
+
copies = Zold::Copies.new(dir)
|
89
|
+
copies.add('content-1', '1.zold.io', 80, 1)
|
90
|
+
copies.add('content-2', '2.zold.io', 80, 2)
|
91
|
+
copies.add('content-3', '3.zold.io', 80, 50)
|
92
|
+
copies.add('content-4', '4.zold.io', 80, 3)
|
93
|
+
assert_equal('50 3 2 1', copies.all.map { |c| c[:score] }.join(' '))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
85
97
|
def test_ignores_too_old_scores
|
86
98
|
Dir.mktmpdir 'test' do |dir|
|
87
99
|
copies = Zold::Copies.new(dir)
|
data/test/test_remotes.rb
CHANGED
@@ -91,6 +91,18 @@ class TestRemotes < Minitest::Test
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def test_log_msg_of_iterates_when_take_too_long
|
95
|
+
Dir.mktmpdir 'test' do |dir|
|
96
|
+
file = File.join(dir, 'remotes')
|
97
|
+
FileUtils.touch(file)
|
98
|
+
remotes = Zold::Remotes.new(file)
|
99
|
+
remotes.add('127.0.0.1')
|
100
|
+
log = TestLogger.new
|
101
|
+
remotes.iterate(log) { sleep(17) }
|
102
|
+
assert(log.msg.include?('Took too long to execute'))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
94
106
|
def test_removes_remotes
|
95
107
|
Dir.mktmpdir 'test' do |dir|
|
96
108
|
file = File.join(dir, 'remotes')
|
data/test/test_score.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'time'
|
24
|
+
require_relative 'test__helper'
|
24
25
|
require_relative '../lib/zold/score'
|
25
26
|
|
26
27
|
# Score test.
|
@@ -142,4 +143,17 @@ class TestScore < Minitest::Test
|
|
142
143
|
).next
|
143
144
|
assert(score.hash.end_with?('000'))
|
144
145
|
end
|
146
|
+
|
147
|
+
def test_generates_hash_correctly
|
148
|
+
score = Zold::Score.new(
|
149
|
+
Time.parse('2018-06-27T06:22:41Z'), 'b2.zold.io', 4096,
|
150
|
+
'THdonv1E@abcdabcdabcdabcd', ['3a934b']
|
151
|
+
)
|
152
|
+
assert_equal('c9c72efbf6beeea13408c5e720ec42aec017c11c3db335e05595c03755000000', score.hash)
|
153
|
+
score = Zold::Score.new(
|
154
|
+
Time.parse('2018-06-27T06:22:41Z'), 'b2.zold.io', 4096,
|
155
|
+
'THdonv1E@abcdabcdabcdabcd', %w[3a934b 1421217]
|
156
|
+
)
|
157
|
+
assert_equal('e04ab4e69f86aa17be1316a52148e7bc3187c6d3df581d885a862d8850000000', score.hash)
|
158
|
+
end
|
145
159
|
end
|
data/test/test_tax.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'time'
|
23
|
+
require_relative 'test__helper'
|
23
24
|
require_relative 'fake_home'
|
24
25
|
require_relative '../lib/zold/id'
|
25
26
|
require_relative '../lib/zold/txn'
|
@@ -35,6 +36,10 @@ require_relative '../lib/zold/score'
|
|
35
36
|
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
36
37
|
# License:: MIT
|
37
38
|
class TestTax < Minitest::Test
|
39
|
+
def test_print_fee
|
40
|
+
test_log.info("Fee in zents: #{Zold::Tax::FEE_TXN_HOUR.to_i}")
|
41
|
+
end
|
42
|
+
|
38
43
|
def test_calculates_tax_for_one_year
|
39
44
|
FakeHome.new.run do |home|
|
40
45
|
wallet = home.create_wallet
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require 'minitest/autorun'
|
22
|
+
require_relative 'test__helper'
|
23
|
+
require_relative '../lib/zold/upgrades'
|
24
|
+
require_relative '../lib/zold/version_file'
|
25
|
+
|
26
|
+
# Upgrade test.
|
27
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
29
|
+
# License:: MIT
|
30
|
+
class TestUpgrades < Minitest::Test
|
31
|
+
# @todo #327:30min Uncomment, when you're ready to work on upgrade manager's
|
32
|
+
# test case of absent version file. Start with running the test first.
|
33
|
+
def test_no_version_file_is_ok
|
34
|
+
skip
|
35
|
+
Dir.mktmpdir do |dir|
|
36
|
+
script_version = '0.0.1'
|
37
|
+
create_upgrade_file(dir, script_version)
|
38
|
+
assert_output(/#{expected_upgrade_script_output(script_version)}/) do
|
39
|
+
run_upgrades(dir)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @todo #327:30min Uncomment, when you're ready to work on upgrade manager's
|
45
|
+
# test case of running only pending upgrade scripts (i.e. the scripts with
|
46
|
+
# versions greater than those in the version file).
|
47
|
+
def test_pending_scripts_run
|
48
|
+
skip
|
49
|
+
Dir.mktmpdir do |dir|
|
50
|
+
%w[0.0.1 0.0.2].each do |script_version|
|
51
|
+
create_upgrade_file(dir, script_version)
|
52
|
+
end
|
53
|
+
create_version_file(dir, '0.0.1')
|
54
|
+
assert_output(/#{expected_upgrade_script_output('0.0.2')}/) do
|
55
|
+
run_upgrades(dir)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_already_ran_scripts_dont_run
|
61
|
+
Dir.mktmpdir do |dir|
|
62
|
+
%w[0.0.1 0.0.2].each do |script_version|
|
63
|
+
create_upgrade_file(dir, script_version)
|
64
|
+
end
|
65
|
+
create_version_file(dir, '0.0.1')
|
66
|
+
out, _err = capture_io do
|
67
|
+
run_upgrades(dir)
|
68
|
+
end
|
69
|
+
refute_match(/#{expected_upgrade_script_output('0.0.1')}/, out)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def run_upgrades(dir)
|
76
|
+
Zold::Upgrades.new(version_file(dir), dir).run
|
77
|
+
end
|
78
|
+
|
79
|
+
def version_file(dir)
|
80
|
+
Zold::VersionFile.new(File.join(dir, 'version'))
|
81
|
+
end
|
82
|
+
|
83
|
+
def create_version_file(dir, version)
|
84
|
+
IO.write(File.join(dir, 'version'), version)
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_upgrade_file(dir, version)
|
88
|
+
IO.write(
|
89
|
+
File.join(dir, "#{version}.rb"),
|
90
|
+
"puts \"#{expected_upgrade_script_output(version)}\""
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def expected_upgrade_script_output(version)
|
95
|
+
"upgrading to #{version}"
|
96
|
+
end
|
97
|
+
end
|
data/test/test_wallet.rb
CHANGED
@@ -44,7 +44,6 @@ class TestWallet < Minitest::Test
|
|
44
44
|
wallet.balance == amount * -3,
|
45
45
|
"#{wallet.balance} is not equal to #{amount * -3}"
|
46
46
|
)
|
47
|
-
assert_equal('1', wallet.version)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
@@ -83,6 +82,27 @@ class TestWallet < Minitest::Test
|
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
85
|
+
def test_returns_modified_time
|
86
|
+
FakeHome.new.run do |home|
|
87
|
+
wallet = home.create_wallet
|
88
|
+
assert(wallet.mtime > Time.now - 60 * 60)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_returns_digest
|
93
|
+
FakeHome.new.run do |home|
|
94
|
+
wallet = home.create_wallet
|
95
|
+
assert_equal(64, wallet.digest.length)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_returns_protocol
|
100
|
+
FakeHome.new.run do |home|
|
101
|
+
wallet = home.create_wallet
|
102
|
+
assert_equal(Zold::PROTOCOL, wallet.protocol)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
86
106
|
def test_iterates_income_transactions
|
87
107
|
FakeHome.new.run do |home|
|
88
108
|
wallet = home.create_wallet
|
data/test/test_wallets.rb
CHANGED
@@ -50,4 +50,12 @@ class TestWallets < Minitest::Test
|
|
50
50
|
assert_equal(1, wallets.all.count)
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
def test_substracts_dir_path_from_full_path
|
55
|
+
FakeHome.new.run do |home|
|
56
|
+
wallets = home.wallets
|
57
|
+
path = wallets.path
|
58
|
+
assert_equal('.', wallets.to_s(path))
|
59
|
+
end
|
60
|
+
end
|
53
61
|
end
|
data/upgrades/2.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# https://github.com/zold-io/zold/issues/358
|
2
|
+
# rename all wallets from their current names into *.z
|
3
|
+
|
4
|
+
module Zold
|
5
|
+
# Upgrade to version 2
|
6
|
+
class UpgradeTo2
|
7
|
+
def initialize(home, log)
|
8
|
+
@home = home
|
9
|
+
@log = log
|
10
|
+
end
|
11
|
+
|
12
|
+
def exec
|
13
|
+
Dir.new(@home).each do |path|
|
14
|
+
next unless path =~ /^[a-f0-9]{16}$/
|
15
|
+
File.rename(path, "#{path}.z")
|
16
|
+
@log.info("Renamed #{path} to #{path}.z")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/zold.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
their ability to become an alternative financial instrument in many
|
38
38
|
different markets. Most of the technologies available at the moment are
|
39
39
|
based on the principles of Blockchain architecture, including
|
40
|
-
dominating currencies like Bitcoin and
|
40
|
+
dominating currencies like Bitcoin and Ethereum. Despite its
|
41
41
|
popularity, Blockchain is not the best possible solution for all scenarios.
|
42
42
|
One such example is for fast micro-payments.
|
43
43
|
Zold is an experimental alternative that enables distributed transactions between
|
@@ -59,8 +59,8 @@ and suggests a different architecture for digital wallet maintenance.'
|
|
59
59
|
s.add_runtime_dependency 'openssl', '~>2.1'
|
60
60
|
s.add_runtime_dependency 'rainbow', '~>3.0'
|
61
61
|
s.add_runtime_dependency 'rake', '~>12.3' # has to stay here for Heroku
|
62
|
-
s.add_runtime_dependency 'rubocop', '
|
63
|
-
s.add_runtime_dependency 'rubocop-rspec', '
|
62
|
+
s.add_runtime_dependency 'rubocop', '0.58.1' # has to stay here for Heroku
|
63
|
+
s.add_runtime_dependency 'rubocop-rspec', '1.27.0' # has to stay here for Heroku
|
64
64
|
s.add_runtime_dependency 'semantic', '~>1.6'
|
65
65
|
s.add_runtime_dependency 'sigdump', '~>0.2'
|
66
66
|
s.add_runtime_dependency 'sinatra', '~>2.0'
|