zold 0.14.22 → 0.14.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1349198ae31f7ea254f40483c00e6f0bcc151933
4
- data.tar.gz: 98293d01a30c67585ffae271f12521749bfd2c29
3
+ metadata.gz: e655198a8ea3c0a9138c5f9b9d2659163cf5a64a
4
+ data.tar.gz: 6439cd7caedd7c330fe7290a5287dcd0c47d789c
5
5
  SHA512:
6
- metadata.gz: 223a08a21b6c7709751192614a1a5eac38ca348f16f879bc3fa1d12321108cf594bff151a5a6d11f5778f52c3d64c0e871c600d6e1a02a29caebc5525d551cf6
7
- data.tar.gz: 0e9398811135a57a1aa31b3a4d2ee490e2223f4d05e11bbfc3b1fc019e99d0b7417dd84bbcdb5d06b270dd62d2b804c1a01f94c7acbd77e7c1b08d7cf06238f4
6
+ metadata.gz: ac548ed4b690c03c0bcf84c1961faff7c6460d8af7e677619a5ef15049f460767cf911bdef2c2512964f4bf70ffacf1872e23a8647dd3eaa8a1d3e2592667eb5
7
+ data.tar.gz: d278d016675843be28fa12df17c2958bdbf07fbc46e283aa3fd6a6e1fe922deb7893e28035c66578b57e98fbfa7b5ab65530fc94fb6940616cd610078520c884
data/lib/zold/tax.rb CHANGED
@@ -48,7 +48,7 @@ module Zold
48
48
  TRIAL = Amount.new(zld: 1.0)
49
49
 
50
50
  # For how many days to pay at once.
51
- DAYS_INCREMENT = 32
51
+ DAYS_INCREMENT = 64
52
52
 
53
53
  # Text prefix for taxes details
54
54
  PREFIX = 'TAXES'
@@ -86,7 +86,7 @@ module Zold
86
86
  next if t.amount > Tax::MAX_PAYMENT
87
87
  t
88
88
  end.reject(&:nil?).uniq(&:details)
89
- paid = scored.empty? ? Amount::ZERO : scored.map(&:amount).inject(&:+) * -1
89
+ paid = scored.empty? ? Amount::ZERO : scored.map(&:amount).inject(&:+)
90
90
  owned = Tax::FEE_TXN_HOUR * txns.count * @wallet.age
91
91
  owned - paid
92
92
  end
data/lib/zold/version.rb CHANGED
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.14.22'
28
+ VERSION = '0.14.23'
29
29
  PROTOCOL = 2
30
30
  end
data/lib/zold/wallet.rb CHANGED
@@ -161,7 +161,7 @@ module Zold
161
161
  # Age of wallet in hours
162
162
  def age
163
163
  list = txns
164
- list.empty? ? 0 : (Time.now - list.min_by(&:date).date) / 60
164
+ list.empty? ? 0 : (Time.now - list.min_by(&:date).date) / (60 * 60)
165
165
  end
166
166
 
167
167
  def txns
@@ -94,12 +94,14 @@ class TestRemote < Minitest::Test
94
94
  def test_remote_trim_with_tolerate
95
95
  Dir.mktmpdir do |dir|
96
96
  remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
97
- zero = Zold::Score::ZERO
98
- stub_request(:get, "http://#{zero.host}:#{zero.port}/remotes").to_return(
97
+ score = Zold::Score.new(
98
+ time: Time.now, host: 'aa1.example.org', port: 9999, invoice: 'NOPREFIX4@ffffffffffffffff'
99
+ )
100
+ stub_request(:get, "http://#{score.host}:#{score.port}/remotes").to_return(
99
101
  status: 200,
100
102
  body: {
101
103
  version: Zold::VERSION,
102
- score: zero.to_h,
104
+ score: score.to_h,
103
105
  all: [
104
106
  { host: 'localhost', port: 8883 }
105
107
  ]
@@ -109,7 +111,7 @@ class TestRemote < Minitest::Test
109
111
  cmd = Zold::Remote.new(remotes: remotes, log: test_log)
110
112
  cmd.run(%w[remote clean])
111
113
  assert(remotes.all.empty?)
112
- cmd.run(['remote', 'add', zero.host, zero.port.to_s, '--skip-ping'])
114
+ cmd.run(['remote', 'add', score.host, score.port.to_s, '--skip-ping'])
113
115
  cmd.run(['remote', 'update', '--ignore-score-weakness', '--skip-ping'])
114
116
  assert_equal(2, remotes.all.count)
115
117
  cmd.run(['remote', 'update', '--ignore-score-weakness'])
data/test/test_tax.rb CHANGED
@@ -54,29 +54,49 @@ class TestTax < Minitest::Test
54
54
  )
55
55
  )
56
56
  tax = Zold::Tax.new(wallet)
57
- assert(tax.debt > Zold::Amount.new(coins: 1_006_523_000))
58
- assert(tax.debt < Zold::Amount.new(coins: 1_006_524_999))
57
+ assert(tax.debt > Zold::Amount.new(coins: 16_770_000))
58
+ assert(tax.debt < Zold::Amount.new(coins: 16_790_000))
59
59
  end
60
60
  end
61
61
 
62
62
  def test_calculates_debt
63
63
  FakeHome.new.run do |home|
64
64
  wallet = home.create_wallet
65
- wallet.add(
66
- Zold::Txn.new(
67
- 1,
68
- Time.now - 24 * 60 * 60 * 365,
69
- Zold::Amount.new(zld: 19.99),
70
- 'NOPREFIX', Zold::Id.new, '-'
65
+ (1..30).each do |i|
66
+ wallet.add(
67
+ Zold::Txn.new(
68
+ i + 1,
69
+ Time.now - 24 * 60 * 60 * 365 * 10,
70
+ Zold::Amount.new(zld: i.to_f),
71
+ 'NOPREFIX', Zold::Id.new, '-'
72
+ )
71
73
  )
72
- )
74
+ end
73
75
  score = Zold::Score.new(
74
76
  time: Time.now, host: 'localhost', port: 80, invoice: 'NOPREFIX@cccccccccccccccc',
75
77
  suffixes: %w[A B C D E F G H I J K L M N O P Q R S T U V]
76
78
  )
77
79
  tax = Zold::Tax.new(wallet)
78
- tax.pay(Zold::Key.new(file: 'fixtures/id_rsa'), score)
79
- assert(tax.debt > Zold::Amount::ZERO)
80
+ txn = tax.pay(Zold::Key.new(file: 'fixtures/id_rsa'), score)
81
+ assert_equal(-88_243_200, txn.amount.to_i)
82
+ end
83
+ end
84
+
85
+ def test_takes_tax_payment_into_account
86
+ FakeHome.new.run do |home|
87
+ wallet = home.create_wallet
88
+ wallet.add(
89
+ Zold::Txn.new(
90
+ 1,
91
+ Time.now,
92
+ Zold::Amount.new(coins: 95_596_800),
93
+ 'NOPREFIX', Zold::Id.new('912ecc24b32dbe74'),
94
+ "TAXES 6 5b5a21a9 b2.zold.io 1000 DCexx0hG 912ecc24b32dbe74 \
95
+ 386d4a ec9eae 306e3d 119d073 1c00dba 1376703 203589 5b55f7"
96
+ )
97
+ )
98
+ tax = Zold::Tax.new(wallet)
99
+ assert(tax.debt < Zold::Amount::ZERO)
80
100
  end
81
101
  end
82
102
 
data/test/test_wallet.rb CHANGED
@@ -109,6 +109,22 @@ class TestWallet < Minitest::Test
109
109
  end
110
110
  end
111
111
 
112
+ def test_calculates_wallet_age_in_hours
113
+ FakeHome.new.run do |home|
114
+ wallet = home.create_wallet
115
+ hours = 100
116
+ wallet.add(
117
+ Zold::Txn.new(
118
+ 1,
119
+ Time.now - 100 * 60 * 60,
120
+ Zold::Amount.new(zld: 1.99),
121
+ 'NOPREFIX', Zold::Id.new, '-'
122
+ )
123
+ )
124
+ assert_equal(hours, wallet.age.round)
125
+ end
126
+ end
127
+
112
128
  def test_returns_modified_time
113
129
  FakeHome.new.run do |home|
114
130
  wallet = home.create_wallet
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.14.22
4
+ version: 0.14.23
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-07-27 00:00:00.000000000 Z
11
+ date: 2018-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby