sibit 0.25.1 → 0.27.0
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/Gemfile +18 -28
- data/Gemfile.lock +187 -0
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +80 -60
- data/REUSE.toml +35 -0
- data/Rakefile +3 -29
- data/bin/sibit +9 -28
- data/cucumber.yml +3 -0
- data/features/cli.feature +2 -0
- data/features/gem_package.feature +4 -1
- data/features/step_definitions/steps.rb +2 -19
- data/features/support/env.rb +2 -19
- data/lib/sibit/bestof.rb +5 -22
- data/lib/sibit/bitcoin/base58.rb +50 -0
- data/lib/sibit/bitcoin/key.rb +87 -0
- data/lib/sibit/bitcoin/script.rb +58 -0
- data/lib/sibit/bitcoin/tx.rb +212 -0
- data/lib/sibit/bitcoin/txbuilder.rb +120 -0
- data/lib/sibit/bitcoinchain.rb +5 -22
- data/lib/sibit/blockchain.rb +5 -22
- data/lib/sibit/blockchair.rb +5 -22
- data/lib/sibit/btc.rb +6 -23
- data/lib/sibit/cex.rb +5 -22
- data/lib/sibit/cryptoapis.rb +5 -22
- data/lib/sibit/error.rb +3 -20
- data/lib/sibit/fake.rb +3 -20
- data/lib/sibit/firstof.rb +5 -22
- data/lib/sibit/http.rb +3 -20
- data/lib/sibit/json.rb +6 -23
- data/lib/sibit/version.rb +4 -21
- data/lib/sibit.rb +31 -40
- data/logo.svg +1 -1
- data/sibit.gemspec +16 -32
- metadata +26 -48
- data/.0pdd.yml +0 -9
- data/.gitattributes +0 -7
- data/.github/workflows/codecov.yml +0 -21
- data/.github/workflows/pdd.yml +0 -15
- data/.github/workflows/rake.yml +0 -24
- data/.github/workflows/xcop.yml +0 -17
- data/.gitignore +0 -8
- data/.pdd +0 -7
- data/.rubocop.yml +0 -38
- data/.rultor.yml +0 -21
- data/.simplecov +0 -40
- data/lib/sibit/earn.rb +0 -102
- data/lib/sibit/log.rb +0 -49
- data/renovate.json +0 -6
- data/test/test__helper.rb +0 -29
- data/test/test_bestof.rb +0 -62
- data/test/test_bitcoinchain.rb +0 -73
- data/test/test_blockchain.rb +0 -58
- data/test/test_blockchair.rb +0 -43
- data/test/test_btc.rb +0 -117
- data/test/test_cex.rb +0 -43
- data/test/test_cryptoapis.rb +0 -51
- data/test/test_fake.rb +0 -55
- data/test/test_firstof.rb +0 -62
- data/test/test_json.rb +0 -40
- data/test/test_live.rb +0 -138
- data/test/test_sibit.rb +0 -209
data/lib/sibit/earn.rb
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'iri'
|
|
24
|
-
require 'json'
|
|
25
|
-
require 'uri'
|
|
26
|
-
require_relative 'error'
|
|
27
|
-
require_relative 'http'
|
|
28
|
-
require_relative 'json'
|
|
29
|
-
require_relative 'version'
|
|
30
|
-
|
|
31
|
-
# Earn.com API.
|
|
32
|
-
#
|
|
33
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
34
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
35
|
-
# License:: MIT
|
|
36
|
-
class Sibit
|
|
37
|
-
# Blockchain.info API.
|
|
38
|
-
class Earn
|
|
39
|
-
# Constructor.
|
|
40
|
-
def initialize(log: Sibit::Log.new, http: Sibit::Http.new, dry: false)
|
|
41
|
-
@http = http
|
|
42
|
-
@log = log
|
|
43
|
-
@dry = dry
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Current price of BTC in USD (float returned).
|
|
47
|
-
def price(_currency)
|
|
48
|
-
raise Sibit::NotSupportedError, 'price() doesn\'t work here'
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Gets the balance of the address, in satoshi.
|
|
52
|
-
def balance(_address)
|
|
53
|
-
raise Sibit::NotSupportedError, 'balance() doesn\'t work here'
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Get hash of the block after this one.
|
|
57
|
-
def next_of(_hash)
|
|
58
|
-
raise Sibit::NotSupportedError, 'Earn.com API doesn\'t provide next_of()'
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# The height of the block.
|
|
62
|
-
def height(_hash)
|
|
63
|
-
raise Sibit::NotSupportedError, 'Earn API doesn\'t provide height()'
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Get recommended fees, in satoshi per byte. The method returns
|
|
67
|
-
# a hash: { S: 12, M: 45, L: 100, XL: 200 }
|
|
68
|
-
def fees
|
|
69
|
-
json = Sibit::Json.new(http: @http, log: @log).get(
|
|
70
|
-
Iri.new('https://bitcoinfees.earn.com/api/v1/fees/recommended')
|
|
71
|
-
)
|
|
72
|
-
@log.info("Current recommended Bitcoin fees: \
|
|
73
|
-
#{json['hourFee']}/#{json['halfHourFee']}/#{json['fastestFee']} sat/byte")
|
|
74
|
-
{
|
|
75
|
-
S: json['hourFee'] / 3,
|
|
76
|
-
M: json['hourFee'],
|
|
77
|
-
L: json['halfHourFee'],
|
|
78
|
-
XL: json['fastestFee']
|
|
79
|
-
}
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Fetch all unspent outputs per address.
|
|
83
|
-
def utxos(_sources)
|
|
84
|
-
raise Sibit::NotSupportedError, 'Not implemented yet'
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# Push this transaction (in hex format) to the network.
|
|
88
|
-
def push(_hex)
|
|
89
|
-
raise Sibit::NotSupportedError, 'Not implemented yet'
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# Gets the hash of the latest block.
|
|
93
|
-
def latest
|
|
94
|
-
raise Sibit::NotSupportedError, 'latest() doesn\'t work here'
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# This method should fetch a Blockchain block and return as a hash.
|
|
98
|
-
def block(_hash)
|
|
99
|
-
raise Sibit::NotSupportedError, 'block() doesn\'t work here'
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
data/lib/sibit/log.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
# The log.
|
|
24
|
-
#
|
|
25
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
26
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
27
|
-
# License:: MIT
|
|
28
|
-
class Sibit
|
|
29
|
-
# Log.
|
|
30
|
-
class Log
|
|
31
|
-
# Constructor.
|
|
32
|
-
#
|
|
33
|
-
# You may provide the log you want to see the messages in. If you don't
|
|
34
|
-
# provide anything, the console will be used. The object you provide
|
|
35
|
-
# has to respond to the method +info+ or +puts+ in order to receive logging
|
|
36
|
-
# messages.
|
|
37
|
-
def initialize(log = $stdout)
|
|
38
|
-
@log = log
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def info(msg)
|
|
42
|
-
if @log.respond_to?(:info)
|
|
43
|
-
@log.info(msg)
|
|
44
|
-
elsif @log.respond_to?(:puts)
|
|
45
|
-
@log.puts(msg)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
data/renovate.json
DELETED
data/test/test__helper.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
$stdout.sync = true
|
|
24
|
-
|
|
25
|
-
require 'simplecov'
|
|
26
|
-
SimpleCov.start
|
|
27
|
-
|
|
28
|
-
require 'minitest/autorun'
|
|
29
|
-
require_relative '../lib/sibit'
|
data/test/test_bestof.rb
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require_relative '../lib/sibit'
|
|
25
|
-
require_relative '../lib/sibit/fake'
|
|
26
|
-
require_relative '../lib/sibit/bestof'
|
|
27
|
-
|
|
28
|
-
# Sibit::BestOf test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestBestOf < Minitest::Test
|
|
33
|
-
def test_not_array
|
|
34
|
-
sibit = Sibit::BestOf.new(Sibit::Fake.new)
|
|
35
|
-
assert_equal(64, sibit.latest.length)
|
|
36
|
-
assert_equal(12, sibit.fees[:S])
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_one_apis
|
|
40
|
-
sibit = Sibit::BestOf.new([Sibit::Fake.new])
|
|
41
|
-
assert_equal(64, sibit.latest.length)
|
|
42
|
-
assert_equal(12, sibit.fees[:S])
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_two_apis
|
|
46
|
-
sibit = Sibit::BestOf.new([Sibit::Fake.new, Sibit::Fake.new])
|
|
47
|
-
assert_equal(64, sibit.latest.length)
|
|
48
|
-
assert_equal(12, sibit.fees[:S])
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_all_fail
|
|
52
|
-
api = Class.new do
|
|
53
|
-
def latest
|
|
54
|
-
raise Sibit::Error, 'intentionally'
|
|
55
|
-
end
|
|
56
|
-
end.new
|
|
57
|
-
sibit = Sibit::BestOf.new([api, api])
|
|
58
|
-
assert_raises Sibit::Error do
|
|
59
|
-
sibit.latest
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
data/test/test_bitcoinchain.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require 'json'
|
|
26
|
-
require_relative '../lib/sibit'
|
|
27
|
-
require_relative '../lib/sibit/bitcoinchain'
|
|
28
|
-
|
|
29
|
-
# Sibit::Bitcoinchain test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestBitcoinchain < Minitest::Test
|
|
34
|
-
def test_fetch_hash
|
|
35
|
-
stub_request(
|
|
36
|
-
:get,
|
|
37
|
-
'https://api-r.bitcoinchain.com/v1/status'
|
|
38
|
-
).to_return(body: '{"hash": "test"}')
|
|
39
|
-
sibit = Sibit::Bitcoinchain.new
|
|
40
|
-
hash = sibit.latest
|
|
41
|
-
assert_equal('test', hash)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_fetch_balance
|
|
45
|
-
hash = '1Chain4asCYNnLVbvG6pgCLGBrtzh4Lx4b'
|
|
46
|
-
stub_request(:get, "https://api-r.bitcoinchain.com/v1/address/#{hash}")
|
|
47
|
-
.to_return(body: '[{"balance": 5}]')
|
|
48
|
-
sibit = Sibit::Bitcoinchain.new
|
|
49
|
-
satoshi = sibit.balance(hash)
|
|
50
|
-
assert_equal(500_000_000, satoshi)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_fetch_block
|
|
54
|
-
hash = '000000000000000007341915521967247f1dec17b3a311b8a8f4495392f1439b'
|
|
55
|
-
stub_request(:get, "https://api-r.bitcoinchain.com/v1/block/#{hash}")
|
|
56
|
-
.to_return(
|
|
57
|
-
body: '[{"next_block": "nn", "prev_block": "pp", "hash": "hh"}]'
|
|
58
|
-
)
|
|
59
|
-
stub_request(:get, "https://api-r.bitcoinchain.com/v1/block/txs/#{hash}")
|
|
60
|
-
.to_return(
|
|
61
|
-
body: '[{"txs":[{"self_hash":"hash123",
|
|
62
|
-
"outputs":[{"value": 123, "receiver": "a1"}]}]}]'
|
|
63
|
-
)
|
|
64
|
-
sibit = Sibit::Bitcoinchain.new
|
|
65
|
-
json = sibit.block(hash)
|
|
66
|
-
assert_equal('nn', json[:next])
|
|
67
|
-
assert_equal('pp', json[:previous])
|
|
68
|
-
assert_equal('hh', json[:hash])
|
|
69
|
-
assert(json[:txns].is_a?(Array))
|
|
70
|
-
assert_equal('hash123', json[:txns][0][:hash])
|
|
71
|
-
assert(json[:txns][0][:outputs].is_a?(Array))
|
|
72
|
-
end
|
|
73
|
-
end
|
data/test/test_blockchain.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require 'json'
|
|
26
|
-
require_relative '../lib/sibit'
|
|
27
|
-
require_relative '../lib/sibit/blockchain'
|
|
28
|
-
|
|
29
|
-
# Sibit::Blockchain test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestBlockchain < Minitest::Test
|
|
34
|
-
def test_fetch_block
|
|
35
|
-
hash = '0000000000000000000f676241aabc9b62b748d26192a44bc25720c34de27d19'
|
|
36
|
-
stub_request(:get, "https://blockchain.info/rawblock/#{hash}")
|
|
37
|
-
.to_return(body: '{"next_block": ["n"], "prev_block": "p", "hash": "h",
|
|
38
|
-
"tx": [{"hash": "h1", "out": [{"hash": "oh", "value": 123}]}]}')
|
|
39
|
-
sibit = Sibit::Blockchain.new
|
|
40
|
-
json = sibit.block(hash)
|
|
41
|
-
assert(json[:next])
|
|
42
|
-
assert(json[:previous])
|
|
43
|
-
assert_equal('h', json[:hash])
|
|
44
|
-
assert(json[:txns].is_a?(Array))
|
|
45
|
-
assert_equal('h1', json[:txns][0][:hash])
|
|
46
|
-
assert(json[:txns][0][:outputs].is_a?(Array))
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_next_of
|
|
50
|
-
skip
|
|
51
|
-
hash = '0000000000000000000f676241aabc9b62b748d26192a44bc25720c34de27d19'
|
|
52
|
-
stub_request(:get, "https://blockchain.info/rawblock/#{hash}")
|
|
53
|
-
.to_return(body: '{"next_block": ["nxt"]}')
|
|
54
|
-
sibit = Sibit::Blockchain.new
|
|
55
|
-
nxt = sibit.next_of(hash)
|
|
56
|
-
assert_equal('nxt', nxt)
|
|
57
|
-
end
|
|
58
|
-
end
|
data/test/test_blockchair.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require 'json'
|
|
26
|
-
require_relative '../lib/sibit'
|
|
27
|
-
require_relative '../lib/sibit/blockchair'
|
|
28
|
-
|
|
29
|
-
# Sibit::Blockchair test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestBlockchair < Minitest::Test
|
|
34
|
-
def test_fetch_balance
|
|
35
|
-
hash = '1GkQmKAmHtNfnD3LHhTkewJxKHVSta4m2a'
|
|
36
|
-
stub_request(:get, "https://api.blockchair.com/bitcoin/dashboards/address/#{hash}")
|
|
37
|
-
.to_return(body: "{\"data\": {\"#{hash}\": {\"address\":
|
|
38
|
-
{\"balance\": 1, \"transactions\": []}}}}")
|
|
39
|
-
sibit = Sibit::Blockchair.new
|
|
40
|
-
satoshi = sibit.balance(hash)
|
|
41
|
-
assert_equal(1, satoshi)
|
|
42
|
-
end
|
|
43
|
-
end
|
data/test/test_btc.rb
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require 'json'
|
|
26
|
-
require_relative '../lib/sibit'
|
|
27
|
-
require_relative '../lib/sibit/btc'
|
|
28
|
-
|
|
29
|
-
# Sibit::Btc test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestBtc < Minitest::Test
|
|
34
|
-
def test_get_zero_balance
|
|
35
|
-
stub_request(
|
|
36
|
-
:get,
|
|
37
|
-
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
38
|
-
).to_return(body: '{"data":{"list":[]}}')
|
|
39
|
-
sibit = Sibit::Btc.new
|
|
40
|
-
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
41
|
-
assert(balance.is_a?(Integer))
|
|
42
|
-
assert_equal(0, balance)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_get_zero_balance_no_txns
|
|
46
|
-
stub_request(
|
|
47
|
-
:get,
|
|
48
|
-
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
49
|
-
).to_return(body: '{"data":{}}')
|
|
50
|
-
sibit = Sibit::Btc.new
|
|
51
|
-
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
52
|
-
assert(balance.is_a?(Integer))
|
|
53
|
-
assert_equal(0, balance)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_get_broken_balance
|
|
57
|
-
stub_request(
|
|
58
|
-
:get,
|
|
59
|
-
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
60
|
-
).to_return(body: '{}')
|
|
61
|
-
sibit = Sibit::Btc.new
|
|
62
|
-
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
63
|
-
assert(balance.is_a?(Integer))
|
|
64
|
-
assert_equal(0, balance)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def test_get_empty_balance
|
|
68
|
-
stub_request(
|
|
69
|
-
:get,
|
|
70
|
-
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
71
|
-
).to_return(body: '{"data":null,"err_no":1,"err_msg":"Resource Not Found"}')
|
|
72
|
-
sibit = Sibit::Btc.new
|
|
73
|
-
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
74
|
-
assert(balance.is_a?(Integer))
|
|
75
|
-
assert_equal(0, balance)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def test_get_balance
|
|
79
|
-
stub_request(
|
|
80
|
-
:get,
|
|
81
|
-
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
82
|
-
).to_return(body: '{"data":{"list":[{"value":123}]}}')
|
|
83
|
-
sibit = Sibit::Btc.new
|
|
84
|
-
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
85
|
-
assert(balance.is_a?(Integer))
|
|
86
|
-
assert_equal(123, balance)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def test_fetch_block_broken
|
|
90
|
-
hash = '000000000000000007341915521967247f1dec17b3a311b8a8f4495392f1439b'
|
|
91
|
-
stub_request(:get, "https://chain.api.btc.com/v3/block/#{hash}")
|
|
92
|
-
.to_return(body: '{"data": {"next_block_hash": "n", "hash": "h", "prev_block_hash": "p"}}')
|
|
93
|
-
stub_request(:get, "https://chain.api.btc.com/v3/block/#{hash}/tx?page=1&pagesize=50")
|
|
94
|
-
.to_return(body: '{}')
|
|
95
|
-
sibit = Sibit::Btc.new
|
|
96
|
-
assert_raises Sibit::Error do
|
|
97
|
-
sibit.block(hash)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_fetch_block
|
|
102
|
-
hash = '000000000000000007341915521967247f1dec17b3a311b8a8f4495392f1439b'
|
|
103
|
-
stub_request(:get, "https://chain.api.btc.com/v3/block/#{hash}")
|
|
104
|
-
.to_return(body: '{"data": {"next_block_hash": "n", "hash": "h", "prev_block_hash": "p"}}')
|
|
105
|
-
stub_request(:get, "https://chain.api.btc.com/v3/block/#{hash}/tx?page=1&pagesize=50")
|
|
106
|
-
.to_return(body: '{"data": {"list":[{"hash": "thash",
|
|
107
|
-
"outputs": [{"addresses": ["a1"], "value": 123}]}]}}')
|
|
108
|
-
sibit = Sibit::Btc.new
|
|
109
|
-
json = sibit.block(hash)
|
|
110
|
-
assert(json[:next])
|
|
111
|
-
assert(json[:previous])
|
|
112
|
-
assert_equal('h', json[:hash])
|
|
113
|
-
assert(json[:txns].is_a?(Array))
|
|
114
|
-
assert_equal('thash', json[:txns][0][:hash])
|
|
115
|
-
assert(json[:txns][0][:outputs].is_a?(Array))
|
|
116
|
-
end
|
|
117
|
-
end
|
data/test/test_cex.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require 'json'
|
|
26
|
-
require_relative '../lib/sibit'
|
|
27
|
-
require_relative '../lib/sibit/cex'
|
|
28
|
-
|
|
29
|
-
# Sibit::Cex test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestBtc < Minitest::Test
|
|
34
|
-
def test_get_price
|
|
35
|
-
stub_request(
|
|
36
|
-
:get,
|
|
37
|
-
'https://cex.io/api/last_price/BTC/USD'
|
|
38
|
-
).to_return(body: '{"lprice":123}')
|
|
39
|
-
sibit = Sibit::Cex.new
|
|
40
|
-
price = sibit.price
|
|
41
|
-
assert_equal(123.0, price)
|
|
42
|
-
end
|
|
43
|
-
end
|
data/test/test_cryptoapis.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2019-2023 Yegor Bugayenko
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
# copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
# SOFTWARE.
|
|
22
|
-
|
|
23
|
-
require 'minitest/autorun'
|
|
24
|
-
require 'webmock/minitest'
|
|
25
|
-
require 'json'
|
|
26
|
-
require_relative '../lib/sibit'
|
|
27
|
-
require_relative '../lib/sibit/cryptoapis'
|
|
28
|
-
|
|
29
|
-
# Sibit::Cryptoapis test.
|
|
30
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
32
|
-
# License:: MIT
|
|
33
|
-
class TestCryptoapis < Minitest::Test
|
|
34
|
-
def test_fetch_block
|
|
35
|
-
hash = '000000000000000007341915521967247f1dec17b3a311b8a8f4495392f1439b'
|
|
36
|
-
url = 'https://api.cryptoapis.io/v1/bc/btc/mainnet'
|
|
37
|
-
stub_request(:get, "#{url}/blocks/#{hash}")
|
|
38
|
-
.to_return(body: '{"payload": {"nextblockhash": "n", "hash": "h", "previousblockhash": "p"}}')
|
|
39
|
-
stub_request(:get, "#{url}/txs/block/#{hash}?index=0&limit=200")
|
|
40
|
-
.to_return(body: '{"payload": [{"hash": "thash",
|
|
41
|
-
"txouts": [{"addresses": ["a1"], "value": 123}]}]}')
|
|
42
|
-
sibit = Sibit::Cryptoapis.new('-')
|
|
43
|
-
json = sibit.block(hash)
|
|
44
|
-
assert(json[:next])
|
|
45
|
-
assert(json[:previous])
|
|
46
|
-
assert_equal('h', json[:hash])
|
|
47
|
-
assert(json[:txns].is_a?(Array))
|
|
48
|
-
assert_equal('thash', json[:txns][0][:hash])
|
|
49
|
-
assert(json[:txns][0][:outputs].is_a?(Array))
|
|
50
|
-
end
|
|
51
|
-
end
|