zold 0.2 → 0.3
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/README.md +3 -1
- data/bin/zold +21 -81
- data/fixtures/keys/1.pub +1 -0
- data/fixtures/keys/2 +51 -0
- data/fixtures/keys/2.pub +1 -0
- data/fixtures/scripts/print-helps.sh +15 -0
- data/fixtures/scripts/push-and-pull.sh +7 -3
- data/lib/zold/commands/clean.rb +24 -7
- data/lib/zold/commands/create.rb +16 -4
- data/lib/zold/commands/diff.rb +32 -9
- data/lib/zold/commands/fetch.rb +36 -9
- data/lib/zold/commands/invoice.rb +64 -0
- data/lib/zold/commands/list.rb +1 -1
- data/lib/zold/commands/merge.rb +31 -10
- data/lib/zold/commands/node.rb +6 -2
- data/lib/zold/commands/pay.rb +40 -17
- data/lib/zold/commands/propagate.rb +34 -14
- data/lib/zold/commands/push.rb +27 -9
- data/lib/zold/commands/remote.rb +63 -34
- data/lib/zold/commands/show.rb +34 -9
- data/lib/zold/copies.rb +4 -0
- data/lib/zold/http.rb +1 -1
- data/lib/zold/key.rb +17 -11
- data/lib/zold/node/farm.rb +8 -0
- data/lib/zold/node/front.rb +13 -3
- data/lib/zold/patch.rb +8 -8
- data/lib/zold/prefixes.rb +53 -0
- data/lib/zold/remotes.rb +6 -0
- data/lib/zold/score.rb +4 -4
- data/lib/zold/signature.rb +9 -9
- data/lib/zold/txn.rb +111 -0
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +32 -59
- data/lib/zold/wallets.rb +2 -2
- data/test/commands/test_clean.rb +5 -4
- data/test/commands/test_create.rb +3 -3
- data/test/commands/test_diff.rb +16 -15
- data/test/commands/test_fetch.rb +13 -11
- data/test/commands/test_invoice.rb +46 -0
- data/test/commands/test_list.rb +4 -4
- data/test/commands/test_merge.rb +21 -22
- data/test/commands/test_node.rb +9 -9
- data/test/commands/test_pay.rb +12 -12
- data/test/commands/test_remote.rb +11 -11
- data/test/commands/test_show.rb +9 -7
- data/test/node/fake_node.rb +3 -3
- data/test/node/test_farm.rb +1 -1
- data/test/node/test_front.rb +6 -6
- data/test/test_amount.rb +1 -1
- data/test/test_copies.rb +1 -1
- data/test/test_http.rb +1 -1
- data/test/test_id.rb +1 -1
- data/test/test_key.rb +19 -1
- data/test/test_patch.rb +11 -11
- data/test/test_prefixes.rb +46 -0
- data/test/test_remotes.rb +1 -1
- data/test/test_score.rb +1 -1
- data/test/test_signature.rb +9 -11
- data/test/test_wallet.rb +22 -21
- data/test/test_wallets.rb +4 -4
- metadata +12 -1
data/lib/zold/score.rb
CHANGED
@@ -29,10 +29,10 @@ require_relative 'remotes'
|
|
29
29
|
module Zold
|
30
30
|
# Score
|
31
31
|
class Score
|
32
|
-
|
33
|
-
attr_reader :time, :host, :port
|
32
|
+
STRENGTH = 7
|
33
|
+
attr_reader :time, :host, :port, :strength
|
34
34
|
# time: UTC ISO 8601 string
|
35
|
-
def initialize(time, host, port, suffixes = [], strength:
|
35
|
+
def initialize(time, host, port, suffixes = [], strength: STRENGTH)
|
36
36
|
raise 'Time must be of type Time' unless time.is_a?(Time)
|
37
37
|
raise 'Port must be of type Integer' unless port.is_a?(Integer)
|
38
38
|
@time = time
|
@@ -44,7 +44,7 @@ module Zold
|
|
44
44
|
|
45
45
|
ZERO = Score.new(Time.now, 'localhost', Remotes::PORT)
|
46
46
|
|
47
|
-
def self.parse(text, strength:
|
47
|
+
def self.parse(text, strength: STRENGTH)
|
48
48
|
_, time, host, port, suffixes = text.split(' ', 5)
|
49
49
|
Score.new(
|
50
50
|
Time.parse(time), host, port.to_i,
|
data/lib/zold/signature.rb
CHANGED
@@ -19,9 +19,9 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'time'
|
22
|
-
require_relative 'key
|
23
|
-
require_relative 'id
|
24
|
-
require_relative 'amount
|
22
|
+
require_relative 'key'
|
23
|
+
require_relative 'id'
|
24
|
+
require_relative 'amount'
|
25
25
|
|
26
26
|
# The signature of a transaction.
|
27
27
|
#
|
@@ -31,18 +31,18 @@ require_relative 'amount.rb'
|
|
31
31
|
module Zold
|
32
32
|
# A signature
|
33
33
|
class Signature
|
34
|
-
def sign(pvt,
|
35
|
-
pvt.sign(block(
|
34
|
+
def sign(pvt, t)
|
35
|
+
pvt.sign(block(t))
|
36
36
|
end
|
37
37
|
|
38
|
-
def valid?(pub,
|
39
|
-
pub.verify(
|
38
|
+
def valid?(pub, t)
|
39
|
+
pub.verify(t.sign, block(t))
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
def block(
|
45
|
-
|
44
|
+
def block(t)
|
45
|
+
[t.id, t.amount.to_i, t.prefix, t.bnf, t.details].join(';')
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
data/lib/zold/txn.rb
ADDED
@@ -0,0 +1,111 @@
|
|
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 'time'
|
22
|
+
require_relative 'id'
|
23
|
+
require_relative 'amount'
|
24
|
+
require_relative 'signature'
|
25
|
+
|
26
|
+
# The transaction.
|
27
|
+
#
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
module Zold
|
32
|
+
# A single transaction
|
33
|
+
class Txn
|
34
|
+
attr_reader :id, :date, :amount, :prefix, :bnf, :details, :sign
|
35
|
+
attr_writer :sign, :amount, :bnf
|
36
|
+
def initialize(id, date, amount, prefix, bnf, details)
|
37
|
+
raise "ID of transaction can't be negative: #{id}" if id < 1
|
38
|
+
@id = id
|
39
|
+
raise 'Time have to be of type Time' unless date.is_a?(Time)
|
40
|
+
raise "Time can't be in the future: #{date}" if date > Time.now
|
41
|
+
@date = date
|
42
|
+
raise 'The amount has to be of type Amount' unless amount.is_a?(Amount)
|
43
|
+
raise 'The amount can\'t be zero' if amount.zero?
|
44
|
+
@amount = amount
|
45
|
+
raise 'The bnf has to be of type Id' unless bnf.is_a?(Id)
|
46
|
+
@bnf = bnf
|
47
|
+
raise "Prefix is too short: \"#{prefix}\"" if prefix.length < 8
|
48
|
+
raise "Prefix is too long: \"#{prefix}\"" if prefix.length > 32
|
49
|
+
@prefix = prefix
|
50
|
+
raise 'Details can\'t be empty' if details.empty?
|
51
|
+
raise "Details are too long: \"#{details}\"" if details.length > 128
|
52
|
+
@details = details
|
53
|
+
end
|
54
|
+
|
55
|
+
def ==(other)
|
56
|
+
id == other.id && bnf == other.bnf
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
[
|
61
|
+
@id,
|
62
|
+
@date.utc.iso8601,
|
63
|
+
@amount.to_i,
|
64
|
+
@prefix,
|
65
|
+
@bnf,
|
66
|
+
@details,
|
67
|
+
@sign
|
68
|
+
].join(';')
|
69
|
+
end
|
70
|
+
|
71
|
+
def inverse(bnf)
|
72
|
+
t = clone
|
73
|
+
t.amount = amount.mul(-1)
|
74
|
+
t.bnf = bnf
|
75
|
+
t
|
76
|
+
end
|
77
|
+
|
78
|
+
def signed(pvt)
|
79
|
+
t = clone
|
80
|
+
t.sign = Signature.new.sign(pvt, self)
|
81
|
+
t
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.parse(line, idx)
|
85
|
+
regex = Regexp.new(
|
86
|
+
[
|
87
|
+
'([0-9]+)',
|
88
|
+
'([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
|
89
|
+
'(-?[0-9]+)',
|
90
|
+
'([A-Za-z0-9]{8,32})',
|
91
|
+
'([a-f0-9]{16})',
|
92
|
+
'([a-zA-Z0-9 -.]{1,128})',
|
93
|
+
'([A-Za-z0-9+/]+={0,3})?'
|
94
|
+
].join(';')
|
95
|
+
)
|
96
|
+
clean = line.strip
|
97
|
+
raise "Invalid line ##{idx}: #{line.inspect}" unless regex.match(clean)
|
98
|
+
parts = clean.split(';')
|
99
|
+
txn = Txn.new(
|
100
|
+
parts[0].to_i,
|
101
|
+
Time.parse(parts[1]),
|
102
|
+
Amount.new(coins: parts[2].to_i),
|
103
|
+
parts[3],
|
104
|
+
Id.new(parts[4]),
|
105
|
+
parts[5]
|
106
|
+
)
|
107
|
+
txn.sign = parts[6]
|
108
|
+
txn
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallet.rb
CHANGED
@@ -19,10 +19,11 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'time'
|
22
|
-
require_relative 'key
|
23
|
-
require_relative 'id
|
24
|
-
require_relative '
|
25
|
-
require_relative '
|
22
|
+
require_relative 'key'
|
23
|
+
require_relative 'id'
|
24
|
+
require_relative 'txn'
|
25
|
+
require_relative 'amount'
|
26
|
+
require_relative 'signature'
|
26
27
|
|
27
28
|
# The wallet.
|
28
29
|
#
|
@@ -70,29 +71,36 @@ module Zold
|
|
70
71
|
end
|
71
72
|
|
72
73
|
def balance
|
73
|
-
txns.inject(Amount::ZERO) { |sum, t| sum + t
|
74
|
-
end
|
75
|
-
|
76
|
-
def sub(amount,
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
74
|
+
txns.inject(Amount::ZERO) { |sum, t| sum + t.amount }
|
75
|
+
end
|
76
|
+
|
77
|
+
def sub(amount, invoice, pvt, details = '-')
|
78
|
+
raise 'The amount has to be of type Amount' unless amount.is_a?(Amount)
|
79
|
+
raise "The amount can't be negative: #{amount}" if amount.negative?
|
80
|
+
raise 'The pvt has to be of type Key' unless pvt.is_a?(Key)
|
81
|
+
prefix, target = invoice.split('@')
|
82
|
+
txn = Txn.new(
|
83
|
+
max + 1,
|
84
|
+
Time.now,
|
85
|
+
amount.mul(-1),
|
86
|
+
prefix,
|
87
|
+
Id.new(target),
|
88
|
+
details
|
89
|
+
)
|
90
|
+
txn = txn.signed(pvt)
|
91
|
+
add(txn)
|
87
92
|
txn
|
88
93
|
end
|
89
94
|
|
90
95
|
def add(txn)
|
91
|
-
|
96
|
+
raise 'The txn has to be of type Txn' unless txn.is_a?(Txn)
|
97
|
+
open(@file, 'a') { |f| f.print "#{txn}\n" }
|
92
98
|
end
|
93
99
|
|
94
100
|
def has?(id, bnf)
|
95
|
-
|
101
|
+
raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer)
|
102
|
+
raise 'The bnf has to be of type Id' unless bnf.is_a?(Id)
|
103
|
+
!txns.find { |t| t.id == id && t.bnf == bnf }.nil?
|
96
104
|
end
|
97
105
|
|
98
106
|
def key
|
@@ -101,15 +109,15 @@ module Zold
|
|
101
109
|
|
102
110
|
def income
|
103
111
|
txns.each do |t|
|
104
|
-
yield t unless t
|
112
|
+
yield t unless t.amount.negative?
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
108
116
|
def txns
|
109
117
|
lines.drop(3)
|
110
118
|
.each_with_index
|
111
|
-
.map { |
|
112
|
-
.sort_by
|
119
|
+
.map { |line, i| Txn.parse(line, i + 4) }
|
120
|
+
.sort_by(&:date)
|
113
121
|
end
|
114
122
|
|
115
123
|
private
|
@@ -119,45 +127,10 @@ module Zold
|
|
119
127
|
if all.empty?
|
120
128
|
0
|
121
129
|
else
|
122
|
-
all.select { |t| t
|
130
|
+
all.select { |t| t.amount.negative? }.max_by(&:id).id
|
123
131
|
end
|
124
132
|
end
|
125
133
|
|
126
|
-
def to_line(txn)
|
127
|
-
[
|
128
|
-
txn[:id],
|
129
|
-
txn[:date].utc.iso8601,
|
130
|
-
txn[:amount].to_i,
|
131
|
-
txn[:bnf],
|
132
|
-
txn[:details],
|
133
|
-
txn[:sign]
|
134
|
-
].join(';') + "\n"
|
135
|
-
end
|
136
|
-
|
137
|
-
def fields(line, idx)
|
138
|
-
regex = Regexp.new(
|
139
|
-
[
|
140
|
-
'([0-9]+)',
|
141
|
-
'([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
|
142
|
-
'(-?[0-9]+)',
|
143
|
-
'([a-f0-9]{16})',
|
144
|
-
'([a-zA-Z0-9 -.]{1,128})',
|
145
|
-
'([A-Za-z0-9+/]+={0,3})?'
|
146
|
-
].join(';')
|
147
|
-
)
|
148
|
-
clean = line.strip
|
149
|
-
raise "Invalid line ##{idx}: #{line.inspect}" unless regex.match(clean)
|
150
|
-
parts = clean.split(';')
|
151
|
-
{
|
152
|
-
id: parts[0].to_i,
|
153
|
-
date: Time.parse(parts[1]),
|
154
|
-
amount: Amount.new(coins: parts[2].to_i),
|
155
|
-
bnf: Id.new(parts[3]),
|
156
|
-
details: parts[4],
|
157
|
-
sign: parts[5]
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
134
|
def lines
|
162
135
|
raise "File '#{@file}' is absent" unless File.exist?(@file)
|
163
136
|
File.readlines(@file)
|
data/lib/zold/wallets.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
|
-
require_relative 'id
|
22
|
-
require_relative 'wallet
|
21
|
+
require_relative 'id'
|
22
|
+
require_relative 'wallet'
|
23
23
|
|
24
24
|
# The local collection of wallets.
|
25
25
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
data/test/commands/test_clean.rb
CHANGED
@@ -21,8 +21,8 @@
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'time'
|
24
|
-
require_relative '../../lib/zold/copies
|
25
|
-
require_relative '../../lib/zold/commands/clean
|
24
|
+
require_relative '../../lib/zold/copies'
|
25
|
+
require_relative '../../lib/zold/commands/clean'
|
26
26
|
|
27
27
|
# CLEAN test.
|
28
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -31,10 +31,11 @@ require_relative '../../lib/zold/commands/clean.rb'
|
|
31
31
|
class TestClean < Minitest::Test
|
32
32
|
def test_cleans_copies
|
33
33
|
Dir.mktmpdir 'test' do |dir|
|
34
|
-
|
34
|
+
id = Zold::Id.new
|
35
|
+
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
35
36
|
copies.add('a1', 'host-1', 80, 1, Time.now - 26 * 60)
|
36
37
|
copies.add('a2', 'host-2', 80, 2, Time.now - 26 * 60)
|
37
|
-
Zold::Clean.new(copies: copies).run
|
38
|
+
Zold::Clean.new(copies: copies.root).run([id.to_s])
|
38
39
|
assert(copies.all.empty?)
|
39
40
|
end
|
40
41
|
end
|
@@ -20,9 +20,9 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
|
-
require_relative '../../lib/zold/wallets
|
24
|
-
require_relative '../../lib/zold/key
|
25
|
-
require_relative '../../lib/zold/commands/create
|
23
|
+
require_relative '../../lib/zold/wallets'
|
24
|
+
require_relative '../../lib/zold/key'
|
25
|
+
require_relative '../../lib/zold/commands/create'
|
26
26
|
|
27
27
|
# CREATE test.
|
28
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
data/test/commands/test_diff.rb
CHANGED
@@ -23,12 +23,13 @@ require 'tmpdir'
|
|
23
23
|
require 'json'
|
24
24
|
require 'time'
|
25
25
|
require 'webmock/minitest'
|
26
|
-
require_relative '../../lib/zold/
|
27
|
-
require_relative '../../lib/zold/
|
28
|
-
require_relative '../../lib/zold/
|
29
|
-
require_relative '../../lib/zold/
|
30
|
-
require_relative '../../lib/zold/
|
31
|
-
require_relative '../../lib/zold/commands/
|
26
|
+
require_relative '../../lib/zold/wallets'
|
27
|
+
require_relative '../../lib/zold/wallet'
|
28
|
+
require_relative '../../lib/zold/id'
|
29
|
+
require_relative '../../lib/zold/copies'
|
30
|
+
require_relative '../../lib/zold/key'
|
31
|
+
require_relative '../../lib/zold/commands/pay'
|
32
|
+
require_relative '../../lib/zold/commands/diff'
|
32
33
|
|
33
34
|
# DIFF test.
|
34
35
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -38,24 +39,24 @@ class TestDiff < Minitest::Test
|
|
38
39
|
def test_diff_with_copies
|
39
40
|
Dir.mktmpdir 'test' do |dir|
|
40
41
|
id = Zold::Id.new
|
41
|
-
|
42
|
-
wallet = Zold::Wallet.new(file)
|
42
|
+
wallet = Zold::Wallet.new(File.join(dir, id.to_s))
|
43
43
|
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
44
44
|
first = Zold::Wallet.new(File.join(dir, 'copy-1'))
|
45
45
|
File.write(first.path, File.read(wallet.path))
|
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
|
-
|
50
|
-
receiver: second,
|
51
|
-
amount: Zold::Amount.new(zld: 14.95),
|
49
|
+
wallets: Zold::Wallets.new(dir),
|
52
50
|
pvtkey: Zold::Key.new(file: 'fixtures/id_rsa')
|
53
|
-
).run(['--force'])
|
54
|
-
copies = Zold::Copies.new(File.join(dir,
|
51
|
+
).run([id.to_s, second.id.to_s, '14.95', '--force'])
|
52
|
+
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
55
53
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
56
54
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
57
|
-
diff = Zold::Diff.new(
|
58
|
-
|
55
|
+
diff = Zold::Diff.new(
|
56
|
+
wallets: Zold::Wallets.new(dir),
|
57
|
+
copies: copies.root
|
58
|
+
).run([id.to_s])
|
59
|
+
assert(diff.include?('-1;'))
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
data/test/commands/test_fetch.rb
CHANGED
@@ -23,13 +23,13 @@ require 'tmpdir'
|
|
23
23
|
require 'json'
|
24
24
|
require 'time'
|
25
25
|
require 'webmock/minitest'
|
26
|
-
require_relative '../../lib/zold/wallet
|
27
|
-
require_relative '../../lib/zold/remotes
|
28
|
-
require_relative '../../lib/zold/id
|
29
|
-
require_relative '../../lib/zold/copies
|
30
|
-
require_relative '../../lib/zold/key
|
31
|
-
require_relative '../../lib/zold/score
|
32
|
-
require_relative '../../lib/zold/commands/fetch
|
26
|
+
require_relative '../../lib/zold/wallet'
|
27
|
+
require_relative '../../lib/zold/remotes'
|
28
|
+
require_relative '../../lib/zold/id'
|
29
|
+
require_relative '../../lib/zold/copies'
|
30
|
+
require_relative '../../lib/zold/key'
|
31
|
+
require_relative '../../lib/zold/score'
|
32
|
+
require_relative '../../lib/zold/commands/fetch'
|
33
33
|
|
34
34
|
# FETCH test.
|
35
35
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -42,7 +42,6 @@ class TestFetch < Minitest::Test
|
|
42
42
|
file = File.join(dir, id.to_s)
|
43
43
|
wallet = Zold::Wallet.new(file)
|
44
44
|
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
45
|
-
copies = Zold::Copies.new(File.join(dir, 'copies'))
|
46
45
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
47
46
|
remotes.clean
|
48
47
|
stub_request(:get, "http://fake-1/wallet/#{id}").to_return(
|
@@ -57,7 +56,10 @@ class TestFetch < Minitest::Test
|
|
57
56
|
)
|
58
57
|
remotes.add('fake-1', 80)
|
59
58
|
remotes.add('fake-2', 80)
|
60
|
-
Zold::
|
59
|
+
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
60
|
+
Zold::Fetch.new(copies: copies.root, remotes: remotes).run(
|
61
|
+
['--ignore-score-weakness', id.to_s]
|
62
|
+
)
|
61
63
|
assert_equal(copies.all[0][:name], '1')
|
62
64
|
assert_equal(copies.all[0][:score], 0)
|
63
65
|
end
|
@@ -66,7 +68,6 @@ class TestFetch < Minitest::Test
|
|
66
68
|
def test_fetches_empty_wallet
|
67
69
|
Dir.mktmpdir 'test' do |dir|
|
68
70
|
id = Zold::Id.new
|
69
|
-
copies = Zold::Copies.new(File.join(dir, 'copies'))
|
70
71
|
remotes = Zold::Remotes.new(File.join(dir, 'remotes.csv'))
|
71
72
|
remotes.clean
|
72
73
|
stub_request(:get, "http://fake-1/wallet/#{id}").to_return(
|
@@ -77,7 +78,8 @@ class TestFetch < Minitest::Test
|
|
77
78
|
}.to_json
|
78
79
|
)
|
79
80
|
remotes.add('fake-1', 80)
|
80
|
-
Zold::
|
81
|
+
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
82
|
+
Zold::Fetch.new(copies: copies.root, remotes: remotes).run([id.to_s])
|
81
83
|
assert_equal(copies.all[0][:name], '1')
|
82
84
|
assert_equal(copies.all[0][:score], 0)
|
83
85
|
end
|
@@ -0,0 +1,46 @@
|
|
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/wallets'
|
24
|
+
require_relative '../../lib/zold/amount'
|
25
|
+
require_relative '../../lib/zold/key'
|
26
|
+
require_relative '../../lib/zold/id'
|
27
|
+
require_relative '../../lib/zold/commands/invoice'
|
28
|
+
|
29
|
+
# INVOICE test.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class TestInvoice < Minitest::Test
|
34
|
+
def test_generates_invoice
|
35
|
+
Dir.mktmpdir 'test' do |dir|
|
36
|
+
id = Zold::Id.new
|
37
|
+
wallets = Zold::Wallets.new(dir)
|
38
|
+
source = wallets.find(id)
|
39
|
+
source.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
40
|
+
invoice = Zold::Invoice.new(wallets: wallets).run(
|
41
|
+
[id.to_s, '--length=16']
|
42
|
+
)
|
43
|
+
assert_equal(33, invoice.length)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/commands/test_list.rb
CHANGED
@@ -20,10 +20,10 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
|
-
require_relative '../../lib/zold/wallet
|
24
|
-
require_relative '../../lib/zold/key
|
25
|
-
require_relative '../../lib/zold/id
|
26
|
-
require_relative '../../lib/zold/commands/list
|
23
|
+
require_relative '../../lib/zold/wallet'
|
24
|
+
require_relative '../../lib/zold/key'
|
25
|
+
require_relative '../../lib/zold/id'
|
26
|
+
require_relative '../../lib/zold/commands/list'
|
27
27
|
|
28
28
|
# LIST test.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
data/test/commands/test_merge.rb
CHANGED
@@ -23,14 +23,14 @@ require 'tmpdir'
|
|
23
23
|
require 'json'
|
24
24
|
require 'time'
|
25
25
|
require 'webmock/minitest'
|
26
|
-
require_relative '../../lib/zold/wallet
|
27
|
-
require_relative '../../lib/zold/id
|
28
|
-
require_relative '../../lib/zold/copies
|
29
|
-
require_relative '../../lib/zold/key
|
30
|
-
require_relative '../../lib/zold/score
|
31
|
-
require_relative '../../lib/zold/patch
|
32
|
-
require_relative '../../lib/zold/commands/merge
|
33
|
-
require_relative '../../lib/zold/commands/pay
|
26
|
+
require_relative '../../lib/zold/wallet'
|
27
|
+
require_relative '../../lib/zold/id'
|
28
|
+
require_relative '../../lib/zold/copies'
|
29
|
+
require_relative '../../lib/zold/key'
|
30
|
+
require_relative '../../lib/zold/score'
|
31
|
+
require_relative '../../lib/zold/patch'
|
32
|
+
require_relative '../../lib/zold/commands/merge'
|
33
|
+
require_relative '../../lib/zold/commands/pay'
|
34
34
|
|
35
35
|
# MERGE test.
|
36
36
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -48,15 +48,16 @@ class TestMerge < Minitest::Test
|
|
48
48
|
second = Zold::Wallet.new(File.join(dir, 'copy-2'))
|
49
49
|
File.write(second.path, File.read(wallet.path))
|
50
50
|
Zold::Pay.new(
|
51
|
-
|
52
|
-
receiver: second,
|
53
|
-
amount: Zold::Amount.new(zld: 14.95),
|
51
|
+
wallets: Zold::Wallets.new(dir),
|
54
52
|
pvtkey: Zold::Key.new(file: 'fixtures/id_rsa')
|
55
|
-
).run(['--force'])
|
56
|
-
copies = Zold::Copies.new(File.join(dir,
|
53
|
+
).run([id.to_s, second.id.to_s, '14.95', '--force'])
|
54
|
+
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
57
55
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
58
56
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
59
|
-
Zold::Merge.new(
|
57
|
+
Zold::Merge.new(
|
58
|
+
wallets: Zold::Wallets.new(dir),
|
59
|
+
copies: copies.root
|
60
|
+
).run([id.to_s])
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
@@ -71,18 +72,16 @@ class TestMerge < Minitest::Test
|
|
71
72
|
second = Zold::Wallet.new(File.join(dir, 'copy-2'))
|
72
73
|
File.write(second.path, File.read(wallet.path))
|
73
74
|
Zold::Pay.new(
|
74
|
-
|
75
|
-
receiver: second,
|
76
|
-
amount: Zold::Amount.new(zld: 14.95),
|
75
|
+
wallets: Zold::Wallets.new(dir),
|
77
76
|
pvtkey: Zold::Key.new(file: 'fixtures/id_rsa')
|
78
|
-
).run(['--force'])
|
79
|
-
copies = Zold::Copies.new(File.join(dir,
|
77
|
+
).run([id.to_s, second.id.to_s, '14.95', '--force'])
|
78
|
+
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
80
79
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
81
80
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
82
81
|
Zold::Merge.new(
|
83
|
-
|
84
|
-
copies: copies
|
85
|
-
).run
|
82
|
+
wallets: Zold::Wallets.new(dir),
|
83
|
+
copies: copies.root
|
84
|
+
).run([id.to_s])
|
86
85
|
end
|
87
86
|
end
|
88
87
|
end
|
data/test/commands/test_node.rb
CHANGED
@@ -21,15 +21,15 @@
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'webmock/minitest'
|
24
|
-
require_relative '../../lib/zold/wallet
|
25
|
-
require_relative '../../lib/zold/remotes
|
26
|
-
require_relative '../../lib/zold/id
|
27
|
-
require_relative '../../lib/zold/copies
|
28
|
-
require_relative '../../lib/zold/key
|
29
|
-
require_relative '../../lib/zold/commands/node
|
30
|
-
require_relative '../../lib/zold/commands/fetch
|
31
|
-
require_relative '../../lib/zold/commands/push
|
32
|
-
require_relative '../node/fake_node
|
24
|
+
require_relative '../../lib/zold/wallet'
|
25
|
+
require_relative '../../lib/zold/remotes'
|
26
|
+
require_relative '../../lib/zold/id'
|
27
|
+
require_relative '../../lib/zold/copies'
|
28
|
+
require_relative '../../lib/zold/key'
|
29
|
+
require_relative '../../lib/zold/commands/node'
|
30
|
+
require_relative '../../lib/zold/commands/fetch'
|
31
|
+
require_relative '../../lib/zold/commands/push'
|
32
|
+
require_relative '../node/fake_node'
|
33
33
|
|
34
34
|
# NODE test.
|
35
35
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|