zold 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -2
  3. data/bin/zold +34 -48
  4. data/features/cli.feature +1 -1
  5. data/features/step_definitions/steps.rb +1 -3
  6. data/features/support/env.rb +2 -0
  7. data/fixtures/scripts/push-and-pull.sh +6 -4
  8. data/lib/zold/amount.rb +17 -3
  9. data/lib/zold/commands/create.rb +9 -6
  10. data/lib/zold/commands/fetch.rb +11 -21
  11. data/lib/zold/commands/node.rb +7 -9
  12. data/lib/zold/commands/pay.rb +9 -6
  13. data/lib/zold/commands/propagate.rb +4 -5
  14. data/lib/zold/commands/push.rb +10 -5
  15. data/lib/zold/commands/remote.rb +22 -24
  16. data/lib/zold/commands/show.rb +1 -2
  17. data/lib/zold/commands/taxes.rb +154 -0
  18. data/lib/zold/http.rb +1 -3
  19. data/lib/zold/key.rb +1 -3
  20. data/lib/zold/node/entrance.rb +8 -3
  21. data/lib/zold/node/farm.rb +8 -6
  22. data/lib/zold/node/front.rb +0 -1
  23. data/lib/zold/patch.rb +1 -1
  24. data/lib/zold/remotes.rb +4 -0
  25. data/lib/zold/score.rb +85 -10
  26. data/lib/zold/signature.rb +7 -7
  27. data/lib/zold/tax.rb +79 -0
  28. data/lib/zold/txn.rb +12 -7
  29. data/lib/zold/version.rb +1 -1
  30. data/lib/zold/wallet.rb +2 -2
  31. data/test/commands/test_create.rb +3 -4
  32. data/test/commands/test_diff.rb +2 -3
  33. data/test/commands/test_merge.rb +4 -6
  34. data/test/commands/test_pay.rb +7 -5
  35. data/test/commands/test_remote.rb +5 -3
  36. data/test/commands/test_taxes.rb +66 -0
  37. data/test/node/fake_node.rb +1 -0
  38. data/test/node/test_farm.rb +2 -1
  39. data/test/node/test_front.rb +1 -0
  40. data/test/test__helper.rb +2 -0
  41. data/test/test_remotes.rb +0 -1
  42. data/test/test_score.rb +40 -21
  43. data/test/test_signature.rb +6 -3
  44. data/test/test_tax.rb +53 -0
  45. data/test/test_txn.rb +46 -0
  46. data/test/test_wallet.rb +2 -2
  47. data/test/test_zold.rb +1 -1
  48. data/wp/.gitignore +6 -0
  49. data/wp/wp.tex +38 -0
  50. data/zold.gemspec +1 -3
  51. metadata +12 -2
@@ -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
+ '--invoice', 'NOPREFIX@ffffffffffffffff',
48
49
  '--port', port.to_s,
49
50
  '--host=locahost',
50
51
  '--bind-port', port.to_s,
@@ -21,11 +21,12 @@
21
21
  require 'minitest/autorun'
22
22
  require 'rack/test'
23
23
  require 'tmpdir'
24
+ require_relative '../../lib/zold/log'
24
25
  require_relative '../../lib/zold/node/farm'
25
26
 
26
27
  class FarmTest < Minitest::Test
27
28
  def test_makes_best_score_in_background
28
- farm = Zold::Farm.new
29
+ farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff')
29
30
  farm.start('localhost', 80, threads: 4, strength: 2)
30
31
  sleep 1 while farm.best.empty? || farm.best[0].value.zero?
31
32
  assert(farm.best[0].value > 0)
@@ -22,6 +22,7 @@ require 'minitest/autorun'
22
22
  require 'tmpdir'
23
23
  require_relative '../../lib/zold/key'
24
24
  require_relative '../../lib/zold/id'
25
+ require_relative '../../lib/zold/log'
25
26
  require_relative '../../lib/zold/amount'
26
27
  require_relative '../../lib/zold/wallet'
27
28
  require_relative '../../lib/zold/http'
data/test/test__helper.rb CHANGED
@@ -20,6 +20,8 @@
20
20
 
21
21
  STDOUT.sync = true
22
22
 
23
+ ENV['RACK_ENV'] = 'test'
24
+
23
25
  require 'simplecov'
24
26
  SimpleCov.start
25
27
  if ENV['CI'] == 'true'
data/test/test_remotes.rb CHANGED
@@ -33,7 +33,6 @@ class TestRemotes < Minitest::Test
33
33
  FileUtils.touch(file)
34
34
  remotes = Zold::Remotes.new(file)
35
35
  remotes.add('127.0.0.1')
36
- remotes.add('127.0.0.1')
37
36
  assert(1, remotes.all.count)
38
37
  end
39
38
  end
data/test/test_score.rb CHANGED
@@ -28,20 +28,11 @@ require_relative '../lib/zold/score'
28
28
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
29
29
  # License:: MIT
30
30
  class TestScore < Minitest::Test
31
- def test_validates_score
32
- score = Zold::Score.new(
33
- Time.parse('2017-07-19T21:24:51Z'),
34
- 'localhost', 443,
35
- %w[9a81d5 40296e], strength: 6
36
- )
37
- assert(score.valid?)
38
- assert_equal(score.value, 2)
39
- end
40
-
41
31
  def test_reduces_itself
42
32
  score = Zold::Score.new(
43
33
  Time.parse('2017-07-19T21:24:51Z'),
44
- 'localhost', 443, %w[A B C D E F G]
34
+ 'localhost', 443, 'NOPREFIX@ffffffffffffffff',
35
+ %w[A B C D E F G]
45
36
  ).reduced(2)
46
37
  assert_equal(score.value, 2)
47
38
  end
@@ -49,9 +40,10 @@ class TestScore < Minitest::Test
49
40
  def test_validates_wrong_score
50
41
  score = Zold::Score.new(
51
42
  Time.parse('2017-07-19T21:24:51Z'),
52
- 'localhost', 443, %w[xxx yyy zzz]
43
+ 'localhost', 443, 'NOPREFIX@ffffffffffffffff',
44
+ %w[xxx yyy zzz]
53
45
  )
54
- assert_equal(score.value, 3)
46
+ assert_equal(3, score.value)
55
47
  assert(!score.valid?)
56
48
  end
57
49
 
@@ -59,21 +51,48 @@ class TestScore < Minitest::Test
59
51
  time = Time.now
60
52
  score = Zold::Score.parse(
61
53
  Zold::Score.new(
62
- time, 'localhost', 999, %w[FIRST SECOND THIRD]
54
+ time, 'localhost', 999, 'NOPREFIX@ffffffffffffffff',
55
+ %w[FIRST SECOND THIRD]
63
56
  ).to_s
64
57
  )
65
- assert_equal(score.value, 3)
58
+ assert_equal(3, score.value)
59
+ assert_equal(score.time.to_s, time.to_s)
60
+ assert_equal('localhost', score.host)
61
+ assert_equal(999, score.port)
62
+ end
63
+
64
+ def test_prints_and_parses_text
65
+ time = Time.now
66
+ score = Zold::Score.parse_text(
67
+ Zold::Score.new(
68
+ time, 'a.example.com', 999, 'NOPREFIX@ffffffffffffffff',
69
+ %w[FIRST SECOND THIRD]
70
+ ).to_text
71
+ )
72
+ assert_equal(3, score.value)
66
73
  assert_equal(score.time.to_s, time.to_s)
67
- assert_equal(score.host, 'localhost')
68
- assert_equal(score.port, 999)
74
+ assert_equal('a.example.com', score.host)
75
+ assert_equal(999, score.port)
76
+ end
77
+
78
+ def test_prints_and_parses_text_zero_score
79
+ time = Time.now
80
+ score = Zold::Score.parse_text(
81
+ Zold::Score.new(
82
+ time, '192.168.0.1', 1, 'NOPREFIX@ffffffffffffffff', []
83
+ ).to_text
84
+ )
85
+ assert_equal(0, score.value)
86
+ assert(!score.expired?)
69
87
  end
70
88
 
71
89
  def test_finds_next_score
72
90
  score = Zold::Score.new(
73
- Time.parse('2017-07-19T21:24:51Z'), 'localhost', 443, strength: 4
74
- ).next
75
- assert_equal(score.value, 1)
76
- assert_equal(score.to_s, '1: 2017-07-19T21:24:51Z localhost 443 1169e')
91
+ Time.now, 'localhost', 443,
92
+ 'NOPREFIX@ffffffffffffffff', strength: 2
93
+ ).next.next.next
94
+ assert_equal(3, score.value)
77
95
  assert(score.valid?)
96
+ assert(!score.expired?)
78
97
  end
79
98
  end
@@ -22,6 +22,7 @@ require 'minitest/autorun'
22
22
  require 'tmpdir'
23
23
  require_relative '../lib/zold/key'
24
24
  require_relative '../lib/zold/id'
25
+ require_relative '../lib/zold/txn'
25
26
  require_relative '../lib/zold/amount'
26
27
  require_relative '../lib/zold/signature'
27
28
 
@@ -35,9 +36,11 @@ class TestSignature < Minitest::Test
35
36
  pub = Zold::Key.new(file: 'fixtures/id_rsa.pub')
36
37
  txn = Zold::Txn.new(
37
38
  123, Time.now, Zold::Amount.new(zld: 14.95),
38
- 'NOPREFIX', Zold::Id.new, '-'
39
+ 'NOPREFIX', Zold::Id.new, 'hello, world!'
39
40
  )
40
- txn = txn.signed(pvt)
41
- assert(Zold::Signature.new.valid?(pub, txn))
41
+ id = Zold::Id.new
42
+ txn = txn.signed(pvt, id)
43
+ assert_equal(684, txn.sign.length)
44
+ assert(Zold::Signature.new.valid?(pub, id, txn))
42
45
  end
43
46
  end
data/test/test_tax.rb ADDED
@@ -0,0 +1,53 @@
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 'time'
24
+ require_relative '../lib/zold/id'
25
+ require_relative '../lib/zold/txn'
26
+ require_relative '../lib/zold/wallet'
27
+ require_relative '../lib/zold/tax'
28
+ require_relative '../lib/zold/key'
29
+ require_relative '../lib/zold/amount'
30
+
31
+ # Tax test.
32
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
34
+ # License:: MIT
35
+ class TestTax < Minitest::Test
36
+ def test_calculates_tax_for_one_year
37
+ Dir.mktmpdir 'test' do |dir|
38
+ id = Zold::Id.new
39
+ wallet = Zold::Wallet.new(File.join(dir, id.to_s))
40
+ wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
41
+ wallet.add(
42
+ Zold::Txn.new(
43
+ 1,
44
+ Time.now - 24 * 60 * 365,
45
+ Zold::Amount.new(zld: 19.99),
46
+ 'NOPREFIX', Zold::Id.new, '-'
47
+ )
48
+ )
49
+ tax = Zold::Tax.new(wallet)
50
+ assert_equal(Zold::Amount.new(coins: 61_320), tax.debt)
51
+ end
52
+ end
53
+ end
data/test/test_txn.rb ADDED
@@ -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 'time'
24
+ require_relative '../lib/zold/id'
25
+ require_relative '../lib/zold/txn'
26
+ require_relative '../lib/zold/amount'
27
+
28
+ # Txn test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestTxn < Minitest::Test
33
+ def test_prints_and_parses
34
+ time = Time.now
35
+ txn = Zold::Txn.parse(
36
+ Zold::Txn.new(
37
+ 123, time, Zold::Amount.new(zld: 99.95),
38
+ 'NOPREFIX', Zold::Id.new,
39
+ 'Some details to see 123. Works, or not.'
40
+ ).to_s
41
+ )
42
+ assert_equal(123, txn.id)
43
+ assert_equal('99.95', txn.amount.to_zld)
44
+ assert_equal('NOPREFIX', txn.prefix)
45
+ end
46
+ end
data/test/test_wallet.rb CHANGED
@@ -41,8 +41,8 @@ class TestWallet < Minitest::Test
41
41
  wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
42
42
  wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
43
43
  assert(
44
- wallet.balance == amount.mul(-3),
45
- "#{wallet.balance} is not equal to #{amount.mul(-3)}"
44
+ wallet.balance == amount * -3,
45
+ "#{wallet.balance} is not equal to #{amount * -3}"
46
46
  )
47
47
  end
48
48
  end
data/test/test_zold.rb CHANGED
@@ -61,7 +61,7 @@ class TestZold < Minitest::Test
61
61
  FileUtils.cp('fixtures/id_rsa.pub', dir)
62
62
  FileUtils.cp('fixtures/id_rsa', dir)
63
63
  stdout = exec(
64
- '--private-key id_rsa --public-key id_rsa.pub --verbose --trace create',
64
+ '--verbose --trace create --public-key=id_rsa.pub',
65
65
  dir
66
66
  )
67
67
  assert(stdout.include?('created at'))
data/wp/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ wp.aux
2
+ wp.bcf
3
+ wp.log
4
+ wp.out
5
+ wp.pdf
6
+ wp.run.xml
data/wp/wp.tex ADDED
@@ -0,0 +1,38 @@
1
+ \documentclass[11pt,oneside]{article}
2
+ \usepackage[utf8]{inputenc}
3
+ \usepackage[american]{babel}
4
+ \usepackage[
5
+ paperwidth=6in, paperheight=9in,
6
+ bindingoffset=0.25in, left=0.75in, right=0.75in, top=0.75in, bottom=1.25in
7
+ ]{geometry}
8
+ \usepackage{setspace}
9
+ \usepackage{indentfirst}
10
+
11
+ \pagestyle{empty}
12
+ \setlength{\topskip}{6pt}
13
+ \setlength{\parindent}{0pt} % indent first line
14
+ \setlength{\parskip}{0pt} % before par
15
+ \interfootnotelinepenalty=10000
16
+ \setstretch{1.1}
17
+
18
+ \usepackage{mathpazo} % Palantino font
19
+
20
+ \usepackage{hyperref}
21
+ \usepackage[style=authoryear,sorting=nyt,backend=biber,
22
+ hyperref=true,abbreviate=true,
23
+ maxcitenames=1,maxbibnames=1]{biblatex}
24
+ \addbibresource{main.bib}
25
+
26
+ \title{Zold, Lightweight Crypto Currency}
27
+ \author{Yegor Bugayenko\\
28
+ CEO of Zerocracy, Inc.\\
29
+ 555 Bryant, Ste 470, Palo Alto, CA 94301\\
30
+ \texttt{yegor@zerocracy.com}\\
31
+ 408.692.4742}
32
+ \begin{document}
33
+
34
+ \raggedbottom
35
+
36
+ how are you?
37
+
38
+ \end{document}
data/zold.gemspec CHANGED
@@ -26,9 +26,7 @@ require_relative 'lib/zold/version'
26
26
 
27
27
  Gem::Specification.new do |s|
28
28
  s.specification_version = 2 if s.respond_to? :specification_version=
29
- if s.respond_to? :required_rubygems_version=
30
- s.required_rubygems_version = Gem::Requirement.new('>= 0')
31
- end
29
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
32
30
  s.rubygems_version = '2.2'
33
31
  s.required_ruby_version = '>= 2.2'
34
32
  s.name = 'zold'
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.5'
4
+ version: '0.6'
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-13 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -288,6 +288,7 @@ files:
288
288
  - lib/zold/commands/push.rb
289
289
  - lib/zold/commands/remote.rb
290
290
  - lib/zold/commands/show.rb
291
+ - lib/zold/commands/taxes.rb
291
292
  - lib/zold/copies.rb
292
293
  - lib/zold/http.rb
293
294
  - lib/zold/id.rb
@@ -301,6 +302,7 @@ files:
301
302
  - lib/zold/remotes.rb
302
303
  - lib/zold/score.rb
303
304
  - lib/zold/signature.rb
305
+ - lib/zold/tax.rb
304
306
  - lib/zold/txn.rb
305
307
  - lib/zold/version.rb
306
308
  - lib/zold/wallet.rb
@@ -317,6 +319,7 @@ files:
317
319
  - test/commands/test_pay.rb
318
320
  - test/commands/test_remote.rb
319
321
  - test/commands/test_show.rb
322
+ - test/commands/test_taxes.rb
320
323
  - test/node/fake_node.rb
321
324
  - test/node/test_farm.rb
322
325
  - test/node/test_front.rb
@@ -331,9 +334,13 @@ files:
331
334
  - test/test_remotes.rb
332
335
  - test/test_score.rb
333
336
  - test/test_signature.rb
337
+ - test/test_tax.rb
338
+ - test/test_txn.rb
334
339
  - test/test_wallet.rb
335
340
  - test/test_wallets.rb
336
341
  - test/test_zold.rb
342
+ - wp/.gitignore
343
+ - wp/wp.tex
337
344
  - zold.gemspec
338
345
  homepage: http://github.com/zerocracy/zold
339
346
  licenses:
@@ -376,6 +383,7 @@ test_files:
376
383
  - test/commands/test_pay.rb
377
384
  - test/commands/test_remote.rb
378
385
  - test/commands/test_show.rb
386
+ - test/commands/test_taxes.rb
379
387
  - test/node/fake_node.rb
380
388
  - test/node/test_farm.rb
381
389
  - test/node/test_front.rb
@@ -390,6 +398,8 @@ test_files:
390
398
  - test/test_remotes.rb
391
399
  - test/test_score.rb
392
400
  - test/test_signature.rb
401
+ - test/test_tax.rb
402
+ - test/test_txn.rb
393
403
  - test/test_wallet.rb
394
404
  - test/test_wallets.rb
395
405
  - test/test_zold.rb