Restructured test files and added alphapoint test

This commit is contained in:
Ryan O'Hara-Reid
2017-04-08 15:40:47 +10:00
committed by Adrian Gallagher
parent a4dc2cdaae
commit 8a96f20858
13 changed files with 597 additions and 469 deletions

View File

@@ -18,6 +18,7 @@ import (
const (
CONFIG_FILE = "config.dat"
OLD_CONFIG_FILE = "config.json"
CONFIG_TEST = "../testdata/configtest.dat"
CONFIG_FILE_ENCRYPTION_PROMPT = 0
CONFIG_FILE_ENCRYPTION_ENABLED = 1
@@ -265,7 +266,7 @@ func (c *Config) RetrieveConfigCurrencyPairs() error {
return nil
}
func (c *Config) ReadConfig() error {
func CheckConfig() error {
_, err := common.ReadFile(OLD_CONFIG_FILE)
if err == nil {
err = os.Rename(OLD_CONFIG_FILE, CONFIG_FILE)
@@ -274,8 +275,23 @@ func (c *Config) ReadConfig() error {
}
log.Printf(RenamingConfigFile+"\n", OLD_CONFIG_FILE, CONFIG_FILE)
}
return nil
}
file, err := common.ReadFile(CONFIG_FILE)
func (c *Config) ReadConfig(configPath string) error {
defaultPath := ""
if configPath == "" {
defaultPath = CONFIG_FILE
} else {
defaultPath = configPath
}
err := CheckConfig()
if err != nil {
return err
}
file, err := common.ReadFile(defaultPath)
if err != nil {
return err
}
@@ -293,7 +309,7 @@ func (c *Config) ReadConfig() error {
if c.EncryptConfig == CONFIG_FILE_ENCRYPTION_PROMPT {
if c.PromptForConfigEncryption() {
c.EncryptConfig = CONFIG_FILE_ENCRYPTION_ENABLED
return c.SaveConfig()
return c.SaveConfig("")
}
}
} else {
@@ -315,7 +331,14 @@ func (c *Config) ReadConfig() error {
return nil
}
func (c *Config) SaveConfig() error {
func (c *Config) SaveConfig(configPath string) error {
defaultPath := ""
if configPath == "" {
defaultPath = CONFIG_FILE
} else {
defaultPath = configPath
}
payload, err := json.MarshalIndent(c, "", " ")
if c.EncryptConfig == CONFIG_FILE_ENCRYPTION_ENABLED {
@@ -330,15 +353,15 @@ func (c *Config) SaveConfig() error {
}
}
err = common.WriteFile(CONFIG_FILE, payload)
err = common.WriteFile(defaultPath, payload)
if err != nil {
return err
}
return nil
}
func (c *Config) LoadConfig() error {
err := c.ReadConfig()
func (c *Config) LoadConfig(configPath string) error {
err := c.ReadConfig(configPath)
if err != nil {
return fmt.Errorf(ErrFailureOpeningConfig, CONFIG_FILE, err)
}

View File

@@ -31,7 +31,7 @@ func (c *Config) PromptForConfigEncryption() bool {
if !common.YesOrNo(input) {
c.EncryptConfig = CONFIG_FILE_ENCRYPTION_DISABLED
c.SaveConfig()
c.SaveConfig("")
return false
}
return true

View File

@@ -1,4 +1,4 @@
package test
package config
import (
"encoding/json"
@@ -6,15 +6,12 @@ import (
"testing"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
)
func TestPromptForConfigEncryption(t *testing.T) {
t.Parallel()
promptForConfigEncryption := config.GetConfig()
if promptForConfigEncryption.PromptForConfigEncryption() {
if Cfg.PromptForConfigEncryption() {
t.Error("Test failed. PromptForConfigEncryption return incorrect bool")
}
}
@@ -22,21 +19,19 @@ func TestPromptForConfigEncryption(t *testing.T) {
func TestPromptForConfigKey(t *testing.T) {
t.Parallel()
byteyBite, err := config.PromptForConfigKey()
byteyBite, err := PromptForConfigKey()
if err == nil && len(byteyBite) > 1 {
t.Errorf("Test failed. PromptForConfigKey: %s", err)
}
}
func TestEncryptDecryptConfigFile(t *testing.T) { //Dual function Test
t.Parallel()
testKey := []byte("12345678901234567890123456789012")
testConfigData, err := common.ReadFile("config.dat")
testConfigData, err := common.ReadFile("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. EncryptConfigFile: %s", err)
}
encryptedFile, err2 := config.EncryptConfigFile(testConfigData, testKey)
encryptedFile, err2 := EncryptConfigFile(testConfigData, testKey)
if err2 != nil {
t.Errorf("Test failed. EncryptConfigFile: %s", err2)
}
@@ -44,14 +39,14 @@ func TestEncryptDecryptConfigFile(t *testing.T) { //Dual function Test
t.Errorf("Test failed. EncryptConfigFile: Incorrect Type")
}
decryptedFile, err3 := config.DecryptConfigFile(encryptedFile, testKey)
decryptedFile, err3 := DecryptConfigFile(encryptedFile, testKey)
if err3 != nil {
t.Errorf("Test failed. DecryptConfigFile: %s", err3)
}
if reflect.TypeOf(decryptedFile).String() != "[]uint8" {
t.Errorf("Test failed. DecryptConfigFile: Incorrect Type")
}
unmarshalled := config.Config{}
unmarshalled := Config{}
err4 := json.Unmarshal(decryptedFile, &unmarshalled)
if err4 != nil {
t.Errorf("Test failed. DecryptConfigFile: %s", err3)
@@ -59,14 +54,12 @@ func TestEncryptDecryptConfigFile(t *testing.T) { //Dual function Test
}
func TestConfirmJson(t *testing.T) {
t.Parallel()
var result interface{}
testConfirmJson, err := common.ReadFile("config.dat")
testConfirmJson, err := common.ReadFile("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. TestConfirmJson: %s", err)
}
err2 := config.ConfirmConfigJSON(testConfirmJson, &result)
err2 := ConfirmConfigJSON(testConfirmJson, &result)
if err2 != nil {
t.Errorf("Test failed. TestConfirmJson: %s", err2)
}
@@ -79,7 +72,7 @@ func TestConfirmECS(t *testing.T) {
t.Parallel()
ECStest := []byte("THORS-HAMMER")
if !config.ConfirmECS(ECStest) {
if !ConfirmECS(ECStest) {
t.Errorf("Test failed. TestConfirmECS: Error finding ECS.")
}
}
@@ -88,7 +81,7 @@ func TestRemoveECS(t *testing.T) {
t.Parallel()
ECStest := []byte("THORS-HAMMER")
isremoved := config.RemoveECS(ECStest)
isremoved := RemoveECS(ECStest)
if string(isremoved) != "" {
t.Errorf("Test failed. TestConfirmECS: Error ECS not deleted.")

View File

@@ -1,17 +1,15 @@
package test
package config
import (
"testing"
"github.com/thrasher-/gocryptotrader/config"
)
func TestGetConfigEnabledExchanges(t *testing.T) {
t.Parallel()
defaultEnabledExchanges := 17
GetConfigEnabledExchanges := config.GetConfig()
err := GetConfigEnabledExchanges.LoadConfig()
GetConfigEnabledExchanges := GetConfig()
err := GetConfigEnabledExchanges.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Error("Test failed. GetConfigEnabledExchanges load config error: " + err.Error())
}
@@ -24,13 +22,13 @@ func TestGetConfigEnabledExchanges(t *testing.T) {
func TestGetExchangeConfig(t *testing.T) {
t.Parallel()
GetExchangeConfig := config.GetConfig()
err := GetExchangeConfig.LoadConfig()
GetExchangeConfig := GetConfig()
err := GetExchangeConfig.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. GetExchangeConfig.LoadConfig Error: %s", err.Error())
}
r, err := GetExchangeConfig.GetExchangeConfig("ANX")
if err != nil && (config.ExchangeConfig{}) == r {
if err != nil && (ExchangeConfig{}) == r {
t.Errorf("Test failed. GetExchangeConfig.GetExchangeConfig Error: %s", err.Error())
}
}
@@ -38,8 +36,8 @@ func TestGetExchangeConfig(t *testing.T) {
func TestUpdateExchangeConfig(t *testing.T) {
t.Parallel()
UpdateExchangeConfig := config.GetConfig()
err := UpdateExchangeConfig.LoadConfig()
UpdateExchangeConfig := GetConfig()
err := UpdateExchangeConfig.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. UpdateExchangeConfig.LoadConfig Error: %s", err.Error())
}
@@ -57,8 +55,8 @@ func TestUpdateExchangeConfig(t *testing.T) {
func TestCheckSMSGlobalConfigValues(t *testing.T) {
t.Parallel()
checkSMSGlobalConfigValues := config.GetConfig()
err := checkSMSGlobalConfigValues.LoadConfig()
checkSMSGlobalConfigValues := GetConfig()
err := checkSMSGlobalConfigValues.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. checkSMSGlobalConfigValues.LoadConfig: %s", err)
}
@@ -71,8 +69,8 @@ func TestCheckSMSGlobalConfigValues(t *testing.T) {
func TestCheckExchangeConfigValues(t *testing.T) {
t.Parallel()
checkExchangeConfigValues := config.Config{}
err := checkExchangeConfigValues.LoadConfig()
checkExchangeConfigValues := Config{}
err := checkExchangeConfigValues.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. checkExchangeConfigValues.LoadConfig: %s", err.Error())
}
@@ -86,8 +84,8 @@ func TestCheckExchangeConfigValues(t *testing.T) {
func TestCheckWebserverConfigValues(t *testing.T) {
t.Parallel()
checkWebserverConfigValues := config.GetConfig()
err := checkWebserverConfigValues.LoadConfig()
checkWebserverConfigValues := GetConfig()
err := checkWebserverConfigValues.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. checkWebserverConfigValues.LoadConfig: %s", err.Error())
}
@@ -100,8 +98,8 @@ func TestCheckWebserverConfigValues(t *testing.T) {
func TestRetrieveConfigCurrencyPairs(t *testing.T) {
t.Parallel()
retrieveConfigCurrencyPairs := config.GetConfig()
err := retrieveConfigCurrencyPairs.LoadConfig()
retrieveConfigCurrencyPairs := GetConfig()
err := retrieveConfigCurrencyPairs.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. checkWebserverConfigValues.LoadConfig: %s", err.Error())
}
@@ -114,8 +112,8 @@ func TestRetrieveConfigCurrencyPairs(t *testing.T) {
func TestReadConfig(t *testing.T) {
t.Parallel()
readConfig := config.GetConfig()
err := readConfig.ReadConfig()
readConfig := GetConfig()
err := readConfig.ReadConfig("../testdata/configtest.dat")
if err != nil {
t.Error("Test failed. TestReadConfig " + err.Error())
}
@@ -124,22 +122,20 @@ func TestReadConfig(t *testing.T) {
func TestLoadConfig(t *testing.T) {
t.Parallel()
loadConfig := config.GetConfig()
err := loadConfig.LoadConfig()
loadConfig := GetConfig()
err := loadConfig.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Error("Test failed. TestLoadConfig " + err.Error())
}
}
func TestSaveConfig(t *testing.T) {
t.Parallel()
saveConfig := config.GetConfig()
err := saveConfig.LoadConfig()
saveConfig := GetConfig()
err := saveConfig.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test failed. TestSaveConfig.LoadConfig: %s", err.Error())
}
err2 := saveConfig.SaveConfig()
err2 := saveConfig.SaveConfig("../testdata/configtest.dat")
if err2 != nil {
t.Error("Test failed. TestSaveConfig.SaveConfig, %s", err2.Error())
}

View File

@@ -1,287 +0,0 @@
{
"Name": "Skynet",
"EncryptConfig": 0,
"Cryptocurrencies": "BTC,LTC,ETH,XRP,NMC,NVC,PPC,XBT,DOGE,DASH",
"PortfolioAddresses": {
"Addresses": [
{
"Address": "1JCe8z4jJVNXSjohjM4i9Hh813dLCNx2Sy",
"CoinType": "BTC",
"Balance": 124178.0002442
},
{
"Address": "3Nxwenay9Z8Lc9JBiywExpnEFiLp6Afp8v",
"CoinType": "BTC",
"Balance": 103439.83659727
},
{
"Address": "LgY8ahfHRhvjVQC1zJnBhFMG5pCTMuKRqh",
"CoinType": "LTC",
"Balance": 3.00000005e+06
},
{
"Address": "0xb794f5ea0ba39494ce839613fffba74279579268",
"CoinType": "ETH",
"Balance": 5.774999820458524e+06
}
]
},
"SMSGlobal": {
"Enabled": false,
"Username": "Username",
"Password": "Password",
"Contacts": [
{
"Name": "Bob",
"Number": "12345",
"Enabled": false
}
]
},
"Webserver": {
"Enabled": false,
"AdminUsername": "admin",
"AdminPassword": "Password",
"ListenAddress": ":9050"
},
"Exchanges": [
{
"Name": "ANX",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC",
"EnabledPairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC",
"BaseCurrencies": "USD,HKD,EUR,CAD,AUD,SGD,JPY,GBP,NZD"
},
{
"Name": "Bitfinex",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC,ETCBTC,ETCUSD,BFXUSD,BFXBTC,RRTUSD,RRTBTC,ZECUSD,ZECBTC,XMRUSD,XMRBTC,DSHUSD,DSHBTC",
"EnabledPairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC",
"BaseCurrencies": "USD"
},
{
"Name": "Bitstamp",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "ClientID",
"AvailablePairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR",
"EnabledPairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR",
"BaseCurrencies": "USD,EUR"
},
{
"Name": "BTCC",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCCNY,LTCCNY,LTCBTC",
"EnabledPairs": "BTCCNY,LTCCNY,LTCBTC",
"BaseCurrencies": "CNY"
},
{
"Name": "BTCE",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD",
"EnabledPairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD",
"BaseCurrencies": "USD,RUR,EUR"
},
{
"Name": "BTC Markets",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "LTC,BTC",
"EnabledPairs": "LTC,BTC",
"BaseCurrencies": "AUD"
},
{
"Name": "GDAX",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "ClientID",
"AvailablePairs": "BTCGBP,BTCEUR,ETHUSD,ETHBTC,LTCUSD,LTCBTC,BTCUSD",
"EnabledPairs": "BTCUSD,BTCGBP,BTCEUR",
"BaseCurrencies": "USD,GBP,EUR"
},
{
"Name": "Gemini",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,ETHBTC,ETHUSD",
"EnabledPairs": "BTCUSD",
"BaseCurrencies": "USD"
},
{
"Name": "Huobi",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCCNY,LTCCNY",
"EnabledPairs": "BTCCNY,LTCCNY",
"BaseCurrencies": "CNY"
},
{
"Name": "ITBIT",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "ClientID",
"AvailablePairs": "XBTUSD,XBTSGD,XBTEUR",
"EnabledPairs": "XBTUSD,XBTSGD,XBTEUR",
"BaseCurrencies": "USD,SGD,EUR"
},
{
"Name": "Kraken",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "ETCUSD,ICNETH,REPXBT,ZECXBT,ETHXBT,ETHXBT.d,ETHGBP,LTCXBT,XBTGBP.d,XDGXBT,XMRUSD,ZECUSD,ETCETH,ETHJPY,XBTCAD.d,XBTJPY.d,XBTUSD.d,XLMXBT,XLMEUR,XLMUSD,XMREUR,ETCXBT,ETHCAD.d,ETHEUR.d,ETHJPY.d,XBTEUR.d,ETHEUR,ETHGBP.d,ICNXBT,LTCEUR,REPEUR,XBTGBP,XBTJPY,ETHUSD,ETHUSD.d,LTCUSD,REPETH,XBTUSD,XMRXBT,ETCEUR,ETHCAD,REPUSD,XBTCAD,XBTEUR,XRPXBT,ZECEUR",
"EnabledPairs": "ETCUSD,XBTUSD,ETHUSD",
"BaseCurrencies": "EUR,USD,CAD,GBP,JPY"
},
{
"Name": "LakeBTC",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,BTCEUR,USDHKD,AUDUSD,BTCGBP,BTCNZD,USDJPY,BTCSGD,BTCNGN,EURUSD,USDSGD,NZDUSD,USDNGN,USDCHF,BTCJPY,BTCAUD,BTCCAD,BTCCHF,GBPUSD,USDCAD",
"EnabledPairs": "BTCUSD,BTCAUD",
"BaseCurrencies": "USD,EUR,HKD,AUD,GBP,NZD,JPY,SGD,NGN,CHF,CAD"
},
{
"Name": "Liqui",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "TIME_BTC,ETH_BTC,GNT_BTC,WAVES_BTC,ICN_BTC,1ST_BTC,WINGS_BTC,MLN_BTC,ROUND_BTC,VSL_BTC,LTC_BTC,DCT_BTC,INCNT_BTC,PLU_BTC,DASH_BTC",
"EnabledPairs": "ETH_BTC,LTC_BTC,DASH_BTC",
"BaseCurrencies": "USD"
},
{
"Name": "LocalBitcoins",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR",
"EnabledPairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR",
"BaseCurrencies": "ARS,AUD,BRL,CAD,CHF,CZK,DKK,EUR,GBP,HKD,ILS,INR,MXN,NOK,NZD,PLN,RUB,SEK,SGD,THB,USD,ZAR"
},
{
"Name": "OKCOIN China",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCCNY,LTCCNY",
"EnabledPairs": "BTCCNY,LTCCNY",
"BaseCurrencies": "CNY"
},
{
"Name": "OKCOIN International",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,LTCUSD",
"EnabledPairs": "BTCUSD,LTCUSD",
"BaseCurrencies": "USD"
},
{
"Name": "Poloniex",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTC_XUSD,BTC_FCT,BTC_MMNXT,BTC_NMC,BTC_BITUSD,BTC_RDD,BTC_XMR,BTC_XST,BTC_DSH,BTC_MAID,BTC_DGB,BTC_NEOS,BTC_BLK,BTC_NAUT,BTC_NBT,BTC_XCP,BTC_STR,BTC_BTCD,BTC_GRC,BTC_HUC,BTC_BBR,BTC_XDN,BTC_INDEX,BTC_IOC,BTC_SWARM,BTC_EMC2,BTC_MCN,BTC_NOXT,BTC_MINT,BTC_PTS,BTC_SC,BTC_GEO,BTC_XRP,BTC_FLO,BTC_BITS,BTC_HYP,BTC_XCR,BTC_LTBC,BTC_SYS,BTC_GMC,BTC_ETH,BTC_SYNC,BTC_GAP,BTC_BCN,BTC_C2,BTC_PINK,BTC_FIBRE,BTC_POT,BTC_QTL,BTC_SDC,BTC_XC,BTC_DASH,BTC_SILK,BTC_CLAM,BTC_NAV,BTC_PIGGY,BTC_BCY,BTC_MIL,BTC_XCN,BTC_YACC,BTC_BTS,BTC_QBK,BTC_SJCX,BTC_LQD,BTC_BURST,BTC_RIC,BTC_VRC,BTC_LTC,BTC_XPB,BTC_GRS,BTC_XCH,BTC_ARCH,BTC_QORA,BTC_HZ,BTC_NSR,BTC_XPM,BTC_BITCNY,BTC_EXE,BTC_XMG,BTC_BTC,BTC_BTM,BTC_NOBL,BTC_NXT,BTC_DOGE,BTC_CURE,BTC_MNTA,BTC_ADN,BTC_EXP,BTC_VTC,BTC_FLDC,BTC_MRS,BTC_MYR,BTC_OMNI,BTC_VNL,BTC_USDT,BTC_NOTE,BTC_WDC,BTC_BELA,BTC_VIA,BTC_CGA,BTC_DIEM,BTC_IFC,BTC_XDP,BTC_BLOCK,BTC_MMC,BTC_1CR,BTC_UNITY,BTC_XBC,BTC_GEMZ,BTC_FLT,BTC_PPC,BTC_XEM,BTC_RBY,BTC_CNMT,BTC_ABY,XMR_XDN,XMR_IFC,XMR_DIEM,XMR_BBR,XMR_DSH,XMR_BCN,XMR_LTC,XMR_MAID,XMR_DASH,XMR_BTCD,XMR_HYP,XMR_BLK,XMR_QORA,XMR_MNTA,XMR_NXT,USDT_BTC,USDT_ETH,USDT_XRP,USDT_DASH,USDT_LTC,USDT_NXT,USDT_XMR,USDT_STR",
"EnabledPairs": "BTC_LTC,BTC_ETH,BTC_DOGE,BTC_DASH,BTC_XRP",
"BaseCurrencies": "USD"
}
]
}

View File

@@ -1,11 +1,10 @@
package tests
package currency
import (
"reflect"
"testing"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
)
func TestIsDefaultCurrency(t *testing.T) {
@@ -13,13 +12,13 @@ func TestIsDefaultCurrency(t *testing.T) {
var str1, str2, str3 string = "USD", "usd", "cats123"
if !currency.IsDefaultCurrency(str1) {
if !IsDefaultCurrency(str1) {
t.Errorf("Test Failed. TestIsDefaultCurrency: \nCannot match currency, %s.", str1)
}
if !currency.IsDefaultCurrency(str2) {
if !IsDefaultCurrency(str2) {
t.Errorf("Test Failed. TestIsDefaultCurrency: \nCannot match currency, %s.", str2)
}
if currency.IsDefaultCurrency(str3) {
if IsDefaultCurrency(str3) {
t.Errorf("Test Failed. TestIsDefaultCurrency: \nFunction return is incorrect with, %s.", str3)
}
}
@@ -29,13 +28,13 @@ func TestIsDefaultCryptocurrency(t *testing.T) {
var str1, str2, str3 string = "BTC", "btc", "dogs123"
if !currency.IsDefaultCryptocurrency(str1) {
if !IsDefaultCryptocurrency(str1) {
t.Errorf("Test Failed. TestIsDefaultCryptocurrency: \nCannot match currency, %s.", str1)
}
if !currency.IsDefaultCryptocurrency(str2) {
if !IsDefaultCryptocurrency(str2) {
t.Errorf("Test Failed. TestIsDefaultCryptocurrency: \nCannot match currency, %s.", str2)
}
if currency.IsDefaultCryptocurrency(str3) {
if IsDefaultCryptocurrency(str3) {
t.Errorf("Test Failed. TestIsDefaultCryptocurrency: \nFunction return is incorrect with, %s.", str3)
}
}
@@ -43,17 +42,16 @@ func TestIsDefaultCryptocurrency(t *testing.T) {
func TestIsFiatCurrency(t *testing.T) {
t.Parallel()
currency.BaseCurrencies = "USD,AUD"
BaseCurrencies = "USD,AUD"
var str1, str2, str3 string = "BTC", "USD", "birds123"
if currency.IsFiatCurrency(str1) {
if IsFiatCurrency(str1) {
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str1)
}
if !currency.IsFiatCurrency(str2) {
if !IsFiatCurrency(str2) {
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str2)
}
if currency.IsFiatCurrency(str3) {
if IsFiatCurrency(str3) {
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str3)
}
}
@@ -61,16 +59,16 @@ func TestIsFiatCurrency(t *testing.T) {
func TestIsCryptocurrency(t *testing.T) {
t.Parallel()
currency.CryptoCurrencies = "BTC,LTC,DASH"
CryptoCurrencies = "BTC,LTC,DASH"
var str1, str2, str3 string = "USD", "BTC", "pterodactyl123"
if currency.IsCryptocurrency(str1) {
if IsCryptocurrency(str1) {
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str1)
}
if !currency.IsCryptocurrency(str2) {
if !IsCryptocurrency(str2) {
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str2)
}
if currency.IsCryptocurrency(str3) {
if IsCryptocurrency(str3) {
t.Errorf("Test Failed. TestIsFiatCurrency: \nCannot match currency, %s.", str3)
}
}
@@ -80,19 +78,19 @@ func TestContainsSeparator(t *testing.T) {
var str1, str2, str3, str4 string = "ding-dong", "ding_dong", "dong_ding-dang", "ding"
doesIt, whatIsIt := currency.ContainsSeparator(str1)
doesIt, whatIsIt := ContainsSeparator(str1)
if doesIt != true || whatIsIt != "-" {
t.Errorf("Test Failed. ContainsSeparator: \nCannot find separator, %s.", str1)
}
doesIt2, whatIsIt2 := currency.ContainsSeparator(str2)
doesIt2, whatIsIt2 := ContainsSeparator(str2)
if doesIt2 != true || whatIsIt2 != "_" {
t.Errorf("Test Failed. ContainsSeparator: \nCannot find separator, %s.", str2)
}
doesIt3, whatIsIt3 := currency.ContainsSeparator(str3)
doesIt3, whatIsIt3 := ContainsSeparator(str3)
if doesIt3 != true || len(whatIsIt3) != 3 {
t.Errorf("Test Failed. ContainsSeparator: \nCannot find or incorrect separator, %s.", str3)
}
doesIt4, whatIsIt4 := currency.ContainsSeparator(str4)
doesIt4, whatIsIt4 := ContainsSeparator(str4)
if doesIt4 != false || whatIsIt4 != "" {
t.Errorf("Test Failed. ContainsSeparator: \nReturn Issues with string, %s.", str3)
}
@@ -104,11 +102,11 @@ func TestContainsBaseCurrencyIndex(t *testing.T) {
baseCurrencies := []string{"USD", "AUD", "EUR", "CNY"}
currency1, currency2 := "USD", "DINGDONG"
isIt, whatIsIt := currency.ContainsBaseCurrencyIndex(baseCurrencies, currency1)
isIt, whatIsIt := ContainsBaseCurrencyIndex(baseCurrencies, currency1)
if !isIt && whatIsIt != "USD" {
t.Errorf("Test Failed. ContainsBaseCurrencyIndex: \nReturned: %t & %s, with Currency as %s.", isIt, whatIsIt, currency1)
}
isIt2, whatIsIt2 := currency.ContainsBaseCurrencyIndex(baseCurrencies, currency2)
isIt2, whatIsIt2 := ContainsBaseCurrencyIndex(baseCurrencies, currency2)
if isIt2 && whatIsIt2 != "DINGDONG" {
t.Errorf("Test Failed. ContainsBaseCurrencyIndex: \nReturned: %t & %s, with Currency as %s.", isIt2, whatIsIt2, currency2)
}
@@ -120,11 +118,11 @@ func TestContainsBaseCurrency(t *testing.T) {
baseCurrencies := []string{"USD", "AUD", "EUR", "CNY"}
currency1, currency2 := "USD", "DINGDONG"
isIt := currency.ContainsBaseCurrency(baseCurrencies, currency1)
isIt := ContainsBaseCurrency(baseCurrencies, currency1)
if !isIt {
t.Errorf("Test Failed. ContainsBaseCurrency: \nReturned: %t, with Currency as %s.", isIt, currency1)
}
isIt2 := currency.ContainsBaseCurrency(baseCurrencies, currency2)
isIt2 := ContainsBaseCurrency(baseCurrencies, currency2)
if isIt2 {
t.Errorf("Test Failed. ContainsBaseCurrency: \nReturned: %t, with Currency as %s.", isIt2, currency2)
}
@@ -141,37 +139,37 @@ func TestCheckAndAddCurrency(t *testing.T) {
cryptoIncrease := "XMR"
obtuse := "CATSANDDOGS"
appendedString := currency.CheckAndAddCurrency(inputFiat, fiat)
appendedString := CheckAndAddCurrency(inputFiat, fiat)
if len(appendedString) > len(inputFiat) {
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", fiat)
}
appendedString = currency.CheckAndAddCurrency(inputFiat, fiatIncrease)
appendedString = CheckAndAddCurrency(inputFiat, fiatIncrease)
if len(appendedString) <= len(inputFiat) {
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", fiatIncrease)
}
appendedString = currency.CheckAndAddCurrency(inputFiat, crypto)
appendedString = CheckAndAddCurrency(inputFiat, crypto)
if len(appendedString) > len(inputFiat) {
t.Log(appendedString)
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", crypto)
}
appendedString = currency.CheckAndAddCurrency(inputFiat, obtuse)
appendedString = CheckAndAddCurrency(inputFiat, obtuse)
if len(appendedString) > len(inputFiat) {
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputFiat, currency as %s.", obtuse)
}
appendedString = currency.CheckAndAddCurrency(inputCrypto, crypto)
appendedString = CheckAndAddCurrency(inputCrypto, crypto)
if len(appendedString) > len(inputCrypto) {
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", crypto)
}
appendedString = currency.CheckAndAddCurrency(inputCrypto, cryptoIncrease)
appendedString = CheckAndAddCurrency(inputCrypto, cryptoIncrease)
if len(appendedString) <= len(inputCrypto) {
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", cryptoIncrease)
}
appendedString = currency.CheckAndAddCurrency(inputCrypto, fiat)
appendedString = CheckAndAddCurrency(inputCrypto, fiat)
if len(appendedString) > len(inputCrypto) {
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", fiat)
}
appendedString = currency.CheckAndAddCurrency(inputCrypto, obtuse)
appendedString = CheckAndAddCurrency(inputCrypto, obtuse)
if len(appendedString) > len(inputCrypto) {
t.Errorf("Test Failed. CheckAndAddCurrency: Error with inputCrytpo, currency as %s.", obtuse)
}
@@ -184,15 +182,15 @@ func TestSeedCurrencyData(t *testing.T) {
currencyRequestUSDAUD := "USD,AUD"
currencyRequestObtuse := "WigWham"
err := currency.SeedCurrencyData(currencyRequestDefault)
err := SeedCurrencyData(currencyRequestDefault)
if err != nil {
t.Errorf("Test Failed. SeedCurrencyData: Error %s with currency as %s.", err, currencyRequestDefault)
}
err2 := currency.SeedCurrencyData(currencyRequestUSDAUD)
err2 := SeedCurrencyData(currencyRequestUSDAUD)
if err2 != nil {
t.Errorf("Test Failed. SeedCurrencyData: Error %s with currency as %s.", err2, currencyRequestUSDAUD)
}
err3 := currency.SeedCurrencyData(currencyRequestObtuse)
err3 := SeedCurrencyData(currencyRequestObtuse)
if err3 == nil {
t.Errorf("Test Failed. SeedCurrencyData: Error %s with currency as %s.", err3, currencyRequestObtuse)
}
@@ -201,8 +199,8 @@ func TestSeedCurrencyData(t *testing.T) {
func TestMakecurrencyPairs(t *testing.T) {
t.Parallel()
lengthDefault := len(common.SplitStrings(currency.DEFAULT_CURRENCIES, ","))
fiatPairsLength := len(common.SplitStrings(currency.MakecurrencyPairs(currency.DEFAULT_CURRENCIES), ","))
lengthDefault := len(common.SplitStrings(DEFAULT_CURRENCIES, ","))
fiatPairsLength := len(common.SplitStrings(MakecurrencyPairs(DEFAULT_CURRENCIES), ","))
if lengthDefault*(lengthDefault-1) > fiatPairsLength {
t.Error("Test Failed. MakecurrencyPairs: Error, mismatched length")
@@ -212,13 +210,13 @@ func TestMakecurrencyPairs(t *testing.T) {
func TestConvertCurrency(t *testing.T) {
t.Parallel()
fiatCurrencies := currency.DEFAULT_CURRENCIES
fiatCurrencies := DEFAULT_CURRENCIES
for _, currencyFrom := range common.SplitStrings(fiatCurrencies, ",") {
for _, currencyTo := range common.SplitStrings(fiatCurrencies, ",") {
if currencyFrom == currencyTo {
continue
} else {
floatyMcfloat, err := currency.ConvertCurrency(1000, currencyFrom, currencyTo)
floatyMcfloat, err := ConvertCurrency(1000, currencyFrom, currencyTo)
if err != nil {
t.Errorf("Test Failed. ConvertCurrency: Error %s with return: %.2f Currency 1: %s Currency 2: %s",
err, floatyMcfloat, currencyFrom, currencyTo)
@@ -237,7 +235,7 @@ func TestConvertCurrency(t *testing.T) {
func TestFetchYahooCurrencyData(t *testing.T) {
t.Parallel()
var fetchData []string
fiatCurrencies := currency.DEFAULT_CURRENCIES
fiatCurrencies := DEFAULT_CURRENCIES
for _, currencyOne := range common.SplitStrings(fiatCurrencies, ",") {
for _, currencyTwo := range common.SplitStrings(fiatCurrencies, ",") {
@@ -248,7 +246,7 @@ func TestFetchYahooCurrencyData(t *testing.T) {
}
}
}
err := currency.FetchYahooCurrencyData(fetchData)
err := FetchYahooCurrencyData(fetchData)
if err != nil {
t.Errorf("Test Failed. FetchYahooCurrencyData: Error %s", err)
}
@@ -257,12 +255,12 @@ func TestFetchYahooCurrencyData(t *testing.T) {
func TestQueryYahooCurrencyValues(t *testing.T) {
t.Parallel()
err := currency.QueryYahooCurrencyValues(currency.DEFAULT_CURRENCIES)
err := QueryYahooCurrencyValues(DEFAULT_CURRENCIES)
if err != nil {
t.Errorf("Test Failed. QueryYahooCurrencyValues: Error, %s", err)
}
err2 := currency.QueryYahooCurrencyValues(currency.DEFAULT_CRYPTOCURRENCIES)
err2 := QueryYahooCurrencyValues(DEFAULT_CRYPTOCURRENCIES)
if err2 == nil {
t.Errorf("Test Failed. QueryYahooCurrencyValues: Error, %s", err2)
}

View File

@@ -1,82 +1,79 @@
package tests
package events
import (
"testing"
"github.com/thrasher-/gocryptotrader/events"
)
func TestAddEvent(t *testing.T) {
eventID, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil && eventID != 0 {
t.Errorf("Test Failed. AddEvent: Error, %s", err)
}
eventID, err = events.AddEvent("ANXX", "price", ">,==", "BTC", "LTC", "console_print")
eventID, err = AddEvent("ANXX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err == nil && eventID == 0 {
t.Error("Test Failed. AddEvent: Error, error not captured in Exchange")
}
eventID, err = events.AddEvent("ANX", "prices", ">,==", "BTC", "LTC", "console_print")
eventID, err = AddEvent("ANX", "prices", ">,==", "BTC", "LTC", ACTION_TEST)
if err == nil && eventID == 0 {
t.Error("Test Failed. AddEvent: Error, error not captured in Item")
}
eventID, err = events.AddEvent("ANX", "price", "3===D", "BTC", "LTC", "console_print")
eventID, err = AddEvent("ANX", "price", "3===D", "BTC", "LTC", ACTION_TEST)
if err == nil && eventID == 0 {
t.Error("Test Failed. AddEvent: Error, error not captured in Condition")
}
eventID, err = events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_prints")
eventID, err = AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_prints")
if err == nil && eventID == 0 {
t.Error("Test Failed. AddEvent: Error, error not captured in Action")
}
eventID, err = events.AddEvent("ANX", "price", ">,==", "BATMAN", "ROBIN", "console_print")
eventID, err = AddEvent("ANX", "price", ">,==", "BATMAN", "ROBIN", ACTION_TEST)
if err == nil && eventID == 0 {
t.Error("Test Failed. AddEvent: Error, error not captured in Action")
}
if !events.RemoveEvent(eventID) {
if !RemoveEvent(eventID) {
t.Error("Test Failed. RemoveEvent: Error, error removing event")
}
}
func TestRemoveEvent(t *testing.T) {
eventID, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
eventID, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil && eventID != 0 {
t.Errorf("Test Failed. RemoveEvent: Error, %s", err)
}
if !events.RemoveEvent(eventID) {
if !RemoveEvent(eventID) {
t.Error("Test Failed. RemoveEvent: Error, error removing event")
}
}
func TestGetEventCounter(t *testing.T) {
one, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil {
t.Errorf("Test Failed. GetEventCounter: Error, %s", err)
}
two, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
two, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil {
t.Errorf("Test Failed. GetEventCounter: Error, %s", err)
}
three, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
three, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil {
t.Errorf("Test Failed. GetEventCounter: Error, %s", err)
}
total, _ := events.GetEventCounter()
total, _ := GetEventCounter()
if total <= 0 {
t.Errorf("Test Failed. GetEventCounter: Total = %d", total)
}
if !events.RemoveEvent(one) {
if !RemoveEvent(one) {
t.Error("Test Failed. GetEventCounter: Error, error removing event")
}
if !events.RemoveEvent(two) {
if !RemoveEvent(two) {
t.Error("Test Failed. GetEventCounter: Error, error removing event")
}
if !events.RemoveEvent(three) {
if !RemoveEvent(three) {
t.Error("Test Failed. GetEventCounter: Error, error removing event")
}
total2, _ := events.GetEventCounter()
t.Log(total2)
total2, _ := GetEventCounter()
if total2 != 0 {
t.Errorf("Test Failed. GetEventCounter: Total = %d", total2)
}
@@ -85,16 +82,16 @@ func TestGetEventCounter(t *testing.T) {
func TestExecuteAction(t *testing.T) {
t.Parallel()
one, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil {
t.Errorf("Test Failed. ExecuteAction: Error, %s", err)
}
isExecuted := events.Events[one].ExecuteAction()
isExecuted := Events[one].ExecuteAction()
if !isExecuted {
t.Error("Test Failed. ExecuteAction: Error, error removing event")
}
if !events.RemoveEvent(one) {
if !RemoveEvent(one) {
t.Error("Test Failed. ExecuteAction: Error, error removing event")
}
}
@@ -102,17 +99,17 @@ func TestExecuteAction(t *testing.T) {
func TestEventToString(t *testing.T) {
t.Parallel()
one, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil {
t.Errorf("Test Failed. EventToString: Error, %s", err)
}
eventString := events.Events[one].EventToString()
if eventString != "If the BTCLTC price on ANX is > == then console_print." {
eventString := Events[one].EventToString()
if eventString != "If the BTCLTC price on ANX is > == then ACTION_TEST." {
t.Error("Test Failed. EventToString: Error, incorrect return string")
}
if !events.RemoveEvent(one) {
if !RemoveEvent(one) {
t.Error("Test Failed. EventToString: Error, error removing event")
}
@@ -121,39 +118,39 @@ func TestEventToString(t *testing.T) {
func TestCheckCondition(t *testing.T) { //error handling needs to be implemented
t.Parallel()
one, err := events.AddEvent("ANX", "price", ">,==", "BTC", "LTC", "console_print")
one, err := AddEvent("ANX", "price", ">,==", "BTC", "LTC", ACTION_TEST)
if err != nil {
t.Errorf("Test Failed. EventToString: Error, %s", err)
}
conditionBool := events.Events[one].CheckCondition()
conditionBool := Events[one].CheckCondition()
if conditionBool { //check once error handling is implemented
t.Error("Test Failed. EventToString: Error, wrong conditional.")
}
if !events.RemoveEvent(one) {
if !RemoveEvent(one) {
t.Error("Test Failed. EventToString: Error, error removing event")
}
}
func TestIsValidEvent(t *testing.T) {
err := events.IsValidEvent("ANX", "price", ">,==", "console_print")
err := IsValidEvent("ANX", "price", ">,==", ACTION_TEST)
if err != nil {
t.Errorf("Test Failed. IsValidExchange: Error %s", err)
}
}
func TestCheckEvents(t *testing.T) { //Add error handling
//events.CheckEvents() //check once error handling is implemented
//CheckEvents() //check once error handling is implemented
}
func TestIsValidExchange(t *testing.T) {
boolean := events.IsValidExchange("ANX")
boolean := IsValidExchange("ANX", CONFIG_PATH_TEST)
if !boolean {
t.Error("Test Failed. IsValidExchange: Error, incorrect Exchange")
}
boolean = events.IsValidExchange("OBTUSE")
boolean = IsValidExchange("OBTUSE", CONFIG_PATH_TEST)
if boolean {
t.Error("Test Failed. IsValidExchange: Error, incorrect return")
}
@@ -162,27 +159,27 @@ func TestIsValidExchange(t *testing.T) {
func TestIsValidCondition(t *testing.T) {
t.Parallel()
boolean := events.IsValidCondition(">")
boolean := IsValidCondition(">")
if !boolean {
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
}
boolean = events.IsValidCondition(">=")
boolean = IsValidCondition(">=")
if !boolean {
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
}
boolean = events.IsValidCondition("<")
boolean = IsValidCondition("<")
if !boolean {
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
}
boolean = events.IsValidCondition("<=")
boolean = IsValidCondition("<=")
if !boolean {
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
}
boolean = events.IsValidCondition("==")
boolean = IsValidCondition("==")
if !boolean {
t.Error("Test Failed. IsValidCondition: Error, incorrect Condition")
}
boolean = events.IsValidCondition("**********")
boolean = IsValidCondition("**********")
if boolean {
t.Error("Test Failed. IsValidCondition: Error, incorrect return")
}
@@ -191,15 +188,15 @@ func TestIsValidCondition(t *testing.T) {
func TestIsValidAction(t *testing.T) {
t.Parallel()
boolean := events.IsValidAction("sms")
boolean := IsValidAction("sms")
if !boolean {
t.Error("Test Failed. IsValidAction: Error, incorrect Action")
}
boolean = events.IsValidAction("console_print")
boolean = IsValidAction(ACTION_TEST)
if !boolean {
t.Error("Test Failed. IsValidAction: Error, incorrect Action")
}
boolean = events.IsValidAction("randomstring")
boolean = IsValidAction("randomstring")
if boolean {
t.Error("Test Failed. IsValidAction: Error, incorrect return")
}
@@ -208,11 +205,11 @@ func TestIsValidAction(t *testing.T) {
func TestIsValidItem(t *testing.T) {
t.Parallel()
boolean := events.IsValidItem("price")
boolean := IsValidItem("price")
if !boolean {
t.Error("Test Failed. IsValidItem: Error, incorrect Item")
}
boolean = events.IsValidItem("obtuse")
boolean = IsValidItem("obtuse")
if boolean {
t.Error("Test Failed. IsValidItem: Error, incorrect return")
}

View File

@@ -22,6 +22,8 @@ const (
IS_EQUAL = "=="
ACTION_SMS_NOTIFY = "SMS"
ACTION_CONSOLE_PRINT = "CONSOLE_PRINT"
ACTION_TEST = "ACTION_TEST"
CONFIG_PATH_TEST = "../testdata/configtest.dat"
)
var (
@@ -174,7 +176,12 @@ func IsValidEvent(Exchange, Item, Condition, Action string) error {
Item = common.StringToUpper(Item)
Action = common.StringToUpper(Action)
if !IsValidExchange(Exchange) {
configPath := ""
if Action == ACTION_TEST {
configPath = CONFIG_PATH_TEST
}
if !IsValidExchange(Exchange, configPath) {
return ErrExchangeDisabled
}
@@ -203,7 +210,7 @@ func IsValidEvent(Exchange, Item, Condition, Action string) error {
return ErrInvalidAction
}
} else {
if Action != ACTION_CONSOLE_PRINT {
if Action != ACTION_CONSOLE_PRINT && Action != ACTION_TEST {
return ErrInvalidAction
}
}
@@ -240,12 +247,12 @@ func IsValidCurrency(currencies ...string) bool {
return false
}
func IsValidExchange(Exchange string) bool {
func IsValidExchange(Exchange, configPath string) bool {
Exchange = common.StringToUpper(Exchange)
cfg := config.GetConfig()
if len(cfg.Exchanges) == 0 {
cfg.LoadConfig()
cfg.LoadConfig(configPath)
}
for _, x := range cfg.Exchanges {
@@ -267,7 +274,7 @@ func IsValidCondition(Condition string) bool {
func IsValidAction(Action string) bool {
Action = common.StringToUpper(Action)
switch Action {
case ACTION_SMS_NOTIFY, ACTION_CONSOLE_PRINT:
case ACTION_SMS_NOTIFY, ACTION_CONSOLE_PRINT, ACTION_TEST:
return true
}
return false

View File

@@ -137,6 +137,10 @@ func (a *Alphapoint) GetProducts() (AlphapointProducts, error) {
}
func (a *Alphapoint) CreateAccount(firstName, lastName, email, phone, password string) error {
if len(password) < 8 {
return errors.New("Alphapoint Error - Create account - Password must be 8 characters or more.")
}
request := make(map[string]interface{})
request["firstname"] = firstName
request["lastname"] = lastName
@@ -390,7 +394,6 @@ func (a *Alphapoint) SendRequest(method, path string, data map[string]interface{
if err != nil {
return errors.New("SendAuthenticatedHTTPRequest: Unable to JSON request")
}
resp, err := common.SendHTTPRequest(method, path, headers, bytes.NewBuffer(PayloadJson))
if err != nil {

View File

@@ -0,0 +1,413 @@
package alphapoint
import (
"reflect"
"testing"
)
func TestSetDefaults(t *testing.T) {
t.Parallel()
SetDefaults := Alphapoint{}
SetDefaults.SetDefaults()
if SetDefaults.APIUrl != "https://sim3.alphapoint.com:8400" {
t.Error("Test Failed - SetDefaults: String Incorrect -", SetDefaults.APIUrl)
}
if SetDefaults.WebsocketURL != "wss://sim3.alphapoint.com:8401/v1/GetTicker/" {
t.Error("Test Failed - SetDefaults: String Incorrect -", SetDefaults.WebsocketURL)
}
}
func TestGetTicker(t *testing.T) {
GetTicker := Alphapoint{}
GetTicker.SetDefaults()
response, err := GetTicker.GetTicker("BTCUSD")
if err != nil {
t.Error("Test Failed - Alphapoint GetTicker init error: ", err)
}
if reflect.ValueOf(response).NumField() != 13 {
t.Error("Test Failed - Alphapoint GetTicker struct change/or updated")
}
if reflect.TypeOf(response.Ask).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.Ask value is not a float64")
}
if reflect.TypeOf(response.Bid).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.Bid value is not a float64")
}
if reflect.TypeOf(response.BuyOrderCount).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.BuyOrderCount value is not a float64")
}
if reflect.TypeOf(response.High).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.High value is not a float64")
}
if reflect.TypeOf(response.IsAccepted).String() != "bool" {
t.Error("Test Failed - Alphapoint GetTicker.IsAccepted value is not a bool")
}
if reflect.TypeOf(response.Last).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.Last value is not a float64")
}
if reflect.TypeOf(response.Low).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.Low value is not a float64")
}
if reflect.TypeOf(response.NumOfCreateOrders).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.NumOfCreateOrders value is not a float64")
}
if reflect.TypeOf(response.RejectReason).String() != "string" {
t.Error("Test Failed - Alphapoint GetTicker.RejectReason value is not a string")
}
if reflect.TypeOf(response.SellOrderCount).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.SellOrderCount value is not a float64")
}
if reflect.TypeOf(response.Total24HrNumTrades).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.Total24HrNumTrades value is not a float64")
}
if reflect.TypeOf(response.Total24HrQtyTraded).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.Total24HrQtyTraded value is not a float64")
}
if reflect.TypeOf(response.Volume).String() != "float64" {
t.Error("Test Failed - Alphapoint GetTicker.Volume value is not a float64")
}
if response.Ask < 0 {
t.Error("Test Failed - Alphapoint GetTicker.Ask value is negative")
}
if response.Bid < 0 {
t.Error("Test Failed - Alphapoint GetTicker.Bid value is negative")
}
if response.BuyOrderCount < 0 {
t.Error("Test Failed - Alphapoint GetTicker.High value is negative")
}
if response.High < 0 {
t.Error("Test Failed - Alphapoint GetTicker.Last value is negative")
}
if response.Last < 0 {
t.Error("Test Failed - Alphapoint GetTicker.Low value is negative")
}
if response.Low < 0 {
t.Error("Test Failed - Alphapoint GetTicker.Mid value is negative")
}
if response.NumOfCreateOrders < 0 {
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
}
if response.SellOrderCount < 0 {
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
}
if response.Total24HrNumTrades < 0 {
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
}
if response.Total24HrQtyTraded < 0 {
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
}
if response.Volume < 0 {
t.Error("Test Failed - Alphapoint GetTicker.ask value is negative")
}
}
func TestGetTrades(t *testing.T) {
GetTrades := Alphapoint{}
GetTrades.SetDefaults()
trades, err := GetTrades.GetTrades("BTCUSD", 0, 10)
if err != nil {
t.Errorf("Test Failed - Init error: %s", err)
}
if reflect.ValueOf(trades).NumField() != 7 {
t.Error("Test Failed - Alphapoint AlphapointTrades struct updated/changed")
}
if len(trades.Trades) == 0 {
t.Error("Test Failed - Alphapoint trades.Trades: Incorrect length")
}
if reflect.ValueOf(trades.Trades[0]).NumField() != 8 {
t.Error("Test Failed - Alphapoint AlphapointTrades.Trades struct updated/changed")
}
if reflect.TypeOf(trades.Trades[0].BookServerOrderID).String() != "int" {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is not a int")
}
if reflect.TypeOf(trades.Trades[0].IncomingOrderSide).String() != "int" {
t.Error("Test Failed - Alphapoint trades.Trades.IncomingOrderSide value is not a int")
}
if reflect.TypeOf(trades.Trades[0].IncomingServerOrderID).String() != "int" {
t.Error("Test Failed - Alphapoint trades.Trades.IncomingServerOrderID value is not a int")
}
if reflect.TypeOf(trades.Trades[0].Price).String() != "float64" {
t.Error("Test Failed - Alphapoint trades.Trades.Price value is not a float64")
}
if reflect.TypeOf(trades.Trades[0].Quantity).String() != "float64" {
t.Error("Test Failed - Alphapoint trades.Trades.Quantity value is not a float64")
}
if reflect.TypeOf(trades.Trades[0].TID).String() != "int64" {
t.Error("Test Failed - Alphapoint trades.Trades.TID value is not a int64")
}
if reflect.TypeOf(trades.Trades[0].UTCTicks).String() != "int64" {
t.Error("Test Failed - Alphapoint trades.Trades.UTCTicks value is not a int64")
}
if reflect.TypeOf(trades.Trades[0].Unixtime).String() != "int" {
t.Error("Test Failed - Alphapoint trades.Trades.Unixtime value is not a int")
}
if reflect.TypeOf(trades.Count).String() != "int" {
t.Error("Test Failed - Alphapoint trades.Count value is not a int")
}
if reflect.TypeOf(trades.DateTimeUTC).String() != "int64" {
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is not a int64")
}
if reflect.TypeOf(trades.Instrument).String() != "string" {
t.Error("Test Failed - Alphapoint trades.Instrument value is not a string")
}
if reflect.TypeOf(trades.IsAccepted).String() != "bool" {
t.Error("Test Failed - Alphapoint trades.IsAccepted value is not a bool")
}
if reflect.TypeOf(trades.RejectReason).String() != "string" {
t.Error("Test Failed - Alphapoint trades.string value is not a string")
}
if reflect.TypeOf(trades.StartIndex).String() != "int" {
t.Error("Test Failed - Alphapoint trades.Count value is not a int")
}
if trades.Count < 0 {
t.Error("Test Failed - Alphapoint trades.Count value is negative")
}
if trades.DateTimeUTC <= 0 {
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is negative or 0")
}
if trades.Instrument != "BTCUSD" {
t.Error("Test Failed - Alphapoint trades.Instrument value is incorrect")
}
if trades.IsAccepted != true {
t.Error("Test Failed - Alphapoint trades.IsAccepted value is true")
}
if len(trades.RejectReason) > 0 {
t.Error("Test Failed - Alphapoint trades.IsAccepted value has been returned")
}
if trades.StartIndex != 0 {
t.Error("Test Failed - Alphapoint trades.StartIndex value is incorrect")
}
if trades.Trades[0].BookServerOrderID < 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
if trades.Trades[0].IncomingOrderSide < 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
if trades.Trades[0].IncomingServerOrderID < 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
if trades.Trades[0].Price < 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
if trades.Trades[0].Quantity < 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
if trades.Trades[0].TID != 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
if trades.Trades[0].UTCTicks < 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
if trades.Trades[0].Unixtime < 0 {
t.Error("Test Failed - Alphapoint trades.Trades.BookServerOrderID value is negative")
}
}
func TestGetTradesByDate(t *testing.T) {
GetTradesByDate := Alphapoint{}
GetTradesByDate.SetDefaults()
trades, err := GetTradesByDate.GetTradesByDate("BTCUSD", 1414799400, 1414800000)
if err != nil {
t.Errorf("Test Failed - Init error: %s", err)
}
if reflect.ValueOf(trades).NumField() != 7 {
t.Error("Test Failed - Alphapoint AlphapointTrades struct updated/changed")
}
if len(trades.Trades) != 0 {
t.Error("Test Failed - Alphapoint trades.Trades: Incorrect length")
}
if reflect.TypeOf(trades.DateTimeUTC).String() != "int64" {
t.Error("Test Failed - Alphapoint trades.Count value is not a int64")
}
if reflect.TypeOf(trades.EndDate).String() != "int64" {
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is not a int64")
}
if reflect.TypeOf(trades.Instrument).String() != "string" {
t.Error("Test Failed - Alphapoint trades.Instrument value is not a string")
}
if reflect.TypeOf(trades.IsAccepted).String() != "bool" {
t.Error("Test Failed - Alphapoint trades.IsAccepted value is not a bool")
}
if reflect.TypeOf(trades.RejectReason).String() != "string" {
t.Error("Test Failed - Alphapoint trades.string value is not a string")
}
if reflect.TypeOf(trades.StartDate).String() != "int64" {
t.Error("Test Failed - Alphapoint trades.StartDate value is not a int64")
}
if trades.DateTimeUTC < 0 {
t.Error("Test Failed - Alphapoint trades.Count value is negative")
}
if trades.EndDate < 0 {
t.Error("Test Failed - Alphapoint trades.DateTimeUTC value is negative")
}
if trades.Instrument != "BTCUSD" {
t.Error("Test Failed - Alphapoint trades.Instrument value is incorrect")
}
if trades.IsAccepted != true {
t.Error("Test Failed - Alphapoint trades.IsAccepted value is true")
}
if len(trades.RejectReason) > 0 {
t.Error("Test Failed - Alphapoint trades.IsAccepted value has been returned")
}
if trades.StartDate < 0 {
t.Error("Test Failed - Alphapoint trades.StartIndex value is negative")
}
}
func TestGetOrderbook(t *testing.T) {
GetOrderbook := Alphapoint{}
GetOrderbook.SetDefaults()
orderBook, err := GetOrderbook.GetOrderbook("BTCUSD")
if err != nil {
t.Errorf("Test Failed - Init error: %s", err)
}
if reflect.ValueOf(orderBook).NumField() != 4 {
t.Error("Test Failed - Alphapoint AlphapointOrderbook struct updated/changed")
}
if reflect.TypeOf(orderBook.IsAccepted).String() != "bool" {
t.Error("Test Failed - Alphapoint orderBook.IsAccepted value is not a bool")
}
if reflect.TypeOf(orderBook.RejectReason).String() != "string" {
t.Error("Test Failed - Alphapoint orderBook.RejectReason value is not a string")
}
if len(orderBook.Asks) < 1 {
t.Error("Test Failed - Alphapoint orderBook.Asks does not contain anything.")
}
if len(orderBook.Bids) < 1 {
t.Error("Test Failed - Alphapoint orderBook.Asks does not contain anything.")
}
}
func TestGetProductPairs(t *testing.T) {
GetProductPairs := Alphapoint{}
GetProductPairs.SetDefaults()
productPairs, err := GetProductPairs.GetProductPairs()
if err != nil {
t.Errorf("Test Failed - Init error: %s", err)
}
if reflect.ValueOf(productPairs).NumField() != 3 {
t.Error("Test Failed - Alphapoint GetProductPairs struct updated/changed")
}
if reflect.TypeOf(productPairs.IsAccepted).String() != "bool" {
t.Error("Test Failed - Alphapoint productPairs.IsAccepted value is not a bool")
}
if reflect.TypeOf(productPairs.RejectReason).String() != "string" {
t.Error("Test Failed - Alphapoint productPairs.RejectReason value is not a string")
}
if len(productPairs.ProductPairs) >= 1 {
if reflect.ValueOf(productPairs.ProductPairs[0]).NumField() != 6 {
t.Error("Test Failed - Alphapoint GetProductPairs.ProductPairs[] struct updated/changed")
}
if reflect.TypeOf(productPairs.ProductPairs[0].Name).String() != "string" {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Name value is not a string")
}
if reflect.TypeOf(productPairs.ProductPairs[0].Product1Decimalplaces).String() != "int" {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product1Decimalplaces value is not a int")
}
if reflect.TypeOf(productPairs.ProductPairs[0].Product1Label).String() != "string" {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product1Label value is not a string")
}
if reflect.TypeOf(productPairs.ProductPairs[0].Product2Decimalplaces).String() != "int" {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product2Decimalplaces value is not a int")
}
if reflect.TypeOf(productPairs.ProductPairs[0].Product2Label).String() != "string" {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product2Label value is not a string")
}
if reflect.TypeOf(productPairs.ProductPairs[0].Productpaircode).String() != "int" {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Productpaircode value is not a int")
}
if productPairs.ProductPairs[0].Product1Decimalplaces < 0 {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product1Decimalplaces value is negative")
}
if productPairs.ProductPairs[0].Product2Decimalplaces < 0 {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Product2Decimalplaces value is negative")
}
if productPairs.ProductPairs[0].Productpaircode < 0 {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs.Productpaircode value is negative")
}
} else {
t.Error("Test Failed - Alphapoint productPairs.ProductPairs no product pairs.")
}
}
func TestGetProducts(t *testing.T) {
GetProducts := Alphapoint{}
GetProducts.SetDefaults()
products, err := GetProducts.GetProducts()
if err != nil {
t.Errorf("Test Failed - Init error: %s", err)
}
if reflect.ValueOf(products).NumField() != 3 {
t.Error("Test Failed - Alphapoint GetProductPairs struct updated/changed")
}
if reflect.TypeOf(products.IsAccepted).String() != "bool" {
t.Error("Test Failed - Alphapoint products.IsAccepted value is not a bool")
}
if reflect.TypeOf(products.RejectReason).String() != "string" {
t.Error("Test Failed - Alphapoint products.RejectReason value is not a string")
}
if len(products.Products) >= 1 {
if reflect.ValueOf(products.Products[0]).NumField() != 5 {
t.Error("Test Failed - Alphapoint Getproducts.Products[] struct updated/changed")
}
if reflect.TypeOf(products.Products[0].DecimalPlaces).String() != "int" {
t.Error("Test Failed - Alphapoint products.Products.DecimalPlaces value is not a int")
}
if reflect.TypeOf(products.Products[0].FullName).String() != "string" {
t.Error("Test Failed - Alphapoint products.Products.FullName value is not a string")
}
if reflect.TypeOf(products.Products[0].IsDigital).String() != "bool" {
t.Error("Test Failed - Alphapoint products.Products.IsDigital value is not a bool")
}
if reflect.TypeOf(products.Products[0].Name).String() != "string" {
t.Error("Test Failed - Alphapoint products.Products.Name value is not a string")
}
if reflect.TypeOf(products.Products[0].ProductCode).String() != "int" {
t.Error("Test Failed - Alphapoint products.Products.ProductCode value is not a int")
}
if products.Products[0].DecimalPlaces < 0 {
t.Error("Test Failed - Alphapoint products.Products.DecimalPlaces value is negative")
}
if products.Products[0].ProductCode < 0 {
t.Log(products.Products[0].ProductCode)
t.Error("Test Failed - Alphapoint products.Products.ProductCode value is negative")
}
} else {
t.Error("Test Failed - Alphapoint products.Products no product pairs.")
}
}
func TestCreateAccount(t *testing.T) {
CreateAccount := Alphapoint{}
CreateAccount.SetDefaults()
err := CreateAccount.CreateAccount("test", "account", "oharareid.ryan@gmail.com", "0433588258", "lolcat123")
if err != nil {
t.Errorf("Test Failed - Init error: %s", err)
}
}
func TestGetUserInfo(t *testing.T) {
GetUserInfo := Alphapoint{}
GetUserInfo.SetDefaults()
userInfo, err := GetUserInfo.GetUserInfo()
if err != nil {
t.Errorf("Test Failed - Init error: %s", err)
}
t.Log(userInfo)
}

View File

@@ -26,7 +26,7 @@ func GetEnabledSMSContacts(smsCfg config.SMSGlobalConfig) int {
return counter
}
func SMSSendToAll(message string, cfg config.Config) {
func SMSSendToAll(message string, cfg config.Config) { // return error here
for _, contact := range cfg.SMS.Contacts {
if contact.Enabled {
err := SMSNotify(contact.Number, message, cfg)

View File

@@ -1,20 +1,19 @@
package test
package smsglobal
import (
"testing"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/smsglobal"
)
func TestGetEnabledSMSContacts(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig()
err := cfg.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test Failed. GetEnabledSMSContacts: \nFunction return is incorrect with, %s.", err)
}
numberOfContacts := smsglobal.GetEnabledSMSContacts(cfg.SMS)
numberOfContacts := GetEnabledSMSContacts(cfg.SMS)
if numberOfContacts != len(cfg.SMS.Contacts) {
t.Errorf("Test Failed. GetEnabledSMSContacts: \nFunction return is incorrect with, %d.", numberOfContacts)
}
@@ -22,21 +21,21 @@ func TestGetEnabledSMSContacts(t *testing.T) {
func TestSMSSendToAll(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig()
err := cfg.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test Failed. SMSSendToAll: \nFunction return is incorrect with, %s.", err)
}
smsglobal.SMSSendToAll("Test", *cfg) //+60sec reply issue without account details
SMSSendToAll("SMSGLOBAL Test - SMSSENDTOALL", *cfg) //+60sec reply issue without account details
}
func TestSMSGetNumberByName(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig()
err := cfg.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test Failed. SMSGetNumberByName: \nFunction return is incorrect with, %s.", err)
}
number := smsglobal.SMSGetNumberByName("POLYESTERGIRL", cfg.SMS)
number := SMSGetNumberByName("StyleGherkin", cfg.SMS)
if number == "" {
t.Error("Test Failed. SMSNotify: \nError: No number, name not found.")
}
@@ -44,12 +43,12 @@ func TestSMSGetNumberByName(t *testing.T) {
func TestSMSNotify(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig()
err := cfg.LoadConfig("../testdata/configtest.dat")
if err != nil {
t.Errorf("Test Failed. SMSNotify: \nFunction return is incorrect with, %s.", err)
}
err2 := smsglobal.SMSNotify(cfg.SMS.Contacts[0].Number, "Test", *cfg)
err2 := SMSNotify(cfg.SMS.Contacts[0].Number, "SMSGLOBAL Test - SMS SEND TO SINGLE", *cfg)
if err2 != nil {
t.Error("Test Failed. SMSNotify: \nError: ", err2)
}

View File

@@ -17,24 +17,24 @@
{
"Address": "LgY8ahfHRhvjVQC1zJnBhFMG5pCTMuKRqh",
"CoinType": "LTC",
"Balance": 3.00000005e+06
"Balance": 3000000.05
},
{
"Address": "0xb794f5ea0ba39494ce839613fffba74279579268",
"CoinType": "ETH",
"Balance": 5.774999820458524e+06
"Balance": 5774999.820458524
}
]
},
"SMSGlobal": {
"Enabled": false,
"Username": "Username",
"Password": "Password",
"Enabled": true,
"Username": "1234",
"Password": "12334",
"Contacts": [
{
"Name": "Bob",
"Number": "12345",
"Enabled": false
"Name": "StyleGherkin",
"Number": "1231424",
"Enabled": true
}
]
},
@@ -54,7 +54,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC",
"EnabledPairs": "BTCUSD,BTCHKD,BTCEUR,BTCCAD,BTCAUD,BTCSGD,BTCJPY,BTCGBP,BTCNZD,LTCBTC,DOGEBTC,STRBTC,XRPBTC",
"BaseCurrencies": "USD,HKD,EUR,CAD,AUD,SGD,JPY,GBP,NZD"
@@ -68,7 +67,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC,ETCBTC,ETCUSD,BFXUSD,BFXBTC,RRTUSD,RRTBTC,ZECUSD,ZECBTC,XMRUSD,XMRBTC,DSHUSD,DSHBTC",
"EnabledPairs": "BTCUSD,LTCUSD,LTCBTC,ETHUSD,ETHBTC",
"BaseCurrencies": "USD"
@@ -96,7 +94,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCCNY,LTCCNY,LTCBTC",
"EnabledPairs": "BTCCNY,LTCCNY,LTCBTC",
"BaseCurrencies": "CNY"
@@ -110,7 +107,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD",
"EnabledPairs": "BTCUSD,BTCRUR,BTCEUR,LTCBTC,LTCUSD,LTCRUR,LTCEUR,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,PPCBTC,PPCUSD",
"BaseCurrencies": "USD,RUR,EUR"
@@ -124,7 +120,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "LTC,BTC",
"EnabledPairs": "LTC,BTC",
"BaseCurrencies": "AUD"
@@ -152,7 +147,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,ETHBTC,ETHUSD",
"EnabledPairs": "BTCUSD",
"BaseCurrencies": "USD"
@@ -166,7 +160,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCCNY,LTCCNY",
"EnabledPairs": "BTCCNY,LTCCNY",
"BaseCurrencies": "CNY"
@@ -194,7 +187,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "ETCUSD,ICNETH,REPXBT,ZECXBT,ETHXBT,ETHXBT.d,ETHGBP,LTCXBT,XBTGBP.d,XDGXBT,XMRUSD,ZECUSD,ETCETH,ETHJPY,XBTCAD.d,XBTJPY.d,XBTUSD.d,XLMXBT,XLMEUR,XLMUSD,XMREUR,ETCXBT,ETHCAD.d,ETHEUR.d,ETHJPY.d,XBTEUR.d,ETHEUR,ETHGBP.d,ICNXBT,LTCEUR,REPEUR,XBTGBP,XBTJPY,ETHUSD,ETHUSD.d,LTCUSD,REPETH,XBTUSD,XMRXBT,ETCEUR,ETHCAD,REPUSD,XBTCAD,XBTEUR,XRPXBT,ZECEUR",
"EnabledPairs": "ETCUSD,XBTUSD,ETHUSD",
"BaseCurrencies": "EUR,USD,CAD,GBP,JPY"
@@ -208,7 +200,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,BTCEUR,USDHKD,AUDUSD,BTCGBP,BTCNZD,USDJPY,BTCSGD,BTCNGN,EURUSD,USDSGD,NZDUSD,USDNGN,USDCHF,BTCJPY,BTCAUD,BTCCAD,BTCCHF,GBPUSD,USDCAD",
"EnabledPairs": "BTCUSD,BTCAUD",
"BaseCurrencies": "USD,EUR,HKD,AUD,GBP,NZD,JPY,SGD,NGN,CHF,CAD"
@@ -222,7 +213,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "TIME_BTC,ETH_BTC,GNT_BTC,WAVES_BTC,ICN_BTC,1ST_BTC,WINGS_BTC,MLN_BTC,ROUND_BTC,VSL_BTC,LTC_BTC,DCT_BTC,INCNT_BTC,PLU_BTC,DASH_BTC",
"EnabledPairs": "ETH_BTC,LTC_BTC,DASH_BTC",
"BaseCurrencies": "USD"
@@ -236,7 +226,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR",
"EnabledPairs": "BTCARS,BTCAUD,BTCBRL,BTCCAD,BTCCHF,BTCCZK,BTCDKK,BTCEUR,BTCGBP,BTCHKD,BTCILS,BTCINR,BTCMXN,BTCNOK,BTCNZD,BTCPLN,BTCRUB,BTCSEK,BTCSGD,BTCTHB,BTCUSD,BTCZAR",
"BaseCurrencies": "ARS,AUD,BRL,CAD,CHF,CZK,DKK,EUR,GBP,HKD,ILS,INR,MXN,NOK,NZD,PLN,RUB,SEK,SGD,THB,USD,ZAR"
@@ -250,7 +239,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCCNY,LTCCNY",
"EnabledPairs": "BTCCNY,LTCCNY",
"BaseCurrencies": "CNY"
@@ -264,7 +252,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTCUSD,LTCUSD",
"EnabledPairs": "BTCUSD,LTCUSD",
"BaseCurrencies": "USD"
@@ -278,7 +265,6 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "",
"AvailablePairs": "BTC_XUSD,BTC_FCT,BTC_MMNXT,BTC_NMC,BTC_BITUSD,BTC_RDD,BTC_XMR,BTC_XST,BTC_DSH,BTC_MAID,BTC_DGB,BTC_NEOS,BTC_BLK,BTC_NAUT,BTC_NBT,BTC_XCP,BTC_STR,BTC_BTCD,BTC_GRC,BTC_HUC,BTC_BBR,BTC_XDN,BTC_INDEX,BTC_IOC,BTC_SWARM,BTC_EMC2,BTC_MCN,BTC_NOXT,BTC_MINT,BTC_PTS,BTC_SC,BTC_GEO,BTC_XRP,BTC_FLO,BTC_BITS,BTC_HYP,BTC_XCR,BTC_LTBC,BTC_SYS,BTC_GMC,BTC_ETH,BTC_SYNC,BTC_GAP,BTC_BCN,BTC_C2,BTC_PINK,BTC_FIBRE,BTC_POT,BTC_QTL,BTC_SDC,BTC_XC,BTC_DASH,BTC_SILK,BTC_CLAM,BTC_NAV,BTC_PIGGY,BTC_BCY,BTC_MIL,BTC_XCN,BTC_YACC,BTC_BTS,BTC_QBK,BTC_SJCX,BTC_LQD,BTC_BURST,BTC_RIC,BTC_VRC,BTC_LTC,BTC_XPB,BTC_GRS,BTC_XCH,BTC_ARCH,BTC_QORA,BTC_HZ,BTC_NSR,BTC_XPM,BTC_BITCNY,BTC_EXE,BTC_XMG,BTC_BTC,BTC_BTM,BTC_NOBL,BTC_NXT,BTC_DOGE,BTC_CURE,BTC_MNTA,BTC_ADN,BTC_EXP,BTC_VTC,BTC_FLDC,BTC_MRS,BTC_MYR,BTC_OMNI,BTC_VNL,BTC_USDT,BTC_NOTE,BTC_WDC,BTC_BELA,BTC_VIA,BTC_CGA,BTC_DIEM,BTC_IFC,BTC_XDP,BTC_BLOCK,BTC_MMC,BTC_1CR,BTC_UNITY,BTC_XBC,BTC_GEMZ,BTC_FLT,BTC_PPC,BTC_XEM,BTC_RBY,BTC_CNMT,BTC_ABY,XMR_XDN,XMR_IFC,XMR_DIEM,XMR_BBR,XMR_DSH,XMR_BCN,XMR_LTC,XMR_MAID,XMR_DASH,XMR_BTCD,XMR_HYP,XMR_BLK,XMR_QORA,XMR_MNTA,XMR_NXT,USDT_BTC,USDT_ETH,USDT_XRP,USDT_DASH,USDT_LTC,USDT_NXT,USDT_XMR,USDT_STR",
"EnabledPairs": "BTC_LTC,BTC_ETH,BTC_DOGE,BTC_DASH,BTC_XRP",
"BaseCurrencies": "USD"