2018-02-13 16:31:57 +00:00
|
|
|
package test_config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/config"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
)
|
|
|
|
|
|
|
|
var TestConfig *viper.Viper
|
|
|
|
var DBConfig config.Database
|
|
|
|
var Infura *viper.Viper
|
|
|
|
var InfuraClient config.Client
|
|
|
|
var ABIFilePath string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
setTestConfig()
|
|
|
|
setInfuraConfig()
|
|
|
|
setABIPath()
|
|
|
|
}
|
|
|
|
|
|
|
|
func setTestConfig() {
|
|
|
|
TestConfig = viper.New()
|
|
|
|
TestConfig.SetConfigName("private")
|
|
|
|
TestConfig.AddConfigPath("$GOPATH/src/github.com/vulcanize/vulcanizedb/environments/")
|
|
|
|
err := TestConfig.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
hn := TestConfig.GetString("database.hostname")
|
|
|
|
port := TestConfig.GetInt("database.port")
|
|
|
|
name := TestConfig.GetString("database.name")
|
|
|
|
DBConfig = config.Database{
|
|
|
|
Hostname: hn,
|
|
|
|
Name: name,
|
|
|
|
Port: port,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func setInfuraConfig() {
|
|
|
|
Infura = viper.New()
|
|
|
|
Infura.SetConfigName("infura")
|
|
|
|
Infura.AddConfigPath("$GOPATH/src/github.com/vulcanize/vulcanizedb/environments/")
|
|
|
|
err := Infura.ReadInConfig()
|
|
|
|
ipc := Infura.GetString("client.ipcpath")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
InfuraClient = config.Client{
|
|
|
|
IPCPath: ipc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func setABIPath() {
|
|
|
|
gp := os.Getenv("GOPATH")
|
|
|
|
ABIFilePath = gp + "/src/github.com/vulcanize/vulcanizedb/pkg/geth/testing/"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTestDB(node core.Node) *postgres.DB {
|
|
|
|
db, _ := postgres.NewDB(DBConfig, node)
|
|
|
|
db.MustExec("DELETE FROM blocks")
|
2018-07-17 21:23:07 +00:00
|
|
|
db.MustExec("DELETE FROM headers")
|
|
|
|
db.MustExec("DELETE FROM log_filters")
|
2018-02-13 16:31:57 +00:00
|
|
|
db.MustExec("DELETE FROM logs")
|
|
|
|
db.MustExec("DELETE FROM receipts")
|
2018-07-17 21:23:07 +00:00
|
|
|
db.MustExec("DELETE FROM transactions")
|
|
|
|
db.MustExec("DELETE FROM watched_contracts")
|
2018-02-13 16:31:57 +00:00
|
|
|
return db
|
|
|
|
}
|
2018-05-05 20:25:54 +00:00
|
|
|
|
|
|
|
func NewTestDBWithoutDeletingRecords(node core.Node) *postgres.DB {
|
|
|
|
db, _ := postgres.NewDB(DBConfig, node)
|
|
|
|
return db
|
|
|
|
}
|