zold 0.0.8 → 0.1
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/.github/ISSUE_TEMPLATE.md +12 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/.rubocop.yml +9 -1
- data/.simplecov +2 -2
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/Procfile +1 -1
- data/README.md +208 -101
- data/Rakefile +2 -1
- data/bin/zold +135 -54
- data/features/cli.feature +1 -1
- data/features/step_definitions/steps.rb +1 -1
- data/features/support/env.rb +1 -1
- data/fixtures/scripts/push-and-pull.sh +35 -0
- data/lib/zold.rb +2 -2
- data/lib/zold/amount.rb +10 -2
- data/lib/zold/commands/{send.rb → clean.rb} +16 -16
- data/lib/zold/commands/create.rb +7 -5
- data/lib/zold/commands/diff.rb +59 -0
- data/lib/zold/commands/fetch.rb +74 -0
- data/lib/zold/commands/{pull.rb → list.rb} +11 -17
- data/lib/zold/commands/merge.rb +50 -0
- data/lib/zold/commands/node.rb +94 -0
- data/lib/zold/commands/pay.rb +58 -0
- data/lib/zold/commands/{check.rb → propagate.rb} +19 -20
- data/lib/zold/commands/push.rb +12 -12
- data/lib/zold/commands/remote.rb +115 -0
- data/lib/zold/commands/{balance.rb → show.rb} +11 -7
- data/lib/zold/copies.rb +126 -0
- data/lib/zold/http.rb +70 -0
- data/lib/zold/id.rb +8 -3
- data/lib/zold/key.rb +2 -2
- data/lib/zold/log.rb +51 -2
- data/lib/zold/node/farm.rb +81 -0
- data/lib/zold/node/front.rb +94 -46
- data/lib/zold/patch.rb +58 -0
- data/lib/zold/remotes.rb +106 -0
- data/lib/zold/score.rb +101 -0
- data/lib/zold/signature.rb +48 -0
- data/lib/zold/version.rb +3 -3
- data/lib/zold/wallet.rb +87 -55
- data/lib/zold/wallets.rb +13 -6
- data/resources/remotes +1 -0
- data/test/commands/test_clean.rb +41 -0
- data/test/commands/test_create.rb +2 -2
- data/test/commands/test_diff.rb +61 -0
- data/test/commands/test_fetch.rb +65 -0
- data/test/commands/test_list.rb +42 -0
- data/test/commands/test_merge.rb +62 -0
- data/test/commands/test_node.rb +56 -0
- data/test/commands/{test_send.rb → test_pay.rb} +10 -11
- data/test/commands/test_remote.rb +60 -0
- data/test/commands/{test_balance.rb → test_show.rb} +6 -8
- data/test/node/fake_node.rb +73 -0
- data/test/node/test_farm.rb +34 -0
- data/test/node/test_front.rb +26 -57
- data/test/test__helper.rb +1 -1
- data/test/test_amount.rb +10 -2
- data/test/test_copies.rb +73 -0
- data/test/test_http.rb +42 -0
- data/test/test_id.rb +2 -2
- data/test/test_key.rb +10 -10
- data/test/test_patch.rb +59 -0
- data/test/test_remotes.rb +72 -0
- data/test/test_score.rb +79 -0
- data/test/test_signature.rb +45 -0
- data/test/test_wallet.rb +18 -35
- data/test/test_wallets.rb +14 -3
- data/test/test_zold.rb +52 -5
- data/zold.gemspec +5 -3
- metadata +92 -21
- data/CONTRIBUTING.md +0 -19
- data/views/index.haml +0 -6
- data/views/layout.haml +0 -26
- data/views/not_found.haml +0 -3
@@ -0,0 +1,42 @@
|
|
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 'tmpdir'
|
23
|
+
require_relative '../../lib/zold/wallet.rb'
|
24
|
+
require_relative '../../lib/zold/key.rb'
|
25
|
+
require_relative '../../lib/zold/id.rb'
|
26
|
+
require_relative '../../lib/zold/commands/list.rb'
|
27
|
+
|
28
|
+
# LIST test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class TestList < Minitest::Test
|
33
|
+
def test_lists_wallets_with_balances
|
34
|
+
Dir.mktmpdir 'test' do |dir|
|
35
|
+
id = Zold::Id.new
|
36
|
+
wallets = Zold::Wallets.new(dir)
|
37
|
+
wallet = wallets.find(id)
|
38
|
+
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
39
|
+
Zold::List.new(wallets: wallets).run
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 'tmpdir'
|
23
|
+
require 'json'
|
24
|
+
require 'time'
|
25
|
+
require 'webmock/minitest'
|
26
|
+
require_relative '../../lib/zold/wallet.rb'
|
27
|
+
require_relative '../../lib/zold/id.rb'
|
28
|
+
require_relative '../../lib/zold/copies.rb'
|
29
|
+
require_relative '../../lib/zold/key.rb'
|
30
|
+
require_relative '../../lib/zold/score.rb'
|
31
|
+
require_relative '../../lib/zold/patch.rb'
|
32
|
+
require_relative '../../lib/zold/commands/merge.rb'
|
33
|
+
require_relative '../../lib/zold/commands/pay.rb'
|
34
|
+
|
35
|
+
# MERGE test.
|
36
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
37
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
38
|
+
# License:: MIT
|
39
|
+
class TestMerge < Minitest::Test
|
40
|
+
def test_merges_wallet
|
41
|
+
Dir.mktmpdir 'test' do |dir|
|
42
|
+
id = Zold::Id.new
|
43
|
+
file = File.join(dir, id.to_s)
|
44
|
+
wallet = Zold::Wallet.new(file)
|
45
|
+
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
46
|
+
first = Zold::Wallet.new(File.join(dir, 'copy-1'))
|
47
|
+
File.write(first.path, File.read(wallet.path))
|
48
|
+
second = Zold::Wallet.new(File.join(dir, 'copy-2'))
|
49
|
+
File.write(second.path, File.read(wallet.path))
|
50
|
+
Zold::Pay.new(
|
51
|
+
payer: first,
|
52
|
+
receiver: second,
|
53
|
+
amount: Zold::Amount.new(zld: 14.95),
|
54
|
+
pvtkey: Zold::Key.new(file: 'fixtures/id_rsa')
|
55
|
+
).run(['--force'])
|
56
|
+
copies = Zold::Copies.new(File.join(dir, 'copies'))
|
57
|
+
copies.add(File.read(first.path), 'host-1', 80, 5)
|
58
|
+
copies.add(File.read(second.path), 'host-2', 80, 5)
|
59
|
+
Zold::Merge.new(wallet: wallet, copies: copies).run
|
60
|
+
end
|
61
|
+
end
|
62
|
+
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 'tmpdir'
|
23
|
+
require 'webmock/minitest'
|
24
|
+
require_relative '../../lib/zold/wallet.rb'
|
25
|
+
require_relative '../../lib/zold/remotes.rb'
|
26
|
+
require_relative '../../lib/zold/id.rb'
|
27
|
+
require_relative '../../lib/zold/copies.rb'
|
28
|
+
require_relative '../../lib/zold/key.rb'
|
29
|
+
require_relative '../../lib/zold/commands/node.rb'
|
30
|
+
require_relative '../../lib/zold/commands/fetch.rb'
|
31
|
+
require_relative '../../lib/zold/commands/push.rb'
|
32
|
+
require_relative '../node/fake_node.rb'
|
33
|
+
|
34
|
+
# NODE test.
|
35
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
36
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
37
|
+
# License:: MIT
|
38
|
+
class TestNode < Minitest::Test
|
39
|
+
def test_push_and_fetch
|
40
|
+
FakeNode.new.run do |port|
|
41
|
+
Dir.mktmpdir 'test' do |dir|
|
42
|
+
id = Zold::Id.new
|
43
|
+
wallet = Zold::Wallet.new(File.join(dir, id.to_s))
|
44
|
+
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
45
|
+
copies = Zold::Copies.new(File.join(dir, 'copies'))
|
46
|
+
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
47
|
+
remotes.clean
|
48
|
+
remotes.add('localhost', port)
|
49
|
+
Zold::Push.new(wallet: wallet, remotes: remotes).run
|
50
|
+
Zold::Fetch.new(wallet: wallet, copies: copies, remotes: remotes).run
|
51
|
+
assert_equal(copies.all[0][:name], '1')
|
52
|
+
assert_equal(copies.all[0][:score], 0)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2018
|
1
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -21,30 +21,29 @@
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
23
|
require_relative '../../lib/zold/wallet.rb'
|
24
|
+
require_relative '../../lib/zold/amount.rb'
|
24
25
|
require_relative '../../lib/zold/key.rb'
|
25
26
|
require_relative '../../lib/zold/id.rb'
|
26
|
-
require_relative '../../lib/zold/commands/
|
27
|
+
require_relative '../../lib/zold/commands/pay.rb'
|
27
28
|
|
28
|
-
#
|
29
|
+
# PAY test.
|
29
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2018
|
31
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
31
32
|
# License:: MIT
|
32
|
-
class
|
33
|
+
class TestPay < Minitest::Test
|
33
34
|
def test_sends_from_wallet_to_wallet
|
34
35
|
Dir.mktmpdir 'test' do |dir|
|
35
|
-
source = Zold::Wallet.new(File.join(dir, 'source
|
36
|
+
source = Zold::Wallet.new(File.join(dir, 'source'))
|
36
37
|
source.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
37
|
-
target = Zold::
|
38
|
-
target.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
38
|
+
target = Zold::Id.new
|
39
39
|
amount = Zold::Amount.new(zld: 14.95)
|
40
|
-
Zold::
|
40
|
+
Zold::Pay.new(
|
41
41
|
payer: source,
|
42
42
|
receiver: target,
|
43
43
|
amount: amount,
|
44
44
|
pvtkey: Zold::Key.new(file: 'fixtures/id_rsa')
|
45
|
-
).run
|
45
|
+
).run(['--force'])
|
46
46
|
assert source.balance == amount.mul(-1)
|
47
|
-
assert target.balance == amount
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
@@ -0,0 +1,60 @@
|
|
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 'tmpdir'
|
23
|
+
require 'webmock/minitest'
|
24
|
+
require_relative '../../lib/zold/wallets.rb'
|
25
|
+
require_relative '../../lib/zold/remotes.rb'
|
26
|
+
require_relative '../../lib/zold/key.rb'
|
27
|
+
require_relative '../../lib/zold/score.rb'
|
28
|
+
require_relative '../../lib/zold/commands/remote.rb'
|
29
|
+
|
30
|
+
# REMOTE test.
|
31
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
33
|
+
# License:: MIT
|
34
|
+
class TestRemote < Minitest::Test
|
35
|
+
def test_updates_remote
|
36
|
+
Dir.mktmpdir 'test' do |dir|
|
37
|
+
remotes = Zold::Remotes.new(File.join(dir, 'a/b/c/remotes'))
|
38
|
+
cmd = Zold::Remote.new(remotes: remotes)
|
39
|
+
cmd.run(['clean'])
|
40
|
+
cmd.run(%w[add localhost 1])
|
41
|
+
stub_request(:get, 'http://localhost:1/remotes').to_return(
|
42
|
+
status: 200,
|
43
|
+
body: {
|
44
|
+
score: Zold::Score::ZERO.to_h,
|
45
|
+
all: [
|
46
|
+
{ host: 'localhost', port: 888 },
|
47
|
+
{ host: 'localhost', port: 999 }
|
48
|
+
]
|
49
|
+
}.to_json
|
50
|
+
)
|
51
|
+
cmd.run(%w[add localhost 2])
|
52
|
+
stub_request(:get, 'http://localhost:2/remotes').to_return(
|
53
|
+
status: 404
|
54
|
+
)
|
55
|
+
assert_equal(remotes.all.count, 2)
|
56
|
+
cmd.run(['update'])
|
57
|
+
assert_equal(3, remotes.all.count)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2018
|
1
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -23,21 +23,19 @@ require 'tmpdir'
|
|
23
23
|
require_relative '../../lib/zold/wallet.rb'
|
24
24
|
require_relative '../../lib/zold/key.rb'
|
25
25
|
require_relative '../../lib/zold/id.rb'
|
26
|
-
require_relative '../../lib/zold/commands/
|
26
|
+
require_relative '../../lib/zold/commands/show.rb'
|
27
27
|
|
28
|
-
#
|
28
|
+
# SHOW test.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2018
|
30
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
31
31
|
# License:: MIT
|
32
|
-
class
|
32
|
+
class TestShow < Minitest::Test
|
33
33
|
def test_checks_wallet_balance
|
34
34
|
Dir.mktmpdir 'test' do |dir|
|
35
35
|
id = Zold::Id.new
|
36
36
|
wallet = Zold::Wallets.new(dir).find(id)
|
37
37
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
38
|
-
balance = Zold::
|
39
|
-
wallet: wallet
|
40
|
-
).run
|
38
|
+
balance = Zold::Show.new(wallet: wallet).run
|
41
39
|
assert balance == Zold::Amount::ZERO
|
42
40
|
end
|
43
41
|
end
|
@@ -0,0 +1,73 @@
|
|
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 'tmpdir'
|
22
|
+
require 'webmock/minitest'
|
23
|
+
require_relative '../../lib/zold/log.rb'
|
24
|
+
require_relative '../../lib/zold/http.rb'
|
25
|
+
require_relative '../../lib/zold/commands/node.rb'
|
26
|
+
|
27
|
+
# Fake node.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
class FakeNode
|
32
|
+
def initialize(log: Zold::Log::Quiet.new)
|
33
|
+
@log = log
|
34
|
+
end
|
35
|
+
|
36
|
+
def run
|
37
|
+
WebMock.allow_net_connect!
|
38
|
+
Dir.mktmpdir 'test' do |dir|
|
39
|
+
server = TCPServer.new('127.0.0.1', 0)
|
40
|
+
port = server.addr[1]
|
41
|
+
server.close
|
42
|
+
node = Thread.new do
|
43
|
+
begin
|
44
|
+
Thread.current.abort_on_exception = true
|
45
|
+
home = File.join(dir, 'node-home')
|
46
|
+
Zold::Node.new(log: @log).run(
|
47
|
+
[
|
48
|
+
'--port', port.to_s,
|
49
|
+
'--host=locahost',
|
50
|
+
'--bind-port', port.to_s,
|
51
|
+
'--threads=1',
|
52
|
+
'--home', home
|
53
|
+
]
|
54
|
+
)
|
55
|
+
rescue StandardError => e
|
56
|
+
@log.error(e.message + "\n" + e.backtrace.join("\n"))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
home = URI("http://localhost:#{port}/")
|
60
|
+
while Zold::Http.new(home).get.code == '599' && node.alive?
|
61
|
+
sleep 1
|
62
|
+
@log.debug("Waiting for #{home}...")
|
63
|
+
end
|
64
|
+
begin
|
65
|
+
yield port
|
66
|
+
rescue StandardError => e
|
67
|
+
@log.error(e.message + "\n" + e.backtrace.join("\n"))
|
68
|
+
ensure
|
69
|
+
node.exit
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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 'rack/test'
|
23
|
+
require 'tmpdir'
|
24
|
+
require_relative '../../lib/zold/node/farm.rb'
|
25
|
+
|
26
|
+
class FarmTest < Minitest::Test
|
27
|
+
def test_makes_best_score_in_background
|
28
|
+
farm = Zold::Farm.new
|
29
|
+
farm.start('localhost', 80, threads: 4, strength: 2)
|
30
|
+
sleep 1 while farm.best.empty? || farm.best[0].value.zero?
|
31
|
+
assert(farm.best[0].value > 0)
|
32
|
+
farm.stop
|
33
|
+
end
|
34
|
+
end
|
data/test/node/test_front.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2018
|
1
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -19,68 +19,37 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
|
-
require '
|
22
|
+
require 'tmpdir'
|
23
23
|
require_relative '../../lib/zold/key.rb'
|
24
24
|
require_relative '../../lib/zold/id.rb'
|
25
25
|
require_relative '../../lib/zold/amount.rb'
|
26
26
|
require_relative '../../lib/zold/wallet.rb'
|
27
|
-
require_relative '../../lib/zold/
|
27
|
+
require_relative '../../lib/zold/http.rb'
|
28
|
+
require_relative 'fake_node.rb'
|
28
29
|
|
29
30
|
class FrontTest < Minitest::Test
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def test_pushes_a_wallet
|
53
|
-
Dir.mktmpdir 'test' do |dir|
|
54
|
-
id = Zold::Id::ROOT
|
55
|
-
file = File.join(dir, "#{id}.xml")
|
56
|
-
wallet = Zold::Wallet.new(file)
|
57
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
58
|
-
put("/wallets/#{id}", File.read(file))
|
59
|
-
assert(last_response.ok?, last_response.body)
|
60
|
-
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
61
|
-
wallet.sub(Zold::Amount.new(zld: 39.99), Zold::Id.new, key)
|
62
|
-
put("/wallets/#{id}", File.read(file))
|
63
|
-
assert(last_response.ok?, last_response.body)
|
31
|
+
def test_renders_public_pages
|
32
|
+
FakeNode.new.run do |port|
|
33
|
+
{
|
34
|
+
'200' => [
|
35
|
+
'/robots.txt',
|
36
|
+
'/',
|
37
|
+
'/remotes'
|
38
|
+
],
|
39
|
+
'404' => [
|
40
|
+
'/this-is-absent',
|
41
|
+
'/wallet/ffffeeeeddddcccc'
|
42
|
+
]
|
43
|
+
}.each do |code, paths|
|
44
|
+
paths.each do |p|
|
45
|
+
uri = URI("http://localhost:#{port}#{p}")
|
46
|
+
response = Zold::Http.new(uri).get
|
47
|
+
assert_equal(
|
48
|
+
code, response.code,
|
49
|
+
"Invalid response code for #{uri}: #{response.message}"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
64
53
|
end
|
65
54
|
end
|
66
|
-
|
67
|
-
def test_pulls_a_wallet
|
68
|
-
Dir.mktmpdir 'test' do |dir|
|
69
|
-
id = Zold::Id.new
|
70
|
-
file = File.join(dir, "#{id}.xml")
|
71
|
-
wallet = Zold::Wallet.new(file)
|
72
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
73
|
-
put("/wallets/#{id}", File.read(file))
|
74
|
-
assert(last_response.ok?, last_response.body)
|
75
|
-
get("/wallets/#{id}")
|
76
|
-
assert(last_response.ok?, last_response.body)
|
77
|
-
File.write(file, last_response.body)
|
78
|
-
assert wallet.balance.zero?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_pulls_an_absent_wallet
|
83
|
-
get('/wallets/ffffeeeeddddcccc')
|
84
|
-
assert(last_response.status == 404)
|
85
|
-
end
|
86
55
|
end
|