zold 0.13.34 → 0.13.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +6 -5
- data/bin/zold +6 -1
- data/fixtures/scripts/_head.sh +4 -2
- data/fixtures/scripts/push-and-pull.sh +1 -1
- data/lib/zold/amount.rb +5 -0
- data/lib/zold/atomic_file.rb +3 -3
- data/lib/zold/backtrace.rb +7 -1
- data/lib/zold/commands/clean.rb +1 -1
- data/lib/zold/commands/create.rb +2 -2
- data/lib/zold/commands/diff.rb +2 -2
- data/lib/zold/commands/fetch.rb +8 -4
- data/lib/zold/commands/merge.rb +3 -3
- data/lib/zold/commands/node.rb +32 -11
- data/lib/zold/commands/propagate.rb +1 -1
- data/lib/zold/commands/push.rb +14 -9
- data/lib/zold/commands/remote.rb +4 -2
- data/lib/zold/commands/routines/bonuses.rb +9 -5
- data/lib/zold/commands/routines/spread.rb +4 -1
- data/lib/zold/commands/show.rb +2 -2
- data/lib/zold/commands/taxes.rb +2 -1
- data/lib/zold/http.rb +9 -1
- data/lib/zold/id.rb +4 -0
- data/lib/zold/json_page.rb +43 -0
- data/lib/zold/metronome.rb +15 -15
- data/lib/zold/node/async_entrance.rb +81 -0
- data/lib/zold/node/entrance.rb +26 -91
- data/lib/zold/node/farm.rb +21 -15
- data/lib/zold/node/front.rb +30 -17
- data/lib/zold/node/safe_entrance.rb +78 -0
- data/lib/zold/node/spread_entrance.rb +105 -0
- data/lib/zold/patch.rb +7 -5
- data/lib/zold/remotes.rb +19 -7
- data/lib/zold/txn.rb +3 -1
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +3 -3
- data/lib/zold/wallets.rb +2 -0
- data/test/commands/routines/test_bonuses.rb +2 -2
- data/test/commands/test_fetch.rb +9 -35
- data/test/commands/test_merge.rb +1 -1
- data/test/commands/test_node.rb +4 -2
- data/test/commands/test_push.rb +4 -2
- data/test/node/fake_entrance.rb +41 -0
- data/test/node/fake_node.rb +37 -29
- data/test/node/test_async_entrance.rb +88 -0
- data/test/node/test_entrance.rb +1 -19
- data/test/node/test_front.rb +3 -2
- data/test/node/test_safe_entrance.rb +56 -0
- data/test/node/test_spread_entrance.rb +60 -0
- data/test/test__helper.rb +0 -1
- data/test/test_atomic_file.rb +39 -0
- data/test/test_backtrace.rb +40 -0
- data/test/test_metronome.rb +0 -1
- data/test/test_patch.rb +17 -0
- data/test/test_remotes.rb +21 -0
- data/test/test_wallet.rb +14 -1
- data/test/test_zold.rb +1 -0
- metadata +16 -2
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallet.rb
CHANGED
@@ -94,7 +94,7 @@ module Zold
|
|
94
94
|
txns.inject(Amount::ZERO) { |sum, t| sum + t.amount }
|
95
95
|
end
|
96
96
|
|
97
|
-
def sub(amount, invoice, pvt, details = '-')
|
97
|
+
def sub(amount, invoice, pvt, details = '-', time: Time.now)
|
98
98
|
raise 'The amount has to be of type Amount' unless amount.is_a?(Amount)
|
99
99
|
raise "The amount can't be negative: #{amount}" if amount.negative?
|
100
100
|
raise 'The pvt has to be of type Key' unless pvt.is_a?(Key)
|
@@ -103,7 +103,7 @@ module Zold
|
|
103
103
|
raise 'Too many transactions already, can\'t add more' if max > 0xffff
|
104
104
|
txn = Txn.new(
|
105
105
|
tid,
|
106
|
-
|
106
|
+
time,
|
107
107
|
amount * -1,
|
108
108
|
prefix,
|
109
109
|
Id.new(target),
|
@@ -149,7 +149,7 @@ module Zold
|
|
149
149
|
lines.drop(5)
|
150
150
|
.each_with_index
|
151
151
|
.map { |line, i| Txn.parse(line, i + 6) }
|
152
|
-
.sort_by
|
152
|
+
.sort_by { |t| [t.date, t.amount * -1] }
|
153
153
|
end
|
154
154
|
|
155
155
|
private
|
data/lib/zold/wallets.rb
CHANGED
@@ -34,8 +34,8 @@ require_relative '../../../lib/zold/commands/routines/bonuses.rb'
|
|
34
34
|
# License:: MIT
|
35
35
|
class TestBonuses < Minitest::Test
|
36
36
|
def test_pays_bonuses
|
37
|
-
|
38
|
-
|
37
|
+
FakeHome.new.run do |home|
|
38
|
+
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
39
39
|
bank = home.create_wallet
|
40
40
|
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
41
41
|
['pay', home.create_wallet.id.to_s, bank.id.to_s, '100', '--force', '--private-key=id_rsa']
|
data/test/commands/test_fetch.rb
CHANGED
@@ -24,6 +24,7 @@ require 'json'
|
|
24
24
|
require 'time'
|
25
25
|
require 'webmock/minitest'
|
26
26
|
require_relative '../test__helper'
|
27
|
+
require_relative '../fake_home'
|
27
28
|
require_relative '../../lib/zold/wallet'
|
28
29
|
require_relative '../../lib/zold/wallets'
|
29
30
|
require_relative '../../lib/zold/remotes'
|
@@ -39,54 +40,27 @@ require_relative '../../lib/zold/commands/fetch'
|
|
39
40
|
# License:: MIT
|
40
41
|
class TestFetch < Minitest::Test
|
41
42
|
def test_fetches_wallet
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
wallet = wallets.find(id)
|
46
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
47
|
-
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
48
|
-
remotes.clean
|
49
|
-
stub_request(:get, "http://localhost:80/wallet/#{id}").to_return(
|
43
|
+
FakeHome.new.run do |home|
|
44
|
+
wallet = home.create_wallet
|
45
|
+
stub_request(:get, "http://localhost:80/wallet/#{wallet.id}").to_return(
|
50
46
|
status: 200,
|
51
47
|
body: {
|
52
48
|
'score': Zold::Score::ZERO.to_h,
|
53
49
|
'body': File.read(wallet.path)
|
54
50
|
}.to_json
|
55
51
|
)
|
56
|
-
stub_request(:get, "http://localhost:81/wallet/#{id}").to_return(
|
52
|
+
stub_request(:get, "http://localhost:81/wallet/#{wallet.id}").to_return(
|
57
53
|
status: 404
|
58
54
|
)
|
55
|
+
remotes = home.remotes
|
59
56
|
remotes.add('localhost', 80)
|
60
57
|
remotes.add('localhost', 81)
|
61
|
-
copies =
|
62
|
-
Zold::Fetch.new(wallets: wallets, copies: copies.root, remotes: remotes, log: test_log).run(
|
63
|
-
['fetch', '--ignore-score-weakness', id.to_s]
|
58
|
+
copies = home.copies(wallet)
|
59
|
+
Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: test_log).run(
|
60
|
+
['fetch', '--ignore-score-weakness', wallet.id.to_s]
|
64
61
|
)
|
65
62
|
assert_equal(copies.all[0][:name], '1')
|
66
63
|
assert_equal(copies.all[0][:score], 0)
|
67
64
|
end
|
68
65
|
end
|
69
|
-
|
70
|
-
def test_fetches_empty_wallet
|
71
|
-
Dir.mktmpdir 'test' do |dir|
|
72
|
-
id = Zold::Id.new
|
73
|
-
wallets = Zold::Wallets.new(dir)
|
74
|
-
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
75
|
-
remotes.clean
|
76
|
-
stub_request(:get, "http://localhost:80/wallet/#{id}").to_return(
|
77
|
-
status: 200,
|
78
|
-
body: {
|
79
|
-
'score': Zold::Score::ZERO.to_h,
|
80
|
-
'body': 'the body'
|
81
|
-
}.to_json
|
82
|
-
)
|
83
|
-
remotes.add('localhost', 80)
|
84
|
-
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
85
|
-
Zold::Fetch.new(
|
86
|
-
wallets: wallets, copies: copies.root, remotes: remotes, log: test_log
|
87
|
-
).run(['fetch', id.to_s])
|
88
|
-
assert_equal(copies.all[0][:name], '1')
|
89
|
-
assert_equal(copies.all[0][:score], 0)
|
90
|
-
end
|
91
|
-
end
|
92
66
|
end
|
data/test/commands/test_merge.rb
CHANGED
@@ -95,7 +95,7 @@ class TestMerge < Minitest::Test
|
|
95
95
|
|
96
96
|
def test_merges_a_copy_on_top
|
97
97
|
FakeHome.new.run do |home|
|
98
|
-
wallet = home.create_wallet
|
98
|
+
wallet = home.create_wallet(Zold::Id::ROOT)
|
99
99
|
copies = home.copies(wallet)
|
100
100
|
copies.add(File.read(wallet.path), 'good-host', 80, 5)
|
101
101
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
data/test/commands/test_node.rb
CHANGED
@@ -44,12 +44,14 @@ class TestNode < Minitest::Test
|
|
44
44
|
wallet = home.create_wallet
|
45
45
|
remotes = home.remotes
|
46
46
|
remotes.add('localhost', port)
|
47
|
-
Zold::Push.new(wallets: wallets, remotes: remotes, log: test_log).run(
|
47
|
+
Zold::Push.new(wallets: wallets, remotes: remotes, log: test_log).run(
|
48
|
+
['push', '--ignore-score-weakness']
|
49
|
+
)
|
48
50
|
copies = home.copies(wallet)
|
49
51
|
Zold::Fetch.new(
|
50
52
|
wallets: wallets, copies: copies.root,
|
51
53
|
remotes: remotes, log: test_log
|
52
|
-
).run(['fetch'])
|
54
|
+
).run(['fetch', '--ignore-score-weakness'])
|
53
55
|
assert_equal(1, copies.all.count)
|
54
56
|
assert_equal('1', copies.all[0][:name])
|
55
57
|
end
|
data/test/commands/test_push.rb
CHANGED
@@ -37,8 +37,10 @@ class TestPush < Minitest::Test
|
|
37
37
|
def test_pushes_wallet
|
38
38
|
FakeHome.new.run do |home|
|
39
39
|
wallet = home.create_wallet
|
40
|
-
|
41
|
-
|
40
|
+
remotes = home.remotes
|
41
|
+
remotes.add('localhost', 80)
|
42
|
+
stub_request(:put, "http://localhost:80/wallet/#{wallet.id}").to_return(status: 304)
|
43
|
+
Zold::Push.new(wallets: home.wallets, remotes: remotes, log: test_log).run(
|
42
44
|
['--ignore-this-stupid-option', 'push', wallet.id.to_s]
|
43
45
|
)
|
44
46
|
end
|
@@ -0,0 +1,41 @@
|
|
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
|
+
# Fake entrance.
|
22
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
23
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
24
|
+
# License:: MIT
|
25
|
+
class FakeEntrance
|
26
|
+
def initialize
|
27
|
+
# Nothing here
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_json
|
31
|
+
{}
|
32
|
+
end
|
33
|
+
|
34
|
+
def start
|
35
|
+
yield self
|
36
|
+
end
|
37
|
+
|
38
|
+
def push(id, _)
|
39
|
+
[id]
|
40
|
+
end
|
41
|
+
end
|
data/test/node/fake_node.rb
CHANGED
@@ -24,6 +24,7 @@ require_relative '../fake_home'
|
|
24
24
|
require_relative '../../lib/zold/log'
|
25
25
|
require_relative '../../lib/zold/http'
|
26
26
|
require_relative '../../lib/zold/verbose_thread'
|
27
|
+
require_relative '../../lib/zold/node/front'
|
27
28
|
|
28
29
|
# Fake node.
|
29
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -41,37 +42,44 @@ class FakeNode
|
|
41
42
|
def run(args = ['--standalone'])
|
42
43
|
WebMock.allow_net_connect!
|
43
44
|
start = Dir.pwd
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
begin
|
46
|
+
FakeHome.new.run do |home|
|
47
|
+
server = TCPServer.new('127.0.0.1', 0)
|
48
|
+
port = server.addr[1]
|
49
|
+
server.close
|
50
|
+
node = Thread.new do
|
51
|
+
Zold::VerboseThread.new(@log).run do
|
52
|
+
Thread.current.abort_on_exception = true
|
53
|
+
Dir.chdir(home.dir)
|
54
|
+
require_relative '../../lib/zold/commands/node'
|
55
|
+
Zold::Node.new(wallets: home.wallets, remotes: home.remotes, copies: home.copies.root, log: @log).run(
|
56
|
+
[
|
57
|
+
'--network=test',
|
58
|
+
'--port', port.to_s,
|
59
|
+
'--host=localhost',
|
60
|
+
'--bind-port', port.to_s,
|
61
|
+
'--threads=1',
|
62
|
+
'--strength=2',
|
63
|
+
'--routine-immediately',
|
64
|
+
'--invoice=NOPREFIX@ffffffffffffffff'
|
65
|
+
] + args
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
uri = "http://localhost:#{port}/"
|
70
|
+
while Zold::Http.new(uri).get.code == '599' && node.alive?
|
71
|
+
@log.debug("Waiting for #{uri}...")
|
72
|
+
sleep 1
|
73
|
+
end
|
74
|
+
begin
|
75
|
+
yield port
|
76
|
+
ensure
|
77
|
+
Zold::Front.stop!
|
78
|
+
node.join
|
62
79
|
end
|
63
80
|
end
|
64
|
-
|
65
|
-
|
66
|
-
sleep 1
|
67
|
-
@log.debug("Waiting for #{uri}...")
|
68
|
-
end
|
69
|
-
begin
|
70
|
-
yield port
|
71
|
-
ensure
|
72
|
-
node.exit
|
73
|
-
Dir.chdir(start)
|
74
|
-
end
|
81
|
+
ensure
|
82
|
+
Dir.chdir(start)
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
@@ -0,0 +1,88 @@
|
|
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 '../fake_home'
|
23
|
+
require_relative '../test__helper'
|
24
|
+
require_relative '../../lib/zold/id'
|
25
|
+
require_relative '../../lib/zold/node/async_entrance'
|
26
|
+
require_relative 'fake_entrance'
|
27
|
+
|
28
|
+
# AsyncEntrance test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class TestAsyncEntrance < Minitest::Test
|
33
|
+
def test_renders_json
|
34
|
+
FakeHome.new.run do
|
35
|
+
Zold::AsyncEntrance.new(FakeEntrance.new, log: test_log).start do |e|
|
36
|
+
assert_equal(true, e.to_json[:'pool.running'])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_sends_through
|
42
|
+
FakeHome.new.run do |home|
|
43
|
+
wallet = home.create_wallet
|
44
|
+
amount = Zold::Amount.new(zld: 39.99)
|
45
|
+
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
46
|
+
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
47
|
+
basic = CountingEntrance.new
|
48
|
+
Zold::AsyncEntrance.new(basic, log: test_log).start do |e|
|
49
|
+
5.times { e.push(wallet.id, File.read(wallet.path)) }
|
50
|
+
sleep 0.1 until e.to_json[:'pool.completed_task_count'] == 5
|
51
|
+
assert_equal(5, basic.count)
|
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'])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_handles_broken_entrance_gracefully
|
60
|
+
FakeHome.new.run do |home|
|
61
|
+
wallet = home.create_wallet
|
62
|
+
Zold::AsyncEntrance.new(BrokenEntrance.new, log: test_log).start do |e|
|
63
|
+
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
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class CountingEntrance < FakeEntrance
|
73
|
+
attr_reader :count
|
74
|
+
def initialize
|
75
|
+
@count = 0
|
76
|
+
end
|
77
|
+
|
78
|
+
def push(_, _)
|
79
|
+
@count += 1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class BrokenEntrance < FakeEntrance
|
84
|
+
def push(_, _)
|
85
|
+
raise 'It intentionally crashes'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/test/node/test_entrance.rb
CHANGED
@@ -34,26 +34,8 @@ require_relative '../../lib/zold/commands/pay'
|
|
34
34
|
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
35
35
|
# License:: MIT
|
36
36
|
class TestEntrance < Minitest::Test
|
37
|
-
def test_renders_json
|
38
|
-
FakeHome.new.run do |home|
|
39
|
-
wallet = home.create_wallet(Zold::Id.new)
|
40
|
-
entrance = Zold::Entrance.new(home.wallets, home.remotes, home.copies(wallet).root, 'x', log: test_log)
|
41
|
-
assert_equal(0, entrance.to_json[:modified])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_ignores_duplicates
|
46
|
-
FakeHome.new.run do |home|
|
47
|
-
wallet = home.create_wallet(Zold::Id.new)
|
48
|
-
entrance = Zold::Entrance.new(home.wallets, home.remotes, home.copies(wallet).root, 'x', log: test_log)
|
49
|
-
id = Zold::Id.new.to_s
|
50
|
-
8.times { entrance.spread([Zold::Id.new(id)]) }
|
51
|
-
assert_equal(1, entrance.to_json[:modified])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
37
|
def test_pushes_wallet
|
56
|
-
sid = Zold::Id
|
38
|
+
sid = Zold::Id::ROOT
|
57
39
|
tid = Zold::Id.new
|
58
40
|
body = FakeHome.new.run do |home|
|
59
41
|
source = home.create_wallet(sid)
|
data/test/node/test_front.rb
CHANGED
@@ -25,6 +25,7 @@ require_relative '../test__helper'
|
|
25
25
|
require_relative 'fake_node'
|
26
26
|
require_relative '../fake_home'
|
27
27
|
require_relative '../../lib/zold/http'
|
28
|
+
require_relative '../../lib/zold/json_page'
|
28
29
|
require_relative '../../lib/zold/score'
|
29
30
|
|
30
31
|
class FrontTest < Minitest::Test
|
@@ -66,7 +67,7 @@ class FrontTest < Minitest::Test
|
|
66
67
|
).next.next.next.next
|
67
68
|
response = Zold::Http.new("http://localhost:#{port}/remotes", score).get
|
68
69
|
body = response.body
|
69
|
-
assert_equal(1,
|
70
|
+
assert_equal(1, Zold::JsonPage.new(body).to_hash['all'].count, body)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -148,7 +149,7 @@ class FrontTest < Minitest::Test
|
|
148
149
|
"Expected HTTP 200 OK: Found #{response.code}"
|
149
150
|
)
|
150
151
|
assert_operator(
|
151
|
-
|
152
|
+
700, :>, response['content-length'].to_i,
|
152
153
|
'Expected the content to be smaller than 600 bytes for gzip'
|
153
154
|
)
|
154
155
|
end
|
@@ -0,0 +1,56 @@
|
|
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 '../fake_home'
|
23
|
+
require_relative '../test__helper'
|
24
|
+
require_relative '../../lib/zold/wallet'
|
25
|
+
require_relative '../../lib/zold/id'
|
26
|
+
require_relative '../../lib/zold/key'
|
27
|
+
require_relative '../../lib/zold/node/safe_entrance'
|
28
|
+
require_relative 'fake_entrance'
|
29
|
+
|
30
|
+
# SafeEntrance test.
|
31
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
33
|
+
# License:: MIT
|
34
|
+
class TestSafeEntrance < Minitest::Test
|
35
|
+
def test_rejects_wallet_with_negative_balance
|
36
|
+
FakeHome.new.run do |home|
|
37
|
+
wallet = home.create_wallet
|
38
|
+
amount = Zold::Amount.new(zld: 39.99)
|
39
|
+
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
40
|
+
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
41
|
+
assert_raises StandardError do
|
42
|
+
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id, File.read(wallet.path))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_rejects_wallet_with_wrong_network
|
48
|
+
FakeHome.new.run do |home|
|
49
|
+
wallet = Zold::Wallet.new(File.join(home.dir, 'wallet'))
|
50
|
+
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'), network: 'someothernetwork')
|
51
|
+
assert_raises StandardError do
|
52
|
+
Zold::SafeEntrance.new(FakeEntrance.new).push(wallet.id, File.read(wallet.path))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|