block_io 2.0.0 → 3.0.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/{.appveyor.yml → .appveyor.yml-disabled} +2 -2
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/LICENSE +1 -1
- data/README.md +14 -13
- data/block_io.gemspec +6 -6
- data/examples/basic.rb +29 -5
- data/examples/dtrust.rb +43 -24
- data/examples/sweeper.rb +21 -16
- data/lib/block_io.rb +3 -2
- data/lib/block_io/api_exception.rb +11 -0
- data/lib/block_io/chainparams/BTC.yml +8 -0
- data/lib/block_io/chainparams/BTCTEST.yml +8 -0
- data/lib/block_io/chainparams/DOGE.yml +8 -0
- data/lib/block_io/chainparams/DOGETEST.yml +8 -0
- data/lib/block_io/chainparams/LTC.yml +8 -0
- data/lib/block_io/chainparams/LTCTEST.yml +8 -0
- data/lib/block_io/client.rb +143 -79
- data/lib/block_io/extended_bitcoinrb.rb +127 -0
- data/lib/block_io/helper.rb +137 -39
- data/lib/block_io/key.rb +11 -124
- data/lib/block_io/version.rb +1 -1
- data/spec/client_misc_spec.rb +76 -0
- data/spec/client_spec.rb +23 -178
- data/spec/dtrust_spec.rb +167 -0
- data/spec/helper_spec.rb +1 -1
- data/spec/key_spec.rb +50 -19
- data/spec/larger_transaction_spec.rb +351 -0
- data/spec/sweep_spec.rb +115 -0
- data/spec/test-cases/.gitignore +2 -0
- data/spec/test-cases/LICENSE +21 -0
- data/spec/test-cases/README.md +2 -0
- data/spec/test-cases/json/create_and_sign_transaction_response.json +61 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_251inputs.json +1261 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_252inputs.json +1266 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_253inputs.json +1271 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_762inputs.json +3816 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2SH_3of5_195inputs.json +2931 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2SH_4of5_195inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_3of5_251inputs.json +3771 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_3of5_252inputs.json +3786 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_3of5_253inputs.json +3801 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_4of5_251inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_4of5_252inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_4of5_253inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_3of5_251inputs.json +3771 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_3of5_252inputs.json +3786 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_3of5_253inputs.json +3801 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_4of5_251inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_4of5_252inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_4of5_253inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys.json +21 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys.json +21 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys.json +36 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3of5_251outputs.json +591 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3of5_252outputs.json +576 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3of5_253outputs.json +531 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4of5_251outputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4of5_252outputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4of5_253outputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_sweep_p2pkh.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_sweep_p2wpkh.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_sweep_p2wpkh_over_p2sh.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json +21 -0
- data/spec/test-cases/json/get_balance_response.json +8 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2SH_3of5_195inputs.json +1397 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2SH_4of5_195inputs.json +1397 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_3of5_251inputs.json +1795 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_3of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_3of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_4of5_251inputs.json +1789 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_4of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_4of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_3of5_251inputs.json +1795 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_3of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_3of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_4of5_251inputs.json +1795 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_4of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_4of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_p2sh.json +45 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_p2wsh_over_p2sh.json +45 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0.json +52 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_3of5_251outputs.json +1805 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_3of5_252outputs.json +1804 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_3of5_253outputs.json +1789 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_4of5_251outputs.json +1805 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_4of5_252outputs.json +1804 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_4of5_253outputs.json +1789 -0
- data/spec/test-cases/json/prepare_sweep_transaction_response_p2pkh.json +35 -0
- data/spec/test-cases/json/prepare_sweep_transaction_response_p2wpkh.json +35 -0
- data/spec/test-cases/json/prepare_sweep_transaction_response_p2wpkh_over_p2sh.json +35 -0
- data/spec/test-cases/json/prepare_transaction_response.json +164 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_251inputs.json +1796 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_252inputs.json +1803 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_253inputs.json +1810 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_762inputs.json +5367 -0
- data/spec/test-cases/json/prepare_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json +76 -0
- data/spec/test-cases/json/summarize_prepared_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json +6 -0
- metadata +187 -45
- data/examples/max_withdrawal.rb +0 -29
- data/lib/block_io/constants.rb +0 -10
- data/spec/data/sign_and_finalize_dtrust_withdrawal_request.json +0 -1
- data/spec/data/sign_and_finalize_sweep_request.json +0 -1
- data/spec/data/sign_and_finalize_withdrawal_request.json +0 -4
- data/spec/data/sweep_from_address_response.json +0 -1
- data/spec/data/withdraw_from_dtrust_address_response.json +0 -1
- data/spec/data/withdraw_response.json +0 -1227
- data/spec/rfc6979_spec.rb +0 -59
- data/spec/withdraw_spec.rb +0 -90
data/lib/block_io/version.rb
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'securerandom'
|
|
2
|
+
|
|
3
|
+
describe "Client" do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@api_key = "0000-0000-0000-0000"
|
|
7
|
+
@req_params = {:to_address => "QTLcyTFrH7T6kqUsi1VV2mJVXmX3AmwUNH", :amounts => "0.248"}
|
|
8
|
+
@headers = {
|
|
9
|
+
'Accept' => 'application/json',
|
|
10
|
+
'Connection' => 'Keep-Alive',
|
|
11
|
+
'Content-Type' => 'application/json; charset=UTF-8',
|
|
12
|
+
'Host' => 'block.io',
|
|
13
|
+
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@prepare_transaction_response = File.new("spec/test-cases/json/prepare_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json").read
|
|
17
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_transaction").
|
|
18
|
+
with(
|
|
19
|
+
body: @req_params.merge({:api_key => @api_key}).to_json,
|
|
20
|
+
headers: @headers).
|
|
21
|
+
to_return(status: 200, body: @prepare_transaction_response, headers: {})
|
|
22
|
+
|
|
23
|
+
@create_and_sign_transaction_response = File.new("spec/test-cases/json/create_and_sign_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json").read
|
|
24
|
+
@summarize_prepared_transaction_response = File.new("spec/test-cases/json/summarize_prepared_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json").read
|
|
25
|
+
|
|
26
|
+
@insecure_pin_valid = "d1650160bd8d2bb32bebd139d0063eb6063ffa2f9e4501ad" # still insecure, don't use this!
|
|
27
|
+
@insecure_pin_invalid = "blockiotestpininsecure"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "summarize_prepare_transaction" do
|
|
31
|
+
|
|
32
|
+
before(:each) do
|
|
33
|
+
|
|
34
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => @insecure_pin_valid)
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "success" do
|
|
39
|
+
|
|
40
|
+
@blockio.prepare_transaction(@req_params)
|
|
41
|
+
|
|
42
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
43
|
+
|
|
44
|
+
expect(@blockio.summarize_prepared_transaction(Oj.safe_load(@prepare_transaction_response))).to eq(Oj.safe_load(@summarize_prepared_transaction_response))
|
|
45
|
+
|
|
46
|
+
expect(@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_transaction_response))).to eq(Oj.safe_load(@create_and_sign_transaction_response))
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "create_and_sign_transaction_with_invalid_expected_unsigned_txid" do
|
|
53
|
+
|
|
54
|
+
before(:each) do
|
|
55
|
+
|
|
56
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => @insecure_pin_valid)
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "fails" do
|
|
61
|
+
|
|
62
|
+
@blockio.prepare_transaction(@req_params)
|
|
63
|
+
|
|
64
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
65
|
+
|
|
66
|
+
@bad_response = Oj.safe_load(@prepare_transaction_response)
|
|
67
|
+
@bad_response['data']['expected_unsigned_txid'] = SecureRandom.hex(32)
|
|
68
|
+
|
|
69
|
+
expect{@blockio.create_and_sign_transaction(@bad_response)}.to raise_error(Exception, "Expected unsigned transaction ID mismatch. Please report this error to support@block.io.")
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
data/spec/client_spec.rb
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Client.withdraw" do
|
|
1
|
+
describe "Client.prepare_transaction" do
|
|
3
2
|
|
|
4
3
|
before(:each) do
|
|
5
|
-
|
|
6
4
|
@api_key = "0000-0000-0000-0000"
|
|
7
|
-
@req_params = {:
|
|
5
|
+
@req_params = {:to_address => "QTLcyTFrH7T6kqUsi1VV2mJVXmX3AmwUNH", :amounts => "0.248"}
|
|
8
6
|
@headers = {
|
|
9
7
|
'Accept' => 'application/json',
|
|
10
8
|
'Connection' => 'Keep-Alive',
|
|
@@ -13,211 +11,58 @@ describe "Client.withdraw" do
|
|
|
13
11
|
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
@
|
|
17
|
-
@stub1 = stub_request(:post, "https://block.io/api/v2/
|
|
14
|
+
@prepare_transaction_response = File.new("spec/test-cases/json/prepare_transaction_response.json").read
|
|
15
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_transaction").
|
|
18
16
|
with(
|
|
19
17
|
body: @req_params.merge({:api_key => @api_key}).to_json,
|
|
20
|
-
headers: @headers
|
|
21
|
-
)
|
|
22
|
-
to_return(status: 200, body: @withdraw_response, headers: {})
|
|
23
|
-
|
|
24
|
-
@sign_and_finalize_withdrawal_request = Oj.dump(Oj.load_file("spec/data/sign_and_finalize_withdrawal_request.json"))
|
|
25
|
-
@success_response = Oj.dump({"status" => "success", "data" => {"network" => "random", "txid" => "random"}})
|
|
26
|
-
@stub2 = stub_request(:post, "https://block.io/api/v2/sign_and_finalize_withdrawal").
|
|
27
|
-
with(
|
|
28
|
-
body: @sign_and_finalize_withdrawal_request,
|
|
29
|
-
headers: @headers
|
|
30
|
-
).to_return(status: 200, body: @success_response, headers: {})
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context "pin" do
|
|
18
|
+
headers: @headers).
|
|
19
|
+
to_return(status: 200, body: @prepare_transaction_response, headers: {})
|
|
35
20
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => "blockiotestpininsecure", :version => 2, :use_low_r => false)
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "success" do
|
|
43
|
-
|
|
44
|
-
@blockio.withdraw(@req_params)
|
|
45
|
-
|
|
46
|
-
expect(@stub1).to have_been_requested.times(1)
|
|
47
|
-
expect(@stub2).to have_been_requested.times(1)
|
|
48
|
-
|
|
49
|
-
end
|
|
21
|
+
@create_and_sign_transaction_response = File.new("spec/test-cases/json/create_and_sign_transaction_response.json").read
|
|
50
22
|
|
|
23
|
+
@insecure_pin_valid = "d1650160bd8d2bb32bebd139d0063eb6063ffa2f9e4501ad" # still insecure, don't use this!
|
|
24
|
+
@insecure_pin_invalid = "blockiotestpininsecure"
|
|
51
25
|
end
|
|
52
|
-
|
|
53
|
-
context "key" do
|
|
54
|
-
|
|
55
|
-
before(:each) do
|
|
56
26
|
|
|
57
|
-
|
|
58
|
-
@key = BlockIo::Helper.extractKey(Oj.load(@withdraw_response)["data"]["encrypted_passphrase"]["passphrase"], @encryption_key, false)
|
|
27
|
+
context "pin_valid" do
|
|
59
28
|
|
|
60
|
-
|
|
29
|
+
before(:each) do
|
|
61
30
|
|
|
31
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => @insecure_pin_valid)
|
|
32
|
+
|
|
62
33
|
end
|
|
63
34
|
|
|
64
35
|
it "success" do
|
|
65
36
|
|
|
66
|
-
@blockio.
|
|
37
|
+
@blockio.prepare_transaction(@req_params)
|
|
67
38
|
|
|
68
39
|
expect(@stub1).to have_been_requested.times(1)
|
|
69
|
-
expect(@stub2).to have_been_requested.times(1)
|
|
70
|
-
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
end
|
|
76
40
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
before(:each) do
|
|
80
|
-
|
|
81
|
-
@api_key = "0000-0000-0000-0000"
|
|
82
|
-
@wif = "cTYLVcC17cYYoRjaBu15rEcD5WuDyowAw562q2F1ihcaomRJENu5"
|
|
83
|
-
@key = BlockIo::Key.from_wif(@wif)
|
|
84
|
-
@req_params = {:to_address => "QhSWVppS12Fqv6dh3rAyoB18jXh5mB1hoC", :from_address => "tltc1qpygwklc39wl9p0wvlm0p6x42sh9259xdjl059s", :public_key => @key.public_key}
|
|
85
|
-
@headers = {
|
|
86
|
-
'Accept' => 'application/json',
|
|
87
|
-
'Connection' => 'Keep-Alive',
|
|
88
|
-
'Content-Type' => 'application/json; charset=UTF-8',
|
|
89
|
-
'Host' => 'block.io',
|
|
90
|
-
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
|
91
|
-
}
|
|
41
|
+
expect(@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_transaction_response))).to eq(Oj.safe_load(@create_and_sign_transaction_response))
|
|
92
42
|
|
|
93
|
-
|
|
94
|
-
@stub1 = stub_request(:post, "https://block.io/api/v2/sweep_from_address").
|
|
95
|
-
with(
|
|
96
|
-
body: @req_params.merge({:api_key => @api_key}).to_json,
|
|
97
|
-
headers: @headers
|
|
98
|
-
).
|
|
99
|
-
to_return(status: 200, body: @sweep_from_address_response, headers:{})
|
|
100
|
-
|
|
101
|
-
@sign_and_finalize_sweep_request = Oj.dump(Oj.load_file("spec/data/sign_and_finalize_sweep_request.json"))
|
|
102
|
-
@success_response = Oj.dump({"status" => "success", "data" => {"network" => "random", "txid" => "random"}})
|
|
103
|
-
@stub2 = stub_request(:post, "https://block.io/api/v2/sign_and_finalize_sweep").
|
|
104
|
-
with(
|
|
105
|
-
body: @sign_and_finalize_sweep_request,
|
|
106
|
-
headers: @headers
|
|
107
|
-
).to_return(status: 200, body: @success_response, headers: {})
|
|
43
|
+
end
|
|
108
44
|
|
|
109
45
|
end
|
|
110
46
|
|
|
111
|
-
context "
|
|
47
|
+
context "pin_invalid" do
|
|
112
48
|
|
|
113
49
|
before(:each) do
|
|
114
50
|
|
|
115
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :
|
|
116
|
-
|
|
51
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => @insecure_pin_invalid)
|
|
52
|
+
|
|
117
53
|
end
|
|
118
54
|
|
|
119
|
-
it "
|
|
55
|
+
it "fails" do
|
|
120
56
|
|
|
121
|
-
@blockio.
|
|
57
|
+
@blockio.prepare_transaction(@req_params)
|
|
122
58
|
|
|
123
59
|
expect(@stub1).to have_been_requested.times(1)
|
|
124
|
-
expect(@stub2).to have_been_requested.times(1)
|
|
125
|
-
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
end
|
|
131
60
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
before(:each) do
|
|
135
|
-
|
|
136
|
-
@api_key = "0000-0000-0000-0000"
|
|
137
|
-
@req_params = {:from_address => "tltc1q8y9naxlsw7xay4jesqshnpeuc0ap8fg9ejm2j2memwq4ng87dk3s88nr5j", :to_addresses => "QhSWVppS12Fqv6dh3rAyoB18jXh5mB1hoC", :amounts => "0.09"}
|
|
138
|
-
@headers = {
|
|
139
|
-
'Accept' => 'application/json',
|
|
140
|
-
'Connection' => 'Keep-Alive',
|
|
141
|
-
'Content-Type' => 'application/json; charset=UTF-8',
|
|
142
|
-
'Host' => 'block.io',
|
|
143
|
-
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
@keys = [
|
|
147
|
-
BlockIo::Key.new("b515fd806a662e061b488e78e5d0c2ff46df80083a79818e166300666385c0a2", false), # alpha1alpha2alpha3alpha4
|
|
148
|
-
BlockIo::Key.new("1584b821c62ecdc554e185222591720d6fe651ed1b820d83f92cdc45c5e21f", false), # alpha2alpha3alpha4alpha1
|
|
149
|
-
BlockIo::Key.new("2f9090b8aa4ddb32c3b0b8371db1b50e19084c720c30db1d6bb9fcd3a0f78e61", false), # alpha3alpha4alpha1alpha2
|
|
150
|
-
BlockIo::Key.new("6c1cefdfd9187b36b36c3698c1362642083dcc1941dc76d751481d3aa29ca65", false) # alpha4alpha1alpha2alpha3
|
|
151
|
-
].freeze
|
|
152
|
-
|
|
153
|
-
@withdraw_from_dtrust_address_response = File.new("spec/data/withdraw_from_dtrust_address_response.json", "r").read
|
|
154
|
-
@stub1 = stub_request(:post, "https://block.io/api/v2/withdraw_from_dtrust_address").
|
|
155
|
-
with(
|
|
156
|
-
body: @req_params.merge({:api_key => @api_key}).to_json,
|
|
157
|
-
headers: @headers
|
|
158
|
-
).
|
|
159
|
-
to_return(status: 200, body: @withdraw_from_dtrust_address_response, headers: {})
|
|
160
|
-
|
|
161
|
-
@sign_and_finalize_dtrust_withdrawal_request = Oj.dump(Oj.load_file("spec/data/sign_and_finalize_dtrust_withdrawal_request.json"))
|
|
162
|
-
@success_response = Oj.dump({"status" => "success", "data" => {"network" => "random", "txid" => "random"}})
|
|
163
|
-
@stub2 = stub_request(:post, "https://block.io/api/v2/sign_and_finalize_withdrawal").
|
|
164
|
-
with(
|
|
165
|
-
body: @sign_and_finalize_dtrust_withdrawal_request,
|
|
166
|
-
headers: @headers
|
|
167
|
-
).to_return(status: 200, body: @success_response, headers: {})
|
|
168
|
-
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
context "without_keys_at_init" do
|
|
172
|
-
|
|
173
|
-
before(:each) do
|
|
174
|
-
|
|
175
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :version => 2, :use_low_r => false)
|
|
176
|
-
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it "only_required_signatures" do
|
|
180
|
-
|
|
181
|
-
@response = @blockio.withdraw_from_dtrust_address(@req_params)
|
|
182
|
-
|
|
183
|
-
BlockIo::Helper.signData(@response["data"]["inputs"], @keys)
|
|
184
|
-
only_required_signatures = @response["data"]["inputs"].map{|input| input["signers"].map{|s| (s["signed_data"].nil? ? 0 : 1)}.inject(:+) == input["signatures_needed"]}.all?{|x| x}
|
|
185
|
-
|
|
186
|
-
expect(@stub1).to have_been_requested.times(1)
|
|
187
|
-
expect(only_required_signatures).to eq(true)
|
|
61
|
+
expect { @blockio.create_and_sign_transaction(Oj.safe_load(@prepare_transaction_response)) }.to raise_error(Exception, "Invalid Secret PIN provided.")
|
|
188
62
|
|
|
189
63
|
end
|
|
190
64
|
|
|
191
|
-
it "success" do
|
|
192
|
-
|
|
193
|
-
@response = @blockio.withdraw_from_dtrust_address(@req_params)
|
|
194
|
-
|
|
195
|
-
BlockIo::Helper.signData(@response["data"]["inputs"], @keys)
|
|
196
|
-
|
|
197
|
-
@blockio.sign_and_finalize_withdrawal({:signature_data => @response["data"]})
|
|
198
|
-
|
|
199
|
-
expect(@stub1).to have_been_requested.times(1)
|
|
200
|
-
expect(@stub2).to have_been_requested.times(1)
|
|
201
|
-
|
|
202
|
-
end
|
|
203
|
-
|
|
204
65
|
end
|
|
205
66
|
|
|
206
|
-
context "with_keys_at_init" do
|
|
207
|
-
|
|
208
|
-
before(:each) do
|
|
209
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :keys => @keys, :version => 2, :use_low_r => false)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it "success" do
|
|
213
|
-
|
|
214
|
-
@blockio.withdraw_from_dtrust_address(@req_params)
|
|
215
|
-
|
|
216
|
-
expect(@stub1).to have_been_requested.times(1)
|
|
217
|
-
expect(@stub2).to have_been_requested.times(1)
|
|
218
|
-
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
end
|
|
222
|
-
|
|
223
67
|
end
|
|
68
|
+
|
data/spec/dtrust_spec.rb
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
describe "Client.prepare_dtrust_transaction" do
|
|
2
|
+
|
|
3
|
+
before(:each) do
|
|
4
|
+
@api_key = "0000-0000-0000-0000"
|
|
5
|
+
@private_keys = ["b515fd806a662e061b488e78e5d0c2ff46df80083a79818e166300666385c0a2",
|
|
6
|
+
"1584b821c62ecdc554e185222591720d6fe651ed1b820d83f92cdc45c5e21f",
|
|
7
|
+
"2f9090b8aa4ddb32c3b0b8371db1b50e19084c720c30db1d6bb9fcd3a0f78e61",
|
|
8
|
+
"6c1cefdfd9187b36b36c3698c1362642083dcc1941dc76d751481d3aa29ca65"]
|
|
9
|
+
@to_address = "QcnYiN3t3foHxHv7CnqXrmRoiMkADhapZw"
|
|
10
|
+
@amount = "0.00020000"
|
|
11
|
+
@headers = {
|
|
12
|
+
'Accept' => 'application/json',
|
|
13
|
+
'Connection' => 'Keep-Alive',
|
|
14
|
+
'Content-Type' => 'application/json; charset=UTF-8',
|
|
15
|
+
'Host' => 'block.io',
|
|
16
|
+
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "p2sh" do
|
|
22
|
+
|
|
23
|
+
before(:each) do
|
|
24
|
+
|
|
25
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key)
|
|
26
|
+
@from_address = "QZVSzPeaEJxB9bYuDEL7iWrHSdGbAP3pXV"
|
|
27
|
+
@prepare_dtrust_transaction_response_p2sh = File.new("spec/test-cases/json/prepare_dtrust_transaction_response_p2sh.json").read
|
|
28
|
+
@req_params = {:from_address => @from_address, :amount => @amount, :to_address => @to_address}
|
|
29
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_dtrust_transaction").
|
|
30
|
+
with(
|
|
31
|
+
body: @req_params.merge({:api_key => @api_key}).to_json,
|
|
32
|
+
headers: @headers).
|
|
33
|
+
to_return(status: 200, body: @prepare_dtrust_transaction_response_p2sh, headers: {})
|
|
34
|
+
|
|
35
|
+
@create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys.json").read
|
|
36
|
+
@create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys.json").read
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "3_of_5_keys" do
|
|
41
|
+
it "success" do
|
|
42
|
+
|
|
43
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
|
44
|
+
|
|
45
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
46
|
+
|
|
47
|
+
expect(
|
|
48
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2sh), @private_keys.first(3))
|
|
49
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys))
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "4_of_5_keys" do
|
|
55
|
+
it "success" do
|
|
56
|
+
|
|
57
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
|
58
|
+
|
|
59
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
60
|
+
|
|
61
|
+
expect(@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2sh), @private_keys)).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys))
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "p2wsh_over_p2sh" do
|
|
69
|
+
|
|
70
|
+
before(:each) do
|
|
71
|
+
|
|
72
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key)
|
|
73
|
+
@from_address = "Qg1QzgjUDkwaHeT7Yznuyu2V1keJieDVAF"
|
|
74
|
+
@prepare_dtrust_transaction_response_p2wsh_over_p2sh = File.new("spec/test-cases/json/prepare_dtrust_transaction_response_p2wsh_over_p2sh.json").read
|
|
75
|
+
@req_params = {:from_address => @from_address, :amount => @amount, :to_address => @to_address}
|
|
76
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_dtrust_transaction").
|
|
77
|
+
with(
|
|
78
|
+
body: @req_params.merge({:api_key => @api_key}).to_json,
|
|
79
|
+
headers: @headers).
|
|
80
|
+
to_return(status: 200, body: @prepare_dtrust_transaction_response_p2wsh_over_p2sh, headers: {})
|
|
81
|
+
|
|
82
|
+
@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys.json").read
|
|
83
|
+
@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys.json").read
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "3_of_5_keys" do
|
|
88
|
+
it "success" do
|
|
89
|
+
|
|
90
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
|
91
|
+
|
|
92
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
93
|
+
|
|
94
|
+
expect(
|
|
95
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2wsh_over_p2sh), @private_keys.first(3))
|
|
96
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys))
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
context "4_of_5_keys" do
|
|
102
|
+
it "success" do
|
|
103
|
+
|
|
104
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
|
105
|
+
|
|
106
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
107
|
+
|
|
108
|
+
expect(
|
|
109
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2wsh_over_p2sh), @private_keys)
|
|
110
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys))
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context "witness_v0" do
|
|
118
|
+
|
|
119
|
+
before(:each) do
|
|
120
|
+
|
|
121
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key)
|
|
122
|
+
@from_address = "tltc1qtvscupcwnlsykujp98y0jhf8s4x48mzrr3v8v822ytg6vmprvzaqj8jd0h"
|
|
123
|
+
@prepare_dtrust_transaction_response_witness_v0 = File.new("spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0.json").read
|
|
124
|
+
@req_params = {:from_address => @from_address, :amount => @amount, :to_address => @to_address}
|
|
125
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_dtrust_transaction").
|
|
126
|
+
with(
|
|
127
|
+
body: @req_params.merge({:api_key => @api_key}).to_json,
|
|
128
|
+
headers: @headers).
|
|
129
|
+
to_return(status: 200, body: @prepare_dtrust_transaction_response_witness_v0, headers: {})
|
|
130
|
+
|
|
131
|
+
@create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys.json").read
|
|
132
|
+
@create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys.json").read
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
context "3_of_5_keys" do
|
|
137
|
+
it "success" do
|
|
138
|
+
|
|
139
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
|
140
|
+
|
|
141
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
142
|
+
|
|
143
|
+
expect(
|
|
144
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_witness_v0), @private_keys.first(3))
|
|
145
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys))
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
context "4_of_5_keys" do
|
|
151
|
+
it "success" do
|
|
152
|
+
|
|
153
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
|
154
|
+
|
|
155
|
+
expect(@stub1).to have_been_requested.times(1)
|
|
156
|
+
|
|
157
|
+
expect(
|
|
158
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_witness_v0), @private_keys)
|
|
159
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys))
|
|
160
|
+
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
|