sibit 0.25.0 → 0.26.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 +82 -60
- data/REUSE.toml +35 -0
- data/Rakefile +3 -29
- data/bin/sibit +7 -23
- 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/earn.rb +5 -21
- 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 -33
- metadata +27 -49
- 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/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/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
|
data/test/test_fake.rb
DELETED
|
@@ -1,55 +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/fake'
|
|
27
|
-
|
|
28
|
-
# Sibit::Fake test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestFake < Minitest::Test
|
|
33
|
-
def test_fake_object_works
|
|
34
|
-
sibit = Sibit::Fake.new
|
|
35
|
-
assert_equal(4_000, sibit.price)
|
|
36
|
-
assert_equal(12, sibit.fees[:S])
|
|
37
|
-
assert_equal(100_000_000, sibit.balance(''))
|
|
38
|
-
assert_equal([], sibit.utxos(nil))
|
|
39
|
-
assert_equal('00000000000000000008df8a6e1b61d1136803ac9791b8725235c9f780b4ed71', sibit.latest)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_scan_works
|
|
43
|
-
sibit = Sibit.new(api: Sibit::Fake.new)
|
|
44
|
-
hash = '00000000000000000008df8a6e1b61d1136803ac9791b8725235c9f780b4ed71'
|
|
45
|
-
found = false
|
|
46
|
-
tail = sibit.scan(hash) do |addr, tx, satoshi|
|
|
47
|
-
assert_equal(1000, satoshi)
|
|
48
|
-
assert_equal('1HqhZx8U18TYS5paraTM1MzUQWb7ZbcG9u', addr)
|
|
49
|
-
assert_equal("#{hash}:0", tx)
|
|
50
|
-
found = true
|
|
51
|
-
end
|
|
52
|
-
assert(found)
|
|
53
|
-
assert_equal(hash, tail)
|
|
54
|
-
end
|
|
55
|
-
end
|
data/test/test_firstof.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/firstof'
|
|
27
|
-
|
|
28
|
-
# Sibit::FirstOf test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestFirstOf < Minitest::Test
|
|
33
|
-
def test_not_array
|
|
34
|
-
sibit = Sibit::FirstOf.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::FirstOf.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::FirstOf.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::FirstOf.new([api, api])
|
|
58
|
-
assert_raises Sibit::Error do
|
|
59
|
-
sibit.latest
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
data/test/test_json.rb
DELETED
|
@@ -1,40 +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 'uri'
|
|
26
|
-
require_relative '../lib/sibit/json'
|
|
27
|
-
|
|
28
|
-
# Sibit::Json test.
|
|
29
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
|
-
# Copyright:: Copyright (c) 2019-2023 Yegor Bugayenko
|
|
31
|
-
# License:: MIT
|
|
32
|
-
class TestJson < Minitest::Test
|
|
33
|
-
def test_loads_hash
|
|
34
|
-
stub_request(:get, 'https://hello.com').to_return(body: '{"test":123}')
|
|
35
|
-
json = Sibit::Json.new.get(URI('https://hello.com'))
|
|
36
|
-
assert_equal(123, json['test'])
|
|
37
|
-
json = Sibit::Json.new.get(URI('https://hello.com/'))
|
|
38
|
-
assert_equal(123, json['test'])
|
|
39
|
-
end
|
|
40
|
-
end
|