zold 0.8 → 0.9
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/.gitattributes +1 -0
- data/README.md +16 -8
- data/Rakefile +1 -1
- data/bin/zold +1 -1
- data/lib/zold/amount.rb +11 -3
- data/lib/zold/commands/calculate.rb +5 -0
- data/lib/zold/commands/merge.rb +2 -2
- data/lib/zold/commands/pay.rb +12 -3
- data/lib/zold/commands/taxes.rb +3 -3
- data/lib/zold/node/emission.rb +3 -2
- data/lib/zold/node/entrance.rb +3 -3
- data/lib/zold/patch.rb +2 -1
- data/lib/zold/prefixes.rb +1 -1
- data/lib/zold/score.rb +3 -0
- data/lib/zold/tax.rb +22 -6
- data/lib/zold/txn.rb +4 -3
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +7 -1
- data/test/commands/test_diff.rb +13 -15
- data/test/commands/test_merge.rb +25 -34
- data/test/commands/test_node.rb +2 -2
- data/test/commands/test_pay.rb +5 -10
- data/test/commands/test_taxes.rb +1 -1
- data/test/fake_home.rb +59 -0
- data/test/node/test_emission.rb +4 -6
- data/test/test_amount.rb +2 -2
- data/test/test_patch.rb +7 -9
- data/test/test_prefixes.rb +3 -4
- data/test/test_tax.rb +49 -6
- data/test/test_wallet.rb +9 -34
- data/wp/.gitignore +2 -1
- data/wp/Makefile +6 -1
- data/wp/main.bib +99 -0
- data/wp/wp.pdf +0 -0
- data/wp/wp.tex +296 -145
- data/zold.gemspec +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c679c519c561ea8522e9bddbf1607b376a27088f
|
4
|
+
data.tar.gz: acddc029d1978dd0ba26e8091d56a59a05a3b670
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba1472c49c84588d567e727e1dc364c474715cd9c6914e4f67e42a1addad4462efcd5e723362dddb2c20cf42027591ca15014d05ad9e838ce0a84816f92c49b6
|
7
|
+
data.tar.gz: c6ca405a5f4c99737b6b19836bb141c1b9d8604c355375c40493b2ff8c7d7c1f864e4dab8eb5bc326f6871157c1a73426287e00135ba6e8d48ad160e354df02c
|
data/.gitattributes
CHANGED
data/README.md
CHANGED
@@ -5,21 +5,21 @@
|
|
5
5
|
[](http://www.rultor.com/p/yegor256/Zold)
|
6
6
|
[](https://www.jetbrains.com/ruby/)
|
7
7
|
|
8
|
-
[](https://travis-ci.org/yegor256/zold)
|
9
9
|
[](https://ci.appveyor.com/project/yegor256/zold)
|
10
|
-
[](http://www.0pdd.com/p?name=yegor256/zold)
|
11
11
|
[](http://badge.fury.io/rb/zold)
|
12
|
-
[](https://codecov.io/github/yegor256/zold?branch=master)
|
13
13
|
|
14
|
-
[](https://codeclimate.com/github/
|
14
|
+
[](https://gemnasium.com/yegor256/zold)
|
15
|
+
[](https://codeclimate.com/github/yegor256/zold/maintainability)
|
16
16
|
|
17
17
|
**NOTICE**: It's an experiment and a very early draft! Please, feel free to
|
18
18
|
submit your ideas or pull requests.
|
19
19
|
|
20
|
-
Here is the [White Paper](https://
|
20
|
+
Here is the [White Paper](https://github.com/yegor256/zold/raw/master/wp/wp.pdf).
|
21
21
|
|
22
|
-
The license is [MIT](https://github.com/
|
22
|
+
The license is [MIT](https://github.com/yegor256/zold/blob/master/LICENSE.txt).
|
23
23
|
|
24
24
|
## How to Use
|
25
25
|
|
@@ -108,7 +108,15 @@ $ bundle update
|
|
108
108
|
$ rake
|
109
109
|
```
|
110
110
|
|
111
|
-
The build has to be clean. If it's not, [submit an issue](https://github.com/
|
111
|
+
The build has to be clean. If it's not, [submit an issue](https://github.com/yegor256/zold/issues).
|
112
112
|
|
113
113
|
Then, make your changes, make sure the build is still clean,
|
114
114
|
and [submit a pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
115
|
+
|
116
|
+
If some test fails and you need to run it individually,
|
117
|
+
check the logging configuration inside `test__helper.rb` and make
|
118
|
+
sure the `Verbose` log is assigned to `$log`. Then, run, for example:
|
119
|
+
|
120
|
+
```bash
|
121
|
+
ruby test/commands/test_node.rb
|
122
|
+
```
|
data/Rakefile
CHANGED
@@ -73,7 +73,7 @@ desc 'Validate all XML/XSL/XSD/HTML files for formatting'
|
|
73
73
|
Xcop::RakeTask.new :xcop do |task|
|
74
74
|
task.license = 'LICENSE.txt'
|
75
75
|
task.includes = ['**/*.xml', '**/*.xsl', '**/*.xsd', '**/*.html']
|
76
|
-
task.excludes = ['target/**/*', 'coverage/**/*']
|
76
|
+
task.excludes = ['target/**/*', 'coverage/**/*', 'wp/**/*']
|
77
77
|
end
|
78
78
|
|
79
79
|
task :copyright do
|
data/bin/zold
CHANGED
@@ -136,7 +136,7 @@ Available options:"
|
|
136
136
|
Zold::Invoice.new(wallets: wallets, log: log).run(args)
|
137
137
|
when 'pay'
|
138
138
|
require_relative '../lib/zold/commands/pay'
|
139
|
-
Zold::Pay.new(wallets: wallets, log: log).run(args)
|
139
|
+
Zold::Pay.new(wallets: wallets, remotes: remotes, log: log).run(args)
|
140
140
|
when 'show'
|
141
141
|
require_relative '../lib/zold/commands/show'
|
142
142
|
Zold::Show.new(wallets: wallets, log: log).run(args)
|
data/lib/zold/amount.rb
CHANGED
@@ -27,16 +27,24 @@ require 'rainbow'
|
|
27
27
|
module Zold
|
28
28
|
# Amount
|
29
29
|
class Amount
|
30
|
+
# How many zents are in one ZLD: 2^FRACTION
|
31
|
+
FRACTION = 32
|
32
|
+
|
33
|
+
# Maximum amount of zents
|
34
|
+
MAX = 2**63
|
35
|
+
|
30
36
|
def initialize(coins: nil, zld: nil)
|
31
37
|
if !coins.nil?
|
32
38
|
raise "Integer is required, while #{coins.class} provided: #{coins}" unless coins.is_a?(Integer)
|
33
39
|
@coins = coins
|
34
40
|
elsif !zld.nil?
|
35
41
|
raise "Float is required, while #{zld.class} provided: #{zld}" unless zld.is_a?(Float)
|
36
|
-
@coins = (zld * 2**
|
42
|
+
@coins = (zld * 2**Amount::FRACTION).to_i
|
37
43
|
else
|
38
44
|
raise 'You can\'t specify both coints and zld'
|
39
45
|
end
|
46
|
+
raise "The amount is too big: #{@coins}" if @coins > Amount::MAX
|
47
|
+
raise "The amount is too small: #{@coins}" if @coins < -Amount::MAX
|
40
48
|
end
|
41
49
|
|
42
50
|
ZERO = Amount.new(coins: 0)
|
@@ -46,7 +54,7 @@ module Zold
|
|
46
54
|
end
|
47
55
|
|
48
56
|
def to_zld
|
49
|
-
format('%0.2f', @coins.to_f / 2**
|
57
|
+
format('%0.2f', @coins.to_f / 2**Amount::FRACTION)
|
50
58
|
end
|
51
59
|
|
52
60
|
def to_s
|
@@ -98,7 +106,7 @@ module Zold
|
|
98
106
|
|
99
107
|
def *(other)
|
100
108
|
c = (@coins * other).to_i
|
101
|
-
raise "Overflow, can't multiply #{@coins} by #{m}" if c >
|
109
|
+
raise "Overflow, can't multiply #{@coins} by #{m}" if c > Amount::MAX
|
102
110
|
Amount.new(coins: c)
|
103
111
|
end
|
104
112
|
end
|
@@ -52,6 +52,8 @@ Available options:"
|
|
52
52
|
default: 8
|
53
53
|
o.bool '--hide-hash', 'Don\'t print hash',
|
54
54
|
default: false
|
55
|
+
o.bool '--hide-time', 'Don\'t print calculation time per each score',
|
56
|
+
default: false
|
55
57
|
o.bool '--help', 'Print instructions'
|
56
58
|
end
|
57
59
|
if opts.help?
|
@@ -63,6 +65,7 @@ Available options:"
|
|
63
65
|
|
64
66
|
def calculate(opts)
|
65
67
|
start = Time.now
|
68
|
+
mstart = Time.now
|
66
69
|
strength = opts[:strength]
|
67
70
|
raise "Invalid strength: #{strength}" if strength <= 0 || strength > 8
|
68
71
|
score = Zold::Score.new(
|
@@ -72,8 +75,10 @@ Available options:"
|
|
72
75
|
loop do
|
73
76
|
msg = score.to_s
|
74
77
|
msg += (score.value > 0 ? ' ' + score.hash : '') unless opts['hide-hash']
|
78
|
+
msg += " #{(Time.now - mstart).round(2)}s" unless opts['hide-time']
|
75
79
|
@log.info(msg)
|
76
80
|
break if score.value >= opts[:max].to_i
|
81
|
+
mstart = Time.now
|
77
82
|
score = score.next
|
78
83
|
end
|
79
84
|
seconds = (Time.now - start).round(2)
|
data/lib/zold/commands/merge.rb
CHANGED
@@ -69,9 +69,9 @@ Available options:"
|
|
69
69
|
end
|
70
70
|
modified = patch.save(wallet.path, overwrite: true)
|
71
71
|
if modified
|
72
|
-
@log.debug("
|
72
|
+
@log.debug("#{cps.count} copies merged successfully into #{wallet.path}")
|
73
73
|
else
|
74
|
-
@log.debug("Nothing changed in #{wallet.path} after merge")
|
74
|
+
@log.debug("Nothing changed in #{wallet.path} after merge of #{cps.count} copies")
|
75
75
|
end
|
76
76
|
modified
|
77
77
|
end
|
data/lib/zold/commands/pay.rb
CHANGED
@@ -30,8 +30,9 @@ require_relative '../log'
|
|
30
30
|
module Zold
|
31
31
|
# Money sending command
|
32
32
|
class Pay
|
33
|
-
def initialize(wallets:, log: Log::Quiet.new)
|
33
|
+
def initialize(wallets:, remotes:, log: Log::Quiet.new)
|
34
34
|
@wallets = wallets
|
35
|
+
@remotes = remotes
|
35
36
|
@log = log
|
36
37
|
end
|
37
38
|
|
@@ -51,11 +52,14 @@ Available options:"
|
|
51
52
|
o.bool '--force',
|
52
53
|
'Ignore all validations',
|
53
54
|
default: false
|
55
|
+
o.bool '--dont-pay-taxes',
|
56
|
+
'Don\'t pay taxes even if the wallet is in debt',
|
57
|
+
default: false
|
54
58
|
o.bool '--help', 'Print instructions'
|
55
59
|
end
|
56
60
|
mine = Args.new(opts, @log).take || return
|
57
61
|
raise 'Payer wallet ID is required as the first argument' if mine[0].nil?
|
58
|
-
from = @wallets.find(
|
62
|
+
from = @wallets.find(Id.new(mine[0]))
|
59
63
|
raise 'Wallet doesn\'t exist, do \'fetch\' first' unless from.exists?
|
60
64
|
raise 'Recepient\'s invoice or wallet ID is required as the second argument' if mine[1].nil?
|
61
65
|
invoice = mine[1]
|
@@ -64,8 +68,13 @@ Available options:"
|
|
64
68
|
invoice = Invoice.new(wallets: @wallets, log: @log).run(['invoice', invoice])
|
65
69
|
end
|
66
70
|
raise 'Amount is required (in ZLD) as the third argument' if mine[2].nil?
|
67
|
-
amount =
|
71
|
+
amount = Amount.new(zld: mine[2].to_f)
|
68
72
|
details = mine[3] ? mine[3] : '-'
|
73
|
+
if Tax.new(from).in_debt? && !opts['dont-pay-taxes']
|
74
|
+
Taxes.new(wallets: @wallets, remotes: @remotes, log: @log).run(
|
75
|
+
['taxes', "--private-key=#{opts['private-key']}", id.to_s]
|
76
|
+
)
|
77
|
+
end
|
69
78
|
pay(from, invoice, amount, details, opts)
|
70
79
|
end
|
71
80
|
|
data/lib/zold/commands/taxes.rb
CHANGED
@@ -87,7 +87,7 @@ Available options:"
|
|
87
87
|
tax = Tax.new(wallet)
|
88
88
|
debt = tax.debt
|
89
89
|
@log.debug("The current debt is #{debt} (#{debt.to_i} zents)")
|
90
|
-
|
90
|
+
unless debt.in_debt?
|
91
91
|
@log.debug("No need to pay taxes yet, until the debt is less than #{Tax::TRIAL} (#{Tax::TRIAL.to_i} zents)")
|
92
92
|
return
|
93
93
|
end
|
@@ -144,8 +144,8 @@ Available options:"
|
|
144
144
|
@log.info("#{name} score #{Rainbow(score.value).red} is too weak (<#{Score::STRENGTH})")
|
145
145
|
next
|
146
146
|
end
|
147
|
-
if score.value < Tax::
|
148
|
-
@log.info("#{name} score #{Rainbow(score.value).red} is too small (<#{Tax::
|
147
|
+
if score.value < Tax::EXACT_SCORE
|
148
|
+
@log.info("#{name} score #{Rainbow(score.value).red} is too small (<#{Tax::EXACT_SCORE})")
|
149
149
|
next
|
150
150
|
end
|
151
151
|
@log.info("#{score.host}:#{score.port}: #{Rainbow(score.value).green}")
|
data/lib/zold/node/emission.rb
CHANGED
data/lib/zold/node/entrance.rb
CHANGED
@@ -61,9 +61,9 @@ module Zold
|
|
61
61
|
balance = wallet.balance
|
62
62
|
raise "The balance #{balance} is negative and it's not a root wallet" if balance.negative? && !wallet.root?
|
63
63
|
Emission.new(wallet).check
|
64
|
-
|
65
|
-
if
|
66
|
-
raise "Taxes are not paid, the debt is #{debt} (#{debt.to_i} zents)
|
64
|
+
tax = Tax.new(wallet)
|
65
|
+
if tax.in_debt?
|
66
|
+
raise "Taxes are not paid, can't accept the wallet; the debt is #{tax.debt} (#{tax.debt.to_i} zents)"
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/lib/zold/patch.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require_relative 'wallet'
|
22
|
+
require_relative 'signature'
|
22
23
|
|
23
24
|
# Patch.
|
24
25
|
#
|
@@ -57,7 +58,7 @@ module Zold
|
|
57
58
|
def save(file, overwrite: false)
|
58
59
|
before = ''
|
59
60
|
before = File.read(file) if File.exist?(file)
|
60
|
-
wallet =
|
61
|
+
wallet = Wallet.new(file)
|
61
62
|
wallet.init(@id, @key, overwrite: overwrite, network: @network)
|
62
63
|
@txns.each { |t| wallet.add(t) }
|
63
64
|
after = File.read(file)
|
data/lib/zold/prefixes.rb
CHANGED
data/lib/zold/score.rb
CHANGED
@@ -29,7 +29,9 @@ require_relative 'remotes'
|
|
29
29
|
module Zold
|
30
30
|
# Score
|
31
31
|
class Score
|
32
|
+
# Default strength for the entire system, in production mode.
|
32
33
|
STRENGTH = 6
|
34
|
+
|
33
35
|
attr_reader :time, :host, :port, :invoice, :strength
|
34
36
|
# time: UTC ISO 8601 string
|
35
37
|
def initialize(time, host, port, invoice, suffixes = [], strength: STRENGTH)
|
@@ -140,6 +142,7 @@ module Zold
|
|
140
142
|
end
|
141
143
|
|
142
144
|
def reduced(max = 4)
|
145
|
+
raise "The length of the score is #{@suffixes.count}, can't reduce to #{max}" if max > @suffixes.count
|
143
146
|
Score.new(
|
144
147
|
@time, @host, @port, @invoice,
|
145
148
|
@suffixes[0..max - 1], strength: @strength
|
data/lib/zold/tax.rb
CHANGED
@@ -31,8 +31,8 @@ require_relative 'amount'
|
|
31
31
|
module Zold
|
32
32
|
# A single tax payment
|
33
33
|
class Tax
|
34
|
-
# The
|
35
|
-
|
34
|
+
# The exact score a wallet can buy in order to pay taxes.
|
35
|
+
EXACT_SCORE = 16
|
36
36
|
|
37
37
|
# The maximum allowed amount in one transaction.
|
38
38
|
MAX_PAYMENT = Amount.new(zld: 1.0)
|
@@ -49,22 +49,38 @@ module Zold
|
|
49
49
|
# For how many days to pay at once.
|
50
50
|
DAYS_INCREMENT = 32
|
51
51
|
|
52
|
+
# Text prefix for taxes details
|
53
|
+
PREFIX = 'TAXES'.freeze
|
54
|
+
|
52
55
|
def initialize(wallet)
|
53
56
|
@wallet = wallet
|
54
57
|
end
|
55
58
|
|
59
|
+
# Check whether this tax payment already exists in the wallet.
|
60
|
+
def exists?(txn)
|
61
|
+
!@wallet.txns.find { |t| t.details.start_with?("#{Tax::PREFIX} ") && t.details == txn.details }.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
def details(best)
|
65
|
+
"#{Tax::PREFIX} #{best.reduced(Tax::EXACT_SCORE).to_text}"
|
66
|
+
end
|
67
|
+
|
56
68
|
def pay(pvt, best)
|
57
|
-
fee = Tax::
|
58
|
-
@wallet.sub(fee, best.invoice, pvt,
|
69
|
+
fee = Tax::FEE_TXN_HOUR * @wallet.txns.count * Tax::DAYS_INCREMENT * 24
|
70
|
+
@wallet.sub(fee, best.invoice, pvt, details(best))
|
71
|
+
end
|
72
|
+
|
73
|
+
def in_debt?
|
74
|
+
debt > Tax::TRIAL
|
59
75
|
end
|
60
76
|
|
61
77
|
def debt
|
62
78
|
txns = @wallet.txns
|
63
79
|
scores = txns.map do |t|
|
64
80
|
pfx, body = t.details.split(' ')
|
65
|
-
next if pfx !=
|
81
|
+
next if pfx != Tax::PREFIX || body.nil?
|
66
82
|
score = Score.parse_text(body)
|
67
|
-
next if !score.valid? || score.value
|
83
|
+
next if !score.valid? || score.value != Tax::EXACT_SCORE
|
68
84
|
next if t.amount > Tax::MAX_PAYMENT
|
69
85
|
score
|
70
86
|
end.reject(&:nil?).uniq(&:hash)
|
data/lib/zold/txn.rb
CHANGED
@@ -52,11 +52,12 @@ module Zold
|
|
52
52
|
raise 'Prefix can\'t be NIL' if prefix.nil?
|
53
53
|
raise "Prefix is too short: \"#{prefix}\"" if prefix.length < 8
|
54
54
|
raise "Prefix is too long: \"#{prefix}\"" if prefix.length > 32
|
55
|
+
raise "Prefix is wrong: \"#{prefix}\"" unless prefix =~ /^[a-zA-Z0-9]+$/
|
55
56
|
@prefix = prefix
|
56
57
|
raise 'Details can\'t be NIL' if details.nil?
|
57
58
|
raise 'Details can\'t be empty' if details.empty?
|
58
|
-
raise "Details are too long: \"#{details}\"" if details.length >
|
59
|
-
raise "Details are wrong: \"#{details}\"" unless details =~ /^[a-zA-Z0-9 -\.,]
|
59
|
+
raise "Details are too long: \"#{details}\"" if details.length > 512
|
60
|
+
raise "Details are wrong: \"#{details}\"" unless details =~ /^[a-zA-Z0-9 -\.,]+$/
|
60
61
|
@details = details
|
61
62
|
end
|
62
63
|
|
@@ -101,7 +102,7 @@ module Zold
|
|
101
102
|
'([0-9a-f]{16})',
|
102
103
|
'([A-Za-z0-9]{8,32})',
|
103
104
|
'([0-9a-f]{16})',
|
104
|
-
'([a-zA-Z0-9 -\.,]{1,
|
105
|
+
'([a-zA-Z0-9 -\.,]{1,512})',
|
105
106
|
'([A-Za-z0-9+/]+={0,3})?'
|
106
107
|
].join(';') + '$'
|
107
108
|
)
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallet.rb
CHANGED
@@ -23,6 +23,7 @@ require_relative 'version'
|
|
23
23
|
require_relative 'key'
|
24
24
|
require_relative 'id'
|
25
25
|
require_relative 'txn'
|
26
|
+
require_relative 'tax'
|
26
27
|
require_relative 'amount'
|
27
28
|
require_relative 'signature'
|
28
29
|
|
@@ -97,8 +98,10 @@ module Zold
|
|
97
98
|
raise "The amount can't be negative: #{amount}" if amount.negative?
|
98
99
|
raise 'The pvt has to be of type Key' unless pvt.is_a?(Key)
|
99
100
|
prefix, target = invoice.split('@')
|
101
|
+
id = max + 1
|
102
|
+
raise 'Too many transactions already, can\'t add more' if max > 0xffff
|
100
103
|
txn = Txn.new(
|
101
|
-
|
104
|
+
id,
|
102
105
|
Time.now,
|
103
106
|
amount * -1,
|
104
107
|
prefix,
|
@@ -112,6 +115,9 @@ module Zold
|
|
112
115
|
|
113
116
|
def add(txn)
|
114
117
|
raise 'The txn has to be of type Txn' unless txn.is_a?(Txn)
|
118
|
+
dup = txns.find { |t| t.bnf == txn.bnf && t.id == txn.id }
|
119
|
+
raise "The transaction with the same ID and BNF already exists: #{dup}" unless dup.nil?
|
120
|
+
raise "The tax payment already exists: #{txn}" if Tax.new(self).exists?(txn)
|
115
121
|
open(@file, 'a') { |f| f.print "#{txn}\n" }
|
116
122
|
end
|
117
123
|
|
data/test/commands/test_diff.rb
CHANGED
@@ -19,10 +19,11 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
|
-
require 'tmpdir'
|
23
22
|
require 'json'
|
24
23
|
require 'time'
|
25
24
|
require 'webmock/minitest'
|
25
|
+
require_relative '../test__helper'
|
26
|
+
require_relative '../fake_home'
|
26
27
|
require_relative '../../lib/zold/wallets'
|
27
28
|
require_relative '../../lib/zold/wallet'
|
28
29
|
require_relative '../../lib/zold/id'
|
@@ -37,24 +38,21 @@ require_relative '../../lib/zold/commands/diff'
|
|
37
38
|
# License:: MIT
|
38
39
|
class TestDiff < Minitest::Test
|
39
40
|
def test_diff_with_copies
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
44
|
-
first = Zold::Wallet.new(File.join(dir, 'copy-1'))
|
41
|
+
FakeHome.new.run do |home|
|
42
|
+
wallet = home.create_wallet
|
43
|
+
first = home.create_wallet
|
45
44
|
File.write(first.path, File.read(wallet.path))
|
46
|
-
second =
|
45
|
+
second = home.create_wallet
|
47
46
|
File.write(second.path, File.read(wallet.path))
|
48
|
-
Zold::Pay.new(
|
49
|
-
|
50
|
-
)
|
51
|
-
copies =
|
47
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: $log).run(
|
48
|
+
['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
|
49
|
+
)
|
50
|
+
copies = home.copies(wallet)
|
52
51
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
53
52
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
54
|
-
diff = Zold::Diff.new(
|
55
|
-
|
56
|
-
|
57
|
-
).run(['diff', id.to_s])
|
53
|
+
diff = Zold::Diff.new(wallets: home.wallets, copies: copies.root, log: $log).run(
|
54
|
+
['diff', wallet.id.to_s]
|
55
|
+
)
|
58
56
|
assert(diff.include?('-0001;'))
|
59
57
|
end
|
60
58
|
end
|
data/test/commands/test_merge.rb
CHANGED
@@ -19,11 +19,10 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
|
-
require 'tmpdir'
|
23
|
-
require 'json'
|
24
22
|
require 'time'
|
25
23
|
require 'webmock/minitest'
|
26
24
|
require_relative '../test__helper'
|
25
|
+
require_relative '../fake_home'
|
27
26
|
require_relative '../../lib/zold/wallet'
|
28
27
|
require_relative '../../lib/zold/wallets'
|
29
28
|
require_relative '../../lib/zold/id'
|
@@ -40,52 +39,44 @@ require_relative '../../lib/zold/commands/pay'
|
|
40
39
|
# License:: MIT
|
41
40
|
class TestMerge < Minitest::Test
|
42
41
|
def test_merges_wallet
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
wallet = Zold::Wallet.new(file)
|
47
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
48
|
-
first = Zold::Wallet.new(File.join(dir, 'copy-1'))
|
42
|
+
FakeHome.new.run do |home|
|
43
|
+
wallet = home.create_wallet
|
44
|
+
first = home.create_wallet
|
49
45
|
File.write(first.path, File.read(wallet.path))
|
50
|
-
second =
|
46
|
+
second = home.create_wallet
|
51
47
|
File.write(second.path, File.read(wallet.path))
|
52
|
-
Zold::Pay.new(
|
53
|
-
|
54
|
-
)
|
55
|
-
copies =
|
48
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: $log).run(
|
49
|
+
['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
|
50
|
+
)
|
51
|
+
copies = home.copies(wallet)
|
56
52
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
57
53
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
58
|
-
modified = Zold::Merge.new(
|
59
|
-
|
60
|
-
|
61
|
-
).run(['merge', id.to_s])
|
54
|
+
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: $log).run(
|
55
|
+
['merge', wallet.id.to_s]
|
56
|
+
)
|
62
57
|
assert(1, modified.count)
|
63
|
-
assert(id, modified[0])
|
58
|
+
assert(wallet.id, modified[0])
|
64
59
|
end
|
65
60
|
end
|
66
61
|
|
67
62
|
def test_merges_into_empty_wallet
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
wallet = Zold::Wallet.new(file)
|
72
|
-
wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
73
|
-
first = Zold::Wallet.new(File.join(dir, 'copy-1'))
|
63
|
+
FakeHome.new.run do |home|
|
64
|
+
wallet = home.create_wallet
|
65
|
+
first = home.create_wallet
|
74
66
|
File.write(first.path, File.read(wallet.path))
|
75
|
-
second =
|
67
|
+
second = home.create_wallet
|
76
68
|
File.write(second.path, File.read(wallet.path))
|
77
|
-
Zold::Pay.new(
|
78
|
-
|
79
|
-
)
|
80
|
-
copies =
|
69
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: $log).run(
|
70
|
+
['pay', wallet.id.to_s, second.id.to_s, '14.95', '--force', '--private-key=fixtures/id_rsa']
|
71
|
+
)
|
72
|
+
copies = home.copies(wallet)
|
81
73
|
copies.add(File.read(first.path), 'host-1', 80, 5)
|
82
74
|
copies.add(File.read(second.path), 'host-2', 80, 5)
|
83
|
-
modified = Zold::Merge.new(
|
84
|
-
|
85
|
-
|
86
|
-
).run(['merge', id.to_s])
|
75
|
+
modified = Zold::Merge.new(wallets: home.wallets, copies: copies.root, log: $log).run(
|
76
|
+
['merge', wallet.id.to_s]
|
77
|
+
)
|
87
78
|
assert(1, modified.count)
|
88
|
-
assert(id, modified[0])
|
79
|
+
assert(wallet.id, modified[0])
|
89
80
|
end
|
90
81
|
end
|
91
82
|
end
|
data/test/commands/test_node.rb
CHANGED
@@ -54,8 +54,8 @@ class TestNode < Minitest::Test
|
|
54
54
|
).run(['fetch'])
|
55
55
|
copies = Zold::Copies.new(File.join(dir, "copies/#{id}"))
|
56
56
|
assert_equal(1, copies.all.count)
|
57
|
-
assert_equal(copies.all[0][:name]
|
58
|
-
assert_equal(copies.all[0][:score]
|
57
|
+
assert_equal('1', copies.all[0][:name])
|
58
|
+
assert_equal(0, copies.all[0][:score])
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/test/commands/test_pay.rb
CHANGED
@@ -33,19 +33,14 @@ require_relative '../../lib/zold/commands/pay'
|
|
33
33
|
# License:: MIT
|
34
34
|
class TestPay < Minitest::Test
|
35
35
|
def test_sends_from_wallet_to_wallet
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
source = wallets.find(sid)
|
40
|
-
source.init(sid, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
41
|
-
tid = Zold::Id.new
|
42
|
-
target = wallets.find(tid)
|
43
|
-
target.init(tid, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
|
36
|
+
FakeHome.new.run do |home|
|
37
|
+
source = home.create_wallet
|
38
|
+
target = home.create_wallet
|
44
39
|
amount = Zold::Amount.new(zld: 14.95)
|
45
|
-
Zold::Pay.new(wallets: wallets, log: $log).run(
|
40
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: $log).run(
|
46
41
|
[
|
47
42
|
'pay', '--force', '--private-key=fixtures/id_rsa',
|
48
|
-
|
43
|
+
source.id.to_s, target.id.to_s, amount.to_zld, 'For the car'
|
49
44
|
]
|
50
45
|
)
|
51
46
|
assert_equal(amount * -1, source.balance)
|
data/test/commands/test_taxes.rb
CHANGED
@@ -61,7 +61,7 @@ class TestTaxes < Minitest::Test
|
|
61
61
|
Zold::Taxes.new(
|
62
62
|
wallets: wallets, remotes: remotes, log: $log
|
63
63
|
).run(['taxes', '--private-key=fixtures/id_rsa', id.to_s])
|
64
|
-
assert_equal(Zold::Amount.new(coins:
|
64
|
+
assert_equal(Zold::Amount.new(coins: 85_856_396_247), wallet.balance)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|