-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* accounts * addresses * buys
- Loading branch information
Lukas Matt
committed
Jan 31, 2017
1 parent
d2004a5
commit f3729a9
Showing
7 changed files
with
226 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package coinbase_test | ||
|
||
import ( | ||
"testing" | ||
"zauberstuhl/coinbase" | ||
) | ||
|
||
func TestAccounts(t *testing.T) { | ||
s := serverHelper(` | ||
{ | ||
"data": { | ||
"id": "2bbf394c-193b-5b2a-9155-3b4732659ede", | ||
"name": "My Wallet", | ||
"primary": true, | ||
"type": "wallet", | ||
"currency": "BTC", | ||
"balance": { | ||
"amount": "39.59000000", | ||
"currency": "BTC" | ||
}, | ||
"native_balance": { | ||
"amount": "395.90", | ||
"currency": "USD" | ||
}, | ||
"created_at": "2015-01-31T20:49:02Z", | ||
"updated_at": "2015-01-31T20:49:02Z", | ||
"resource": "account", | ||
"resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede" | ||
} | ||
} | ||
`) | ||
defer s.Close() | ||
|
||
a := coinbase.APIClient{ | ||
Key: "123", | ||
Secret: "123456", | ||
Endpoint: s.URL, | ||
} | ||
|
||
acc, err := a.Account("2bbf394c-193b-5b2a-9155-3b4732659ede") | ||
if err != nil { | ||
t.Error("Expected nil, got ", err.Error()) | ||
} | ||
if acc.Data.Id != "2bbf394c-193b-5b2a-9155-3b4732659ede" { | ||
t.Error("Expected 2bbf394c-193b-5b2a-9155-3b4732659ede, got ", acc.Data.Id) | ||
} | ||
if acc.Data.Balance.Amount != 39.59 { | ||
t.Error("Expected 39.59, got ", acc.Data.Balance.Amount) | ||
} | ||
if acc.Data.Native_balance.Amount != 395.90 { | ||
t.Error("Expected 395.90, got ", acc.Data.Native_balance.Amount) | ||
} | ||
if acc.Data.Created_at.Year() != 2015 { | ||
t.Error("Expected 2015, got ", acc.Data.Created_at.Year()) | ||
} | ||
if acc.Data.Updated_at.Year() != 2015 { | ||
t.Error("Expected 2015, got ", acc.Data.Created_at.Year()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package coinbase_test | ||
|
||
import ( | ||
"testing" | ||
"zauberstuhl/coinbase" | ||
) | ||
|
||
func TestAddresses(t *testing.T) { | ||
s := serverHelper(` | ||
{ | ||
"data": { | ||
"id": "dd3183eb-af1d-5f5d-a90d-cbff946435ff", | ||
"address": "mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa", | ||
"name": "One off payment", | ||
"created_at": "2015-01-31T20:49:02Z", | ||
"updated_at": "2015-03-31T17:25:29-07:00", | ||
"network": "bitcoin", | ||
"resource": "address", | ||
"resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/addresses/dd3183eb-af1d-5f5d-a90d-cbff946435ff" | ||
} | ||
} | ||
`) | ||
defer s.Close() | ||
|
||
a := coinbase.APIClient{ | ||
Key: "123", | ||
Secret: "123456", | ||
Endpoint: s.URL, | ||
} | ||
|
||
address, err := a.GetAddress( | ||
"dd3183eb-af1d-5f5d-a90d-cbff946435ff", | ||
"mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa", | ||
) | ||
if err != nil { | ||
t.Error("Expected nil, got ", err.Error()) | ||
} | ||
if address.Data.Id != "dd3183eb-af1d-5f5d-a90d-cbff946435ff" { | ||
t.Error("Expected dd3183eb-af1d-5f5d-a90d-cbff946435ff, got ", | ||
address.Data.Id) | ||
} | ||
if address.Data.Address != "mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa" { | ||
t.Error("Expected mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa, got ", | ||
address.Data.Address) | ||
} | ||
if address.Data.Created_at.Year() != 2015 { | ||
t.Error("Expected 2015, got ", address.Data.Created_at.Year()) | ||
} | ||
if address.Data.Updated_at.Year() != 2015 { | ||
t.Error("Expected 2015, got ", address.Data.Created_at.Year()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package coinbase_test | ||
|
||
import ( | ||
"testing" | ||
"zauberstuhl/coinbase" | ||
) | ||
|
||
func TestBuys(t *testing.T) { | ||
s := serverHelper(` | ||
{ | ||
"data": { | ||
"id": "9e14d574-30fa-5d85-b02c-6be0d851d61d", | ||
"status": "created", | ||
"payment_method": { | ||
"id": "83562370-3e5c-51db-87da-752af5ab9559", | ||
"resource": "payment_method", | ||
"resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559" | ||
}, | ||
"transaction": { | ||
"id": "4117f7d6-5694-5b36-bc8f-847509850ea4", | ||
"resource": "transaction", | ||
"resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/441b9494-b3f0-5b98-b9b0-4d82c21c252a" | ||
}, | ||
"amount": { | ||
"amount": "10.00000000", | ||
"currency": "BTC" | ||
}, | ||
"total": { | ||
"amount": "102.01", | ||
"currency": "USD" | ||
}, | ||
"subtotal": { | ||
"amount": "101.00", | ||
"currency": "USD" | ||
}, | ||
"created_at": "2015-03-26T23:43:59-07:00", | ||
"updated_at": "2015-03-26T23:44:09-07:00", | ||
"resource": "buy", | ||
"resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/buys/9e14d574-30fa-5d85-b02c-6be0d851d61d", | ||
"committed": true, | ||
"instant": false, | ||
"fee": { | ||
"amount": "1.01", | ||
"currency": "USD" | ||
}, | ||
"payout_at": "2015-04-01T23:43:59-07:00" | ||
} | ||
} | ||
`) | ||
defer s.Close() | ||
|
||
a := coinbase.APIClient{ | ||
Key: "123", | ||
Secret: "123456", | ||
Endpoint: s.URL, | ||
} | ||
|
||
buys, err := a.ShowBuy("123", "456") | ||
if err != nil { | ||
t.Error("Expected nil, got ", err.Error()) | ||
} | ||
if buys.Data.Id != "9e14d574-30fa-5d85-b02c-6be0d851d61d" { | ||
t.Error("Expected 9e14d574-30fa-5d85-b02c-6be0d851d61d, got ", | ||
buys.Data.Id) | ||
} | ||
|
||
wrapper := func(data interface{}) { | ||
switch r := data.(type) { | ||
case coinbase.APIResource: | ||
case coinbase.APIBalance: | ||
default: | ||
t.Error("Expected APIBalance or APIResource, got ", r) | ||
} | ||
} | ||
wrapper(buys.Data.Payment_method) | ||
wrapper(buys.Data.Transaction) | ||
wrapper(buys.Data.Amount) | ||
wrapper(buys.Data.Total) | ||
wrapper(buys.Data.Subtotal) | ||
|
||
if buys.Data.Created_at.Year() != 2015 { | ||
t.Error("Expected 2015, got ", buys.Data.Created_at.Year()) | ||
} | ||
if buys.Data.Updated_at.Year() != 2015 { | ||
t.Error("Expected 2015, got ", buys.Data.Created_at.Year()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package coinbase_test | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"fmt" | ||
) | ||
|
||
func serverHelper(body string) *httptest.Server { | ||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
fmt.Fprintln(w, body) | ||
})) | ||
} |