zold 0.6.4 → 0.7
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/.rubocop.yml +4 -0
- data/.simplecov +1 -1
- data/bin/zold +2 -2
- data/fixtures/scripts/calculate-scores.sh +1 -1
- data/fixtures/scripts/print-helps.sh +1 -1
- data/fixtures/scripts/push-and-pull.sh +1 -1
- data/lib/zold/commands/create.rb +5 -1
- data/lib/zold/commands/fetch.rb +10 -5
- data/lib/zold/commands/remote.rb +9 -3
- data/lib/zold/node/entrance.rb +1 -1
- data/lib/zold/patch.rb +5 -1
- data/lib/zold/tax.rb +1 -1
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +20 -6
- data/test/commands/test_calculate.rb +2 -1
- data/test/commands/test_clean.rb +2 -1
- data/test/commands/test_create.rb +2 -1
- data/test/commands/test_diff.rb +2 -2
- data/test/commands/test_fetch.rb +9 -4
- data/test/commands/test_invoice.rb +2 -1
- data/test/commands/test_list.rb +2 -1
- data/test/commands/test_merge.rb +5 -4
- data/test/commands/test_node.rb +11 -5
- data/test/commands/test_pay.rb +2 -1
- data/test/commands/test_push.rb +2 -1
- data/test/commands/test_remote.rb +2 -1
- data/test/commands/test_show.rb +2 -1
- data/test/commands/test_taxes.rb +2 -1
- data/test/node/fake_node.rb +1 -2
- data/test/test__helper.rb +3 -0
- data/test/test_zold.rb +1 -1
- data/wp/wp.tex +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb70a77181642453c08fcda55cd1179d84ad47d3
|
4
|
+
data.tar.gz: 4d5c99e488c3196efcb4b98b5f698fadddd72625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b692c87274e9fe516d80cccee43ccc172f03b151732d33271bf6a256e0fd2355af8d0bce3517dc19e7f7b9842c2f778734c0501c3093e6130b561f60da2c933b
|
7
|
+
data.tar.gz: b0c91ee622378ebcb8b96816c8281ac463153fc6d2daca6591322f3fbd8011cf3b2df954ce5178834efa9833a0711f29f25bd09831597cd153d65d5926971503
|
data/.rubocop.yml
CHANGED
data/.simplecov
CHANGED
data/bin/zold
CHANGED
@@ -142,7 +142,7 @@ Available options:"
|
|
142
142
|
Zold::Show.new(wallets: wallets, log: log).run(args)
|
143
143
|
when 'fetch'
|
144
144
|
require_relative '../lib/zold/commands/fetch'
|
145
|
-
Zold::Fetch.new(remotes: remotes, copies: copies, log: log).run(args)
|
145
|
+
Zold::Fetch.new(wallets: wallets, remotes: remotes, copies: copies, log: log).run(args)
|
146
146
|
when 'clean'
|
147
147
|
require_relative '../lib/zold/commands/clean'
|
148
148
|
Zold::Clean.new(copies: copies, log: log).run(args)
|
@@ -157,7 +157,7 @@ Available options:"
|
|
157
157
|
Zold::Propagate.new(wallets: wallets, log: log).run(args)
|
158
158
|
when 'pull'
|
159
159
|
require_relative '../lib/zold/commands/fetch'
|
160
|
-
Zold::Fetch.new(remotes: remotes, copies: copies, log: log).run(args)
|
160
|
+
Zold::Fetch.new(wallets: wallets, remotes: remotes, copies: copies, log: log).run(args)
|
161
161
|
require_relative '../lib/zold/commands/merge'
|
162
162
|
Zold::Merge.new(wallets: wallets, copies: copies, log: log).run(args)
|
163
163
|
when 'taxes'
|
@@ -3,7 +3,7 @@ set -x
|
|
3
3
|
set -e
|
4
4
|
shopt -s expand_aliases
|
5
5
|
|
6
|
-
alias zold="$1 --ignore-global-config --trace"
|
6
|
+
alias zold="$1 --ignore-global-config --trace --network=test"
|
7
7
|
|
8
8
|
zold --help
|
9
9
|
declare -a commands=(node create invoice remote pay show fetch clean diff merge propagate pull push)
|
@@ -3,7 +3,7 @@ set -x
|
|
3
3
|
set -e
|
4
4
|
shopt -s expand_aliases
|
5
5
|
|
6
|
-
alias zold="$1 --ignore-global-config --trace --ignore-this-stupid-option"
|
6
|
+
alias zold="$1 --ignore-global-config --trace --ignore-this-stupid-option --network=test"
|
7
7
|
|
8
8
|
port=`python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'`
|
9
9
|
|
data/lib/zold/commands/create.rb
CHANGED
@@ -45,6 +45,10 @@ Available options:"
|
|
45
45
|
'The location of RSA public key (default: ~/.ssh/id_rsa.pub)',
|
46
46
|
require: true,
|
47
47
|
default: '~/.ssh/id_rsa.pub'
|
48
|
+
o.string '--network',
|
49
|
+
'The name of the network',
|
50
|
+
require: true,
|
51
|
+
default: 'zold'
|
48
52
|
o.bool '--help', 'Print instructions'
|
49
53
|
end
|
50
54
|
mine = Args.new(opts, @log).take || return
|
@@ -54,7 +58,7 @@ Available options:"
|
|
54
58
|
def create(id, opts)
|
55
59
|
wallet = @wallets.find(id)
|
56
60
|
key = Zold::Key.new(file: opts['public-key'])
|
57
|
-
wallet.init(id, key)
|
61
|
+
wallet.init(id, key, network: opts['network'])
|
58
62
|
@log.info(wallet.id)
|
59
63
|
@log.debug("Wallet #{Rainbow(wallet).green} created at #{@wallets.path}")
|
60
64
|
wallet
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -36,7 +36,8 @@ require_relative '../copies'
|
|
36
36
|
module Zold
|
37
37
|
# FETCH pulling command
|
38
38
|
class Fetch
|
39
|
-
def initialize(remotes:, copies:, log: Log::Quiet.new)
|
39
|
+
def initialize(wallets:, remotes:, copies:, log: Log::Quiet.new)
|
40
|
+
@wallets = wallets
|
40
41
|
@remotes = remotes
|
41
42
|
@copies = copies
|
42
43
|
@log = log
|
@@ -82,6 +83,10 @@ Available options:"
|
|
82
83
|
end
|
83
84
|
uri = URI("#{r[:home]}wallet/#{id}")
|
84
85
|
res = Http.new(uri).get
|
86
|
+
if res.code == '404'
|
87
|
+
@log.info("#{address} wallet #{Rainbow('not found').red}")
|
88
|
+
return false
|
89
|
+
end
|
85
90
|
unless res.code == '200'
|
86
91
|
@log.error("#{address} #{Rainbow(res.code).red}/#{res.message} at #{uri}")
|
87
92
|
return false
|
@@ -89,19 +94,19 @@ Available options:"
|
|
89
94
|
json = JSON.parse(res.body)
|
90
95
|
score = Score.parse_json(json['score'])
|
91
96
|
unless score.valid?
|
92
|
-
@log.error("#{address}: invalid score")
|
97
|
+
@log.error("#{address}: invalid score: #{score}")
|
93
98
|
return false
|
94
99
|
end
|
95
100
|
if score.expired?
|
96
|
-
@log.error("#{address}: score expired")
|
101
|
+
@log.error("#{address}: score expired: #{score}")
|
97
102
|
return false
|
98
103
|
end
|
99
104
|
if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
100
|
-
@log.error("#{address} score is too weak
|
105
|
+
@log.error("#{address} score is too weak (#{score.strength}<#{Score::STRENGTH}): #{score}")
|
101
106
|
return false
|
102
107
|
end
|
103
108
|
cps.add(json['body'], score.host, score.port, score.value)
|
104
|
-
@log.info("#{address} #{json['body'].length}b/#{Rainbow(score.value).green} (
|
109
|
+
@log.info("#{address} #{json['body'].length}b/#{Rainbow(score.value).green} (#{json['version']})")
|
105
110
|
true
|
106
111
|
end
|
107
112
|
end
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -114,6 +114,7 @@ Available options:"
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def update(opts, deep = true)
|
117
|
+
capacity = []
|
117
118
|
@remotes.all.each do |r|
|
118
119
|
uri = URI("#{r[:home]}remotes")
|
119
120
|
res = Http.new(uri).get
|
@@ -132,12 +133,12 @@ Available options:"
|
|
132
133
|
score = Score.parse_json(json['score'])
|
133
134
|
unless score.valid?
|
134
135
|
error(r[:host], r[:port])
|
135
|
-
@log.info("#{Rainbow(r[:host]).red} invalid score")
|
136
|
+
@log.info("#{Rainbow(r[:host]).red} invalid score: #{score}")
|
136
137
|
next
|
137
138
|
end
|
138
139
|
if score.expired?
|
139
140
|
error(r[:host], r[:port])
|
140
|
-
@log.info("#{Rainbow(r[:host]).red} expired score")
|
141
|
+
@log.info("#{Rainbow(r[:host]).red} expired score: #{score}")
|
141
142
|
next
|
142
143
|
end
|
143
144
|
if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
@@ -156,7 +157,12 @@ Available options:"
|
|
156
157
|
add(s['host'], s['port']) unless @remotes.exists?(s['host'], s['port'])
|
157
158
|
end
|
158
159
|
end
|
159
|
-
|
160
|
+
capacity << { host: score.host, port: score.port, count: json['all'].count }
|
161
|
+
@log.info("#{r[:host]}:#{r[:port]}: #{Rainbow(score.value).green} (#{json['version']})")
|
162
|
+
end
|
163
|
+
max_capacity = capacity.map { |c| c[:count] }.max || 0
|
164
|
+
capacity.each do |c|
|
165
|
+
@remotes.error(c[:host], c[:port]) if c[:count] < max_capacity
|
160
166
|
end
|
161
167
|
total = @remotes.all.size
|
162
168
|
if total.zero?
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -54,7 +54,7 @@ module Zold
|
|
54
54
|
copies = Copies.new(File.join(@copies, id.to_s))
|
55
55
|
copies.add(body, 'remote', Remotes::PORT, 0)
|
56
56
|
Fetch.new(
|
57
|
-
remotes: @remotes, copies: copies.root, log: @log
|
57
|
+
wallets: @wallets, remotes: @remotes, copies: copies.root, log: @log
|
58
58
|
).run(['fetch', id.to_s, "--ignore-node=#{@address}"])
|
59
59
|
modified = Merge.new(
|
60
60
|
wallets: @wallets, copies: copies.root, log: @log
|
data/lib/zold/patch.rb
CHANGED
@@ -32,9 +32,13 @@ module Zold
|
|
32
32
|
@id = wallet.id
|
33
33
|
@key = wallet.key
|
34
34
|
@txns = wallet.txns
|
35
|
+
@network = wallet.network
|
35
36
|
end
|
36
37
|
|
37
38
|
def join(wallet)
|
39
|
+
if wallet.network != @network
|
40
|
+
raise "The wallet is from a different network '#{wallet.version}', ours is '#{@network}'"
|
41
|
+
end
|
38
42
|
negative = @txns.select { |t| t.amount.negative? }
|
39
43
|
max = negative.empty? ? 0 : negative.max_by(&:id).id
|
40
44
|
wallet.txns.each do |txn|
|
@@ -54,7 +58,7 @@ module Zold
|
|
54
58
|
before = ''
|
55
59
|
before = File.read(file) if File.exist?(file)
|
56
60
|
wallet = Zold::Wallet.new(file)
|
57
|
-
wallet.init(@id, @key, overwrite: overwrite)
|
61
|
+
wallet.init(@id, @key, overwrite: overwrite, network: @network)
|
58
62
|
@txns.each { |t| wallet.add(t) }
|
59
63
|
after = File.read(file)
|
60
64
|
before != after
|
data/lib/zold/tax.rb
CHANGED
@@ -69,7 +69,7 @@ module Zold
|
|
69
69
|
score
|
70
70
|
end.reject(&:nil?).uniq(&:hash)
|
71
71
|
paid = scores.empty? ? Amount::ZERO : scores.map(&:amount).inject(&:+) * -1
|
72
|
-
age_hours = (Time.now - txns.sort_by(&:date)[0].date) / 60
|
72
|
+
age_hours = txns.empty? ? 0 : (Time.now - txns.sort_by(&:date)[0].date) / 60
|
73
73
|
owned = Tax::FEE_TXN_HOUR * txns.count * age_hours
|
74
74
|
owned - paid
|
75
75
|
end
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallet.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'time'
|
22
|
+
require_relative 'version'
|
22
23
|
require_relative 'key'
|
23
24
|
require_relative 'id'
|
24
25
|
require_relative 'txn'
|
@@ -49,6 +50,18 @@ module Zold
|
|
49
50
|
id.to_s
|
50
51
|
end
|
51
52
|
|
53
|
+
def network
|
54
|
+
n = lines[0].strip
|
55
|
+
raise "Invalid network name '#{n}'" unless n =~ /[a-z]{4,16}/
|
56
|
+
n
|
57
|
+
end
|
58
|
+
|
59
|
+
def version
|
60
|
+
v = lines[1].strip
|
61
|
+
raise "Invalid version name '#{v}'" unless v =~ /[0-9]+(\.[0-9]+){1,2}/
|
62
|
+
v
|
63
|
+
end
|
64
|
+
|
52
65
|
def exists?
|
53
66
|
File.exist?(@file)
|
54
67
|
end
|
@@ -57,9 +70,10 @@ module Zold
|
|
57
70
|
@file
|
58
71
|
end
|
59
72
|
|
60
|
-
def init(id, pubkey, overwrite: false)
|
73
|
+
def init(id, pubkey, overwrite: false, network: 'test')
|
61
74
|
raise "File '#{@file}' already exists" if File.exist?(@file) && !overwrite
|
62
|
-
|
75
|
+
raise "Invalid network name '#{network}'" unless network =~ /[a-z]{4,16}/
|
76
|
+
File.write(@file, "#{network}\n#{VERSION}\n#{id}\n#{pubkey.to_pub}\n\n")
|
63
77
|
end
|
64
78
|
|
65
79
|
def root?
|
@@ -67,7 +81,7 @@ module Zold
|
|
67
81
|
end
|
68
82
|
|
69
83
|
def id
|
70
|
-
Id.new(lines[
|
84
|
+
Id.new(lines[2].strip)
|
71
85
|
end
|
72
86
|
|
73
87
|
def balance
|
@@ -104,7 +118,7 @@ module Zold
|
|
104
118
|
end
|
105
119
|
|
106
120
|
def key
|
107
|
-
Key.new(text: lines[
|
121
|
+
Key.new(text: lines[3].strip)
|
108
122
|
end
|
109
123
|
|
110
124
|
def income
|
@@ -114,9 +128,9 @@ module Zold
|
|
114
128
|
end
|
115
129
|
|
116
130
|
def txns
|
117
|
-
lines.drop(
|
131
|
+
lines.drop(5)
|
118
132
|
.each_with_index
|
119
|
-
.map { |line, i| Txn.parse(line, i +
|
133
|
+
.map { |line, i| Txn.parse(line, i + 6) }
|
120
134
|
.sort_by(&:date)
|
121
135
|
end
|
122
136
|
|
@@ -19,6 +19,7 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
|
+
require_relative '../test__helper'
|
22
23
|
require_relative '../../lib/zold/log'
|
23
24
|
require_relative '../../lib/zold/commands/calculate'
|
24
25
|
|
@@ -28,7 +29,7 @@ require_relative '../../lib/zold/commands/calculate'
|
|
28
29
|
# License:: MIT
|
29
30
|
class TestCalculate < Minitest::Test
|
30
31
|
def test_calculates_score
|
31
|
-
score = Zold::Calculate.new.run(
|
32
|
+
score = Zold::Calculate.new(log: $log).run(
|
32
33
|
['score', '--strength=2', '--max=8', '--invoice=NOSUFFIX@ffffffffffffffff']
|
33
34
|
)
|
34
35
|
assert(score.valid?)
|
data/test/commands/test_clean.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/copies'
|
25
26
|
require_relative '../../lib/zold/commands/clean'
|
26
27
|
|
@@ -35,7 +36,7 @@ class TestClean < Minitest::Test
|
|
35
36
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
36
37
|
copies.add('a1', 'host-1', 80, 1, Time.now - 26 * 60)
|
37
38
|
copies.add('a2', 'host-2', 80, 2, Time.now - 26 * 60)
|
38
|
-
Zold::Clean.new(copies: copies.root).run(['clean', id.to_s])
|
39
|
+
Zold::Clean.new(copies: copies.root, log: $log).run(['clean', id.to_s])
|
39
40
|
assert(copies.all.empty?)
|
40
41
|
end
|
41
42
|
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
|
+
require_relative '../test__helper'
|
23
24
|
require_relative '../../lib/zold/wallets'
|
24
25
|
require_relative '../../lib/zold/key'
|
25
26
|
require_relative '../../lib/zold/commands/create'
|
@@ -31,7 +32,7 @@ require_relative '../../lib/zold/commands/create'
|
|
31
32
|
class TestCreate < Minitest::Test
|
32
33
|
def test_creates_wallet
|
33
34
|
Dir.mktmpdir 'test' do |dir|
|
34
|
-
wallet = Zold::Create.new(wallets: Zold::Wallets.new(dir)).run(
|
35
|
+
wallet = Zold::Create.new(wallets: Zold::Wallets.new(dir), log: $log).run(
|
35
36
|
['create', '--public-key=fixtures/id_rsa.pub']
|
36
37
|
)
|
37
38
|
assert wallet.balance.zero?
|
data/test/commands/test_diff.rb
CHANGED
@@ -46,14 +46,14 @@ class TestDiff < Minitest::Test
|
|
46
46
|
second = Zold::Wallet.new(File.join(dir, 'copy-2'))
|
47
47
|
File.write(second.path, File.read(wallet.path))
|
48
48
|
Zold::Pay.new(
|
49
|
-
wallets: Zold::Wallets.new(dir)
|
49
|
+
wallets: Zold::Wallets.new(dir), log: $log
|
50
50
|
).run(['pay', id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa'])
|
51
51
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
52
52
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
53
53
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
54
54
|
diff = Zold::Diff.new(
|
55
55
|
wallets: Zold::Wallets.new(dir),
|
56
|
-
copies: copies.root
|
56
|
+
copies: copies.root, log: $log
|
57
57
|
).run(['diff', id.to_s])
|
58
58
|
assert(diff.include?('-0001;'))
|
59
59
|
end
|
data/test/commands/test_fetch.rb
CHANGED
@@ -23,7 +23,9 @@ require 'tmpdir'
|
|
23
23
|
require 'json'
|
24
24
|
require 'time'
|
25
25
|
require 'webmock/minitest'
|
26
|
+
require_relative '../test__helper'
|
26
27
|
require_relative '../../lib/zold/wallet'
|
28
|
+
require_relative '../../lib/zold/wallets'
|
27
29
|
require_relative '../../lib/zold/remotes'
|
28
30
|
require_relative '../../lib/zold/id'
|
29
31
|
require_relative '../../lib/zold/copies'
|
@@ -39,8 +41,8 @@ class TestFetch < Minitest::Test
|
|
39
41
|
def test_fetches_wallet
|
40
42
|
Dir.mktmpdir 'test' do |dir|
|
41
43
|
id = Zold::Id.new
|
42
|
-
|
43
|
-
wallet =
|
44
|
+
wallets = Zold::Wallets.new(dir)
|
45
|
+
wallet = wallets.find(id)
|
44
46
|
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
45
47
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
46
48
|
remotes.clean
|
@@ -57,7 +59,7 @@ class TestFetch < Minitest::Test
|
|
57
59
|
remotes.add('fake-1', 80)
|
58
60
|
remotes.add('fake-2', 80)
|
59
61
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
60
|
-
Zold::Fetch.new(copies: copies.root, remotes: remotes).run(
|
62
|
+
Zold::Fetch.new(wallets: wallets, copies: copies.root, remotes: remotes, log: $log).run(
|
61
63
|
['fetch', '--ignore-score-weakness', id.to_s]
|
62
64
|
)
|
63
65
|
assert_equal(copies.all[0][:name], '1')
|
@@ -68,6 +70,7 @@ class TestFetch < Minitest::Test
|
|
68
70
|
def test_fetches_empty_wallet
|
69
71
|
Dir.mktmpdir 'test' do |dir|
|
70
72
|
id = Zold::Id.new
|
73
|
+
wallets = Zold::Wallets.new(dir)
|
71
74
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
72
75
|
remotes.clean
|
73
76
|
stub_request(:get, "http://fake-1/wallet/#{id}").to_return(
|
@@ -79,7 +82,9 @@ class TestFetch < Minitest::Test
|
|
79
82
|
)
|
80
83
|
remotes.add('fake-1', 80)
|
81
84
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
82
|
-
Zold::Fetch.new(
|
85
|
+
Zold::Fetch.new(
|
86
|
+
wallets: wallets, copies: copies.root, remotes: remotes, log: $log
|
87
|
+
).run(['fetch', id.to_s])
|
83
88
|
assert_equal(copies.all[0][:name], '1')
|
84
89
|
assert_equal(copies.all[0][:score], 0)
|
85
90
|
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
|
+
require_relative '../test__helper'
|
23
24
|
require_relative '../../lib/zold/wallets'
|
24
25
|
require_relative '../../lib/zold/amount'
|
25
26
|
require_relative '../../lib/zold/key'
|
@@ -37,7 +38,7 @@ class TestInvoice < Minitest::Test
|
|
37
38
|
wallets = Zold::Wallets.new(dir)
|
38
39
|
source = wallets.find(id)
|
39
40
|
source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
40
|
-
invoice = Zold::Invoice.new(wallets: wallets).run(
|
41
|
+
invoice = Zold::Invoice.new(wallets: wallets, log: $log).run(
|
41
42
|
['invoice', id.to_s, '--length=16']
|
42
43
|
)
|
43
44
|
assert_equal(33, invoice.length)
|
data/test/commands/test_list.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
|
+
require_relative '../test__helper'
|
23
24
|
require_relative '../../lib/zold/wallet'
|
24
25
|
require_relative '../../lib/zold/key'
|
25
26
|
require_relative '../../lib/zold/id'
|
@@ -36,7 +37,7 @@ class TestList < Minitest::Test
|
|
36
37
|
wallets = Zold::Wallets.new(dir)
|
37
38
|
wallet = wallets.find(id)
|
38
39
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
39
|
-
Zold::List.new(wallets: wallets).run
|
40
|
+
Zold::List.new(wallets: wallets, log: $log).run
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
data/test/commands/test_merge.rb
CHANGED
@@ -23,6 +23,7 @@ require 'tmpdir'
|
|
23
23
|
require 'json'
|
24
24
|
require 'time'
|
25
25
|
require 'webmock/minitest'
|
26
|
+
require_relative '../test__helper'
|
26
27
|
require_relative '../../lib/zold/wallet'
|
27
28
|
require_relative '../../lib/zold/wallets'
|
28
29
|
require_relative '../../lib/zold/id'
|
@@ -49,14 +50,14 @@ class TestMerge < Minitest::Test
|
|
49
50
|
second = Zold::Wallet.new(File.join(dir, 'copy-2'))
|
50
51
|
File.write(second.path, File.read(wallet.path))
|
51
52
|
Zold::Pay.new(
|
52
|
-
wallets: Zold::Wallets.new(dir)
|
53
|
+
wallets: Zold::Wallets.new(dir), log: $log
|
53
54
|
).run(['pay', id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa'])
|
54
55
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
55
56
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
56
57
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
57
58
|
modified = Zold::Merge.new(
|
58
59
|
wallets: Zold::Wallets.new(dir),
|
59
|
-
copies: copies.root
|
60
|
+
copies: copies.root, log: $log
|
60
61
|
).run(['merge', id.to_s])
|
61
62
|
assert(1, modified.count)
|
62
63
|
assert(id, modified[0])
|
@@ -74,14 +75,14 @@ class TestMerge < Minitest::Test
|
|
74
75
|
second = Zold::Wallet.new(File.join(dir, 'copy-2'))
|
75
76
|
File.write(second.path, File.read(wallet.path))
|
76
77
|
Zold::Pay.new(
|
77
|
-
wallets: Zold::Wallets.new(dir)
|
78
|
+
wallets: Zold::Wallets.new(dir), log: $log
|
78
79
|
).run(['pay', id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa'])
|
79
80
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
80
81
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
81
82
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
82
83
|
modified = Zold::Merge.new(
|
83
84
|
wallets: Zold::Wallets.new(dir),
|
84
|
-
copies: copies.root
|
85
|
+
copies: copies.root, log: $log
|
85
86
|
).run(['merge', id.to_s])
|
86
87
|
assert(1, modified.count)
|
87
88
|
assert(id, modified[0])
|
data/test/commands/test_node.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'webmock/minitest'
|
24
|
+
require_relative '../test__helper'
|
24
25
|
require_relative '../../lib/zold/wallet'
|
25
26
|
require_relative '../../lib/zold/remotes'
|
26
27
|
require_relative '../../lib/zold/id'
|
@@ -37,17 +38,22 @@ require_relative '../node/fake_node'
|
|
37
38
|
# License:: MIT
|
38
39
|
class TestNode < Minitest::Test
|
39
40
|
def test_push_and_fetch
|
40
|
-
FakeNode.new.run do |port|
|
41
|
+
FakeNode.new(log: $log).run do |port|
|
41
42
|
Dir.mktmpdir 'test' do |dir|
|
42
43
|
id = Zold::Id.new
|
43
|
-
|
44
|
+
wallets = Zold::Wallets.new(dir)
|
45
|
+
wallet = wallets.find(id)
|
44
46
|
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
45
|
-
copies = Zold::Copies.new(File.join(dir, 'copies'))
|
46
47
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
47
48
|
remotes.clean
|
48
49
|
remotes.add('localhost', port)
|
49
|
-
Zold::Push.new(
|
50
|
-
Zold::Fetch.new(
|
50
|
+
Zold::Push.new(wallets: wallets, remotes: remotes, log: $log).run(['push'])
|
51
|
+
Zold::Fetch.new(
|
52
|
+
wallets: wallets, copies: File.join(dir, 'copies'),
|
53
|
+
remotes: remotes, log: $log
|
54
|
+
).run(['fetch'])
|
55
|
+
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
56
|
+
assert_equal(1, copies.all.count)
|
51
57
|
assert_equal(copies.all[0][:name], '1')
|
52
58
|
assert_equal(copies.all[0][:score], 0)
|
53
59
|
end
|
data/test/commands/test_pay.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
|
+
require_relative '../test__helper'
|
23
24
|
require_relative '../../lib/zold/wallets'
|
24
25
|
require_relative '../../lib/zold/amount'
|
25
26
|
require_relative '../../lib/zold/key'
|
@@ -41,7 +42,7 @@ class TestPay < Minitest::Test
|
|
41
42
|
target = wallets.find(tid)
|
42
43
|
target.init(tid, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
43
44
|
amount = Zold::Amount.new(zld: 14.95)
|
44
|
-
Zold::Pay.new(wallets: wallets).run(
|
45
|
+
Zold::Pay.new(wallets: wallets, log: $log).run(
|
45
46
|
[
|
46
47
|
'pay', '--force', '--private-key=fixtures/id_rsa',
|
47
48
|
sid.to_s, tid.to_s, amount.to_zld, 'For the car'
|
data/test/commands/test_push.rb
CHANGED
@@ -23,6 +23,7 @@ require 'tmpdir'
|
|
23
23
|
require 'json'
|
24
24
|
require 'time'
|
25
25
|
require 'webmock/minitest'
|
26
|
+
require_relative '../test__helper'
|
26
27
|
require_relative '../../lib/zold/wallet'
|
27
28
|
require_relative '../../lib/zold/wallets'
|
28
29
|
require_relative '../../lib/zold/remotes'
|
@@ -44,7 +45,7 @@ class TestPush < Minitest::Test
|
|
44
45
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
45
46
|
remotes.clean
|
46
47
|
stub_request(:put, "http://fake-1/wallet/#{id}").to_return(status: 304)
|
47
|
-
Zold::Push.new(wallets: wallets, remotes: remotes).run(
|
48
|
+
Zold::Push.new(wallets: wallets, remotes: remotes, log: $log).run(
|
48
49
|
['--ignore-this-stupid-option', 'push', id.to_s]
|
49
50
|
)
|
50
51
|
end
|
@@ -21,6 +21,7 @@
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'webmock/minitest'
|
24
|
+
require_relative '../test__helper'
|
24
25
|
require_relative '../../lib/zold/wallets'
|
25
26
|
require_relative '../../lib/zold/remotes'
|
26
27
|
require_relative '../../lib/zold/key'
|
@@ -56,7 +57,7 @@ class TestRemote < Minitest::Test
|
|
56
57
|
stub_request(:get, 'http://localhost:999/remotes').to_return(
|
57
58
|
status: 404
|
58
59
|
)
|
59
|
-
cmd = Zold::Remote.new(remotes: remotes)
|
60
|
+
cmd = Zold::Remote.new(remotes: remotes, log: $log)
|
60
61
|
cmd.run(%w[remote clean])
|
61
62
|
cmd.run(['remote', 'add', zero.host, zero.port.to_s])
|
62
63
|
cmd.run(%w[remote add localhost 2])
|
data/test/commands/test_show.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
|
+
require_relative '../test__helper'
|
23
24
|
require_relative '../../lib/zold/wallets'
|
24
25
|
require_relative '../../lib/zold/wallet'
|
25
26
|
require_relative '../../lib/zold/key'
|
@@ -37,7 +38,7 @@ class TestShow < Minitest::Test
|
|
37
38
|
wallets = Zold::Wallets.new(dir)
|
38
39
|
wallet = wallets.find(id)
|
39
40
|
wallet.init(Zold::Id.new, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
40
|
-
balance = Zold::Show.new(wallets: wallets).run(['show', id.to_s])
|
41
|
+
balance = Zold::Show.new(wallets: wallets, log: $log).run(['show', id.to_s])
|
41
42
|
assert_equal(Zold::Amount::ZERO, balance)
|
42
43
|
end
|
43
44
|
end
|
data/test/commands/test_taxes.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'webmock/minitest'
|
24
|
+
require_relative '../test__helper'
|
24
25
|
require_relative '../../lib/zold/wallets'
|
25
26
|
require_relative '../../lib/zold/amount'
|
26
27
|
require_relative '../../lib/zold/key'
|
@@ -58,7 +59,7 @@ class TestTaxes < Minitest::Test
|
|
58
59
|
}.to_json
|
59
60
|
)
|
60
61
|
Zold::Taxes.new(
|
61
|
-
wallets: wallets, remotes: remotes
|
62
|
+
wallets: wallets, remotes: remotes, log: $log
|
62
63
|
).run(['taxes', '--private-key=fixtures/id_rsa', id.to_s])
|
63
64
|
assert_equal(Zold::Amount.new(coins: 335_376_547), wallet.balance)
|
64
65
|
end
|
data/test/node/fake_node.rb
CHANGED
@@ -45,6 +45,7 @@ class FakeNode
|
|
45
45
|
home = File.join(dir, 'node-home')
|
46
46
|
Zold::Node.new(log: @log).run(
|
47
47
|
[
|
48
|
+
'--standalone',
|
48
49
|
'--invoice', 'NOPREFIX@ffffffffffffffff',
|
49
50
|
'--port', port.to_s,
|
50
51
|
'--host=locahost',
|
@@ -64,8 +65,6 @@ class FakeNode
|
|
64
65
|
end
|
65
66
|
begin
|
66
67
|
yield port
|
67
|
-
rescue StandardError => e
|
68
|
-
@log.error(e.message + "\n" + e.backtrace.join("\n"))
|
69
68
|
ensure
|
70
69
|
node.exit
|
71
70
|
end
|
data/test/test__helper.rb
CHANGED
data/test/test_zold.rb
CHANGED
data/wp/wp.tex
CHANGED
@@ -84,7 +84,7 @@ and find hash suffixes, performing certain expensive and meaningless calculation
|
|
84
84
|
There is no central ledger, each wallet has its own personal ledger.
|
85
85
|
All transactions in each ledger are confirmed by
|
86
86
|
\href{https://en.wikipedia.org/wiki/RSA_(cryptosystem)}{RSA signatures}
|
87
|
-
of their owners
|
87
|
+
of their owners.
|
88
88
|
|
89
89
|
\textbf{Capacity}.
|
90
90
|
One currency unit is called ZLD.
|
@@ -202,6 +202,8 @@ Each wallet is an ASCII-text file with the name equal to the wallet ID.
|
|
202
202
|
For example, the wallet in the file \dd{12345678abcdef} may include:
|
203
203
|
|
204
204
|
\begin{minted}{text}
|
205
|
+
zold
|
206
|
+
0.6.4
|
205
207
|
12345678abcdef
|
206
208
|
AAAAB3NzaC1yc2EAAAADAQABAAABAQCuLuVr4Tl2sXoN5Zb7b6SKMPrVjLxb...
|
207
209
|
|
@@ -213,9 +215,11 @@ AAAAB3NzaC1yc2EAAAADAQABAAABAQCuLuVr4Tl2sXoN5Zb7b6SKMPrVjLxb...
|
|
213
215
|
|
214
216
|
Lines are separated by either CR or CRLF.
|
215
217
|
There is a header and a ledger, separated by an empty line.
|
216
|
-
The header includes
|
218
|
+
The header includes four lines:
|
217
219
|
|
218
220
|
\begin{enumerate}
|
221
|
+
\item Network name, \dd{[a-z]\{4,16\}};
|
222
|
+
\item Software version, \dd{[0-9]+(\.[0-9]+)\{1,2\}} (\href{https://semver.org/}{semantic versioning});
|
219
223
|
\item Wallet ID, a 64-bit unsigned integer in hexadecimal format;
|
220
224
|
\item Public \href{https://en.wikipedia.org/wiki/RSA_(cryptosystem)}{RSA}
|
221
225
|
key of the wallet owner, in \href{https://en.wikipedia.org/wiki/Base64}{Base64}.
|
@@ -433,6 +437,7 @@ content the node contains, a
|
|
433
437
|
node responds either with
|
434
438
|
\href{https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.3}{202} (if accepted),
|
435
439
|
\href{https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1}{400} (if the data is corrupted),
|
440
|
+
\href{https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.3}{402} (if taxes are not paid),
|
436
441
|
or
|
437
442
|
\href{https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5}{304}
|
438
443
|
(if the content is the same as the one the node already has).
|
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.
|
4
|
+
version: '0.7'
|
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-05-
|
11
|
+
date: 2018-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|