-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsatoshis_per_kilobyte_spec.rb
More file actions
56 lines (43 loc) · 1.78 KB
/
satoshis_per_kilobyte_spec.rb
File metadata and controls
56 lines (43 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
RSpec.describe BSV::Transaction::FeeModels::SatoshisPerKilobyte do
describe '#compute_fee' do
it 'computes fee for a 1 KB transaction at default rate' do
tx = instance_double(BSV::Transaction::Transaction, estimated_size: 1000)
model = described_class.new
expect(model.compute_fee(tx)).to eq(50) # 1000/1000 * 50
end
it 'computes fee for a 250 byte transaction at default rate' do
tx = instance_double(BSV::Transaction::Transaction, estimated_size: 250)
model = described_class.new
expect(model.compute_fee(tx)).to eq(13) # ceil(250/1000 * 50) = ceil(12.5) = 13
end
it 'computes fee with custom rate' do
tx = instance_double(BSV::Transaction::Transaction, estimated_size: 500)
model = described_class.new(value: 100)
expect(model.compute_fee(tx)).to eq(50) # 500/1000 * 100 = 50
end
it 'rounds up to ensure minimum 1 satoshi fee' do
tx = instance_double(BSV::Transaction::Transaction, estimated_size: 1)
model = described_class.new(value: 1)
expect(model.compute_fee(tx)).to eq(1) # ceil(1/1000 * 1) = ceil(0.001) = 1
end
it 'computes correct fee for large transaction' do
tx = instance_double(BSV::Transaction::Transaction, estimated_size: 10_000)
model = described_class.new(value: 50)
expect(model.compute_fee(tx)).to eq(500) # 10000/1000 * 50 = 500
end
end
describe '#value' do
it 'defaults to 50 sat/kB' do
expect(described_class.new.value).to eq(50)
end
it 'accepts a custom rate' do
expect(described_class.new(value: 200).value).to eq(200)
end
end
describe 'inheritance' do
it 'inherits from FeeModel' do
expect(described_class.superclass).to eq(BSV::Transaction::FeeModel)
end
end
end