github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/wallet_test.go (about)

     1  package bitfinex
     2  
     3  import (
     4  	"bytes"
     5  	"io/ioutil"
     6  	"net/http"
     7  	"testing"
     8  )
     9  
    10  func TestWalletTransfer(t *testing.T) {
    11  	httpDo = func(req *http.Request) (*http.Response, error) {
    12  		msg := `[{
    13            "status":"success",
    14            "message":"1.0 USD transfered from Exchange to Deposit"
    15          }]`
    16  		resp := http.Response{
    17  			Body:       ioutil.NopCloser(bytes.NewBufferString(msg)),
    18  			StatusCode: 200,
    19  		}
    20  		return &resp, nil
    21  	}
    22  
    23  	response, err := NewClient().Wallet.Transfer(10.0, "BTC", "1WalletA", "1WalletB")
    24  
    25  	if err != nil {
    26  		t.Error(err)
    27  	}
    28  
    29  	if response[0].Status != "success" {
    30  		t.Error("Expected", "success")
    31  		t.Error("Actual ", response[0].Status)
    32  	}
    33  }
    34  
    35  func TestWithdrawCrypto(t *testing.T) {
    36  	httpDo = func(req *http.Request) (*http.Response, error) {
    37  		msg := `[{
    38            "status":"success",
    39            "message":"Your withdrawal request has been successfully submitted.",
    40            "withdrawal_id":586829
    41          }]`
    42  		resp := http.Response{
    43  			Body:       ioutil.NopCloser(bytes.NewBufferString(msg)),
    44  			StatusCode: 200,
    45  		}
    46  		return &resp, nil
    47  	}
    48  
    49  	response, err := NewClient().Wallet.WithdrawCrypto(10.0, "bitcoin", WALLET_DEPOSIT, "1WalletABC")
    50  
    51  	if err != nil {
    52  		t.Error(err)
    53  	}
    54  
    55  	if response[0].Status != "success" {
    56  		t.Error("Expected", "success")
    57  		t.Error("Actual ", response[0].Status)
    58  	}
    59  	if response[0].WithdrawalID != 586829 {
    60  		t.Error("Expected", 586829)
    61  		t.Error("Actual ", response[0].WithdrawalID)
    62  	}
    63  
    64  }
    65  
    66  func TestWithdrawWire(t *testing.T) {
    67  	httpDo = func(req *http.Request) (*http.Response, error) {
    68  		msg := `[{
    69            "status":"success",
    70            "message":"Your withdrawal request has been successfully submitted.",
    71            "withdrawal_id":586829
    72          }]`
    73  		resp := http.Response{
    74  			Body:       ioutil.NopCloser(bytes.NewBufferString(msg)),
    75  			StatusCode: 200,
    76  		}
    77  		return &resp, nil
    78  	}
    79  
    80  	intermediaryBank := BankAccount{
    81  		AccountName:   "Bank Account Name",
    82  		AccountNumber: "IBAN12355678976543",
    83  		BankName:      "HongKong Bank",
    84  		BankAddress:   "Bank Address",
    85  		BankCity:      "Bank City",
    86  		BankCountry:   "Bank Country",
    87  		SwiftCode:     "SWIFT",
    88  	}
    89  	beneficiaryBank := BankAccount{
    90  		AccountName:   "Bank Account Name",
    91  		AccountNumber: "IBAN12355678976543",
    92  		BankName:      "HongKong Bank",
    93  		BankAddress:   "Bank Address",
    94  		BankCity:      "Bank City",
    95  		BankCountry:   "Bank Country",
    96  		SwiftCode:     "SWIFT",
    97  	}
    98  	response, err := NewClient().Wallet.WithdrawWire(10.0, true, WALLET_DEPOSIT, beneficiaryBank, intermediaryBank, "Wire MESSAGE")
    99  
   100  	if err != nil {
   101  		t.Error(err)
   102  	}
   103  
   104  	if response[0].Status != "success" {
   105  		t.Error("Expected", "success")
   106  		t.Error("Actual ", response[0].Status)
   107  	}
   108  	if response[0].WithdrawalID != 586829 {
   109  		t.Error("Expected", 586829)
   110  		t.Error("Actual ", response[0].WithdrawalID)
   111  	}
   112  
   113  }