require 'spec_helper' RSpec.describe PortalConnectors::UsdtWalletClient do let(:client) { PortalConnectors::UsdtWalletClient.singleton } describe '#create_deposit_address' do it 'returns the usdt address', vcr: true do address, ok = client.create_deposit_address(ref: 'deposit_address_1') expect(ok).to be_truthy expect(address).to match({ "address" => "1GNfKnYQNdV9mGVbPMyyViL2PPUy66bNYX" }) end end describe '#fetch_deposit' do let(:tx_hash) { "d404af866333a705a8bc5f371dcde33ef7d26daba7ef4cf7882de41e84156959" } it 'returns the deposit data', :vcr do resp, ok = client.fetch_deposit(tx_hash: tx_hash) expect(ok).to be_truthy expect(resp['tx_hash']).to eq(tx_hash) expect(resp['amount']).to eq('10.0') expect(resp['address']).to eq('1Jw8bUhesNti1oU1pipVCo4rf3nS9iyVCv') end end describe '#fetch_stocks' do it 'returns the stocks data', :vcr do resp, ok = client.fetch_stocks expect(ok).to be_truthy expect(resp["buffer"].keys).to match_array(["btc", "usdt"]) end end describe '#fetch_balance' do it 'returns the usdt balance', :vcr do resp, ok = client.fetch_balance expect(ok).to be_truthy expect(resp).to eq(2) end end describe '#send_withdrawal' do context "request sucessfully" do it 'returns the payment', vcr: true do resp, ok = client.send_withdrawal(address: "1GNfKnYQNdV9mGVbPMyyViL2PPUy66bNYX", amount: 10, identifier: "testid") expect(ok).to be_truthy expect(resp).to match({ "tx_hash"=>nil, "address"=>"1GNfKnYQNdV9mGVbPMyyViL2PPUy66bNYX", "amount"=>"10.0", "signing_status"=>"signing", "identifier"=>"testid" }) end end end describe "#list_deposit_keys", vcr: true do it "return deposit keys" do from_time = Date.new(2018, 02, 03).to_datetime to_time = from_time - 1.day json, ok = client.list_deposit_keys(from_time.to_i, to_time.to_i) expect(ok).to be_truthy expect(json["success"]).to be_truthy expect(json["keys"]).to eq(["0e7b65dfe20d4018e86d765e1b27a1f572d96d0444fcdeebdb819d133ccf3fa1","4a7851d682571fd10b82bf3afc12d7caf1a3bb953479564e27ea2da504544ebf"]) end it "return error message" do from_time = Date.new(2018, 02, 03).to_datetime to_time = from_time - 10.days json, ok = client.list_deposit_keys(from_time.to_i, to_time.to_i) expect(ok).to be_truthy expect(json["success"]).to be_falsey expect(json["error"]).to eq("out of allowance range") end end describe "#list_withdraw_keys", vcr: true do it "return withdraw keys" do from_time = Date.new(2018, 02, 03).to_datetime to_time = from_time - 1.day json, ok = client.list_withdraw_keys(from_time.to_i, to_time.to_i) expect(ok).to be_truthy expect(json["success"]).to be_truthy expect(json["keys"]).to eq(["TA111E", "TA222E"]) end it "return error message" do from_time = Date.new(2018, 02, 03).to_datetime to_time = from_time - 10.days json, ok = client.list_withdraw_keys(from_time.to_i, to_time.to_i) expect(ok).to be_truthy expect(json["success"]).to be_falsey expect(json["error"]).to eq("out of allowance range") end end end