This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
forked from bryanchriswhite/ruby-libstorj
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibstorj_spec.rb
81 lines (66 loc) · 1.95 KB
/
libstorj_spec.rb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
RSpec.describe LibStorj do
describe '.util_timestamp' do
let(:actual) {LibStorj.util_timestamp}
let(:expected) {Time.new.to_f}
it 'returns the current unix timestamp' do
# / 1000 to convert from int of milliseconds to a float of seconds
expect(actual / 1000).to eq(expected.floor)
end
end
describe '.util_datetime' do
let(:util_datetime) do
LibStorj.util_datetime
end
let(:current_timestamp) do
DateTime.now.to_time.to_i
end
def to_timestamp(datetime)
datetime.to_time.to_i
end
it 'returns a `DateTime` object with the correct current time' do
expect(util_datetime).to be_an_instance_of(DateTime)
expect(to_timestamp(util_datetime)).to eq(current_timestamp)
end
end
describe '.mnemonic_check' do
let(:invalid_mnemonic) {'nope'}
let(:valid_mnemonic) do
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
end
context 'with a valid mnenonic' do
let(:mnemonic_check) do
described_class.mnemonic_check valid_mnemonic
end
it 'returns true' do
expect(mnemonic_check).to be(true)
end
end
context 'with an invalid mnenonic' do
let(:mnemonic_check) do
described_class.mnemonic_check invalid_mnemonic
end
it 'returns false' do
expect(mnemonic_check).to be(false)
end
end
end
describe '.mnemonic_generate' do
let(:mnemonic) do
described_class.mnemonic_generate strength
end
context 'with minimum strength' do
let(:strength) {128}
it 'returns a new mnemonic longer than 50 characters' do
actual = mnemonic
expect(actual.length).to be > 50
end
end
context 'with maximum strength' do
let(:strength) {256}
it 'returns a new mnemonic longer than 100 characters' do
actual = mnemonic
expect(actual.length).to be > 100
end
end
end
end