Files
gocryptotrader/exchanges/account/account_test.go
Ryan O'Hara-Reid a32d16e1f5 Expose auth validator functionality for wrapper (#416)
* expose auth validator functionality for wrapper

* Add REST validation after keys set, package account types for future syncing

* Add transient error checking for initial creddemtial validation

* fix command types

* Addressed nits from glorious person

* Amalgamate body within error when not between 2xx status, added btcmarket specific auth error check

* nit fix for glorious person

* Format fix

* removed unused code

* check transient first then validate if its an exchange specific authentication error, all others will be disregarded

* Addressed glorious nits

* Addressed glorious nits

* Moved account processing to updateaccountinfo func and added in fetch account info

* Add GRPC Account streaming (NOTE: could not complete until sync item added)

* RM exchange check

* Address xtda nits

* RM comment code

* Fix linter issues

* used most recent protoc version

* lbank linter issues fixed

* Addressed nits and changed len check to range in for loops

* Fixed timeout issue

* thrasher nits addressed

* add string holdings
2020-01-31 12:09:24 +11:00

130 lines
2.2 KiB
Go

package account
import (
"sync"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/dispatch"
)
func TestHoldings(t *testing.T) {
err := dispatch.Start(1, 1)
if err != nil {
t.Fatal(err)
}
err = Process(nil)
if err == nil {
t.Error("error cannot be nil")
}
err = Process(&Holdings{})
if err == nil {
t.Error("error cannot be nil")
}
holdings := Holdings{
Exchange: "Test",
}
err = Process(&holdings)
if err != nil {
t.Error(err)
}
err = Process(&Holdings{
Exchange: "Test",
Accounts: []SubAccount{{
ID: "1337",
Currencies: []Balance{
{
CurrencyName: currency.BTC,
TotalValue: 100,
Hold: 20,
},
},
}},
})
if err != nil {
t.Error(err)
}
_, err = GetHoldings("")
if err == nil {
t.Error("error cannot be nil")
}
_, err = GetHoldings("bla")
if err == nil {
t.Error("error cannot be nil")
}
u, err := GetHoldings("Test")
if err != nil {
t.Error(err)
}
if u.Accounts[0].ID != "1337" {
t.Errorf("expecting 1337 but receieved %s", u.Accounts[0].ID)
}
if u.Accounts[0].Currencies[0].CurrencyName != currency.BTC {
t.Errorf("expecting BTC but receieved %s",
u.Accounts[0].Currencies[0].CurrencyName)
}
if u.Accounts[0].Currencies[0].TotalValue != 100 {
t.Errorf("expecting 100 but receieved %f",
u.Accounts[0].Currencies[0].TotalValue)
}
if u.Accounts[0].Currencies[0].Hold != 20 {
t.Errorf("expecting 20 but receieved %f",
u.Accounts[0].Currencies[0].Hold)
}
_, err = SubscribeToExchangeAccount("nonsense")
if err == nil {
t.Fatal("error cannot be nil")
}
p, err := SubscribeToExchangeAccount("Test")
if err != nil {
t.Fatal(err)
}
var wg sync.WaitGroup
wg.Add(1)
go func(p dispatch.Pipe, wg *sync.WaitGroup) {
for i := 0; i < 2; i++ {
c := time.NewTimer(time.Second)
select {
case <-p.C:
case <-c.C:
}
}
wg.Done()
}(p, &wg)
err = Process(&Holdings{
Exchange: "Test",
Accounts: []SubAccount{{
ID: "1337",
Currencies: []Balance{
{
CurrencyName: currency.BTC,
TotalValue: 100000,
Hold: 20,
},
},
}},
})
if err != nil {
t.Error(err)
}
wg.Wait()
}