2018-02-13 16:31:57 +00:00
|
|
|
package test_config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2018-08-07 20:17:29 +00:00
|
|
|
. "github.com/onsi/gomega"
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/spf13/viper"
|
2018-08-07 20:17:29 +00:00
|
|
|
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/config"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
2018-08-07 20:17:29 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
2018-02-13 16:31:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var TestConfig *viper.Viper
|
|
|
|
var DBConfig config.Database
|
2018-08-07 20:17:29 +00:00
|
|
|
var TestClient config.Client
|
2018-02-13 16:31:57 +00:00
|
|
|
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()
|
2018-08-07 20:17:29 +00:00
|
|
|
ipc := TestConfig.GetString("client.ipcPath")
|
2018-02-13 16:31:57 +00:00
|
|
|
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,
|
|
|
|
}
|
2018-08-07 20:17:29 +00:00
|
|
|
TestClient = config.Client{
|
|
|
|
IPCPath: ipc,
|
|
|
|
}
|
2018-02-13 16:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-08-07 20:17:29 +00:00
|
|
|
return db
|
|
|
|
}
|
|
|
|
|
|
|
|
func CleanTestDB(db *postgres.DB) {
|
2018-02-13 16:31:57 +00:00
|
|
|
db.MustExec("DELETE FROM blocks")
|
2018-07-17 21:23:07 +00:00
|
|
|
db.MustExec("DELETE FROM headers")
|
2018-10-10 10:39:20 +00:00
|
|
|
db.MustExec("DELETE FROM checked_headers")
|
2018-07-17 21:23:07 +00:00
|
|
|
db.MustExec("DELETE FROM log_filters")
|
2018-02-13 16:31:57 +00:00
|
|
|
db.MustExec("DELETE FROM logs")
|
2018-09-04 16:35:38 +00:00
|
|
|
db.MustExec("DELETE FROM maker.bite")
|
2018-09-12 14:10:34 +00:00
|
|
|
db.MustExec("DELETE FROM maker.cat_file_chop_lump")
|
|
|
|
db.MustExec("DELETE FROM maker.cat_file_flip")
|
|
|
|
db.MustExec("DELETE FROM maker.cat_file_pit_vow")
|
2018-10-10 16:35:37 +00:00
|
|
|
db.MustExec("DELETE FROM maker.deal")
|
|
|
|
db.MustExec("DELETE FROM maker.dent")
|
|
|
|
db.MustExec("DELETE FROM maker.drip_drip")
|
2018-09-04 16:35:38 +00:00
|
|
|
db.MustExec("DELETE FROM maker.drip_file_ilk")
|
|
|
|
db.MustExec("DELETE FROM maker.drip_file_repo")
|
|
|
|
db.MustExec("DELETE FROM maker.drip_file_vow")
|
2018-11-06 17:11:09 +00:00
|
|
|
db.MustExec("DELETE FROM maker.flap_kick")
|
2018-10-10 16:35:37 +00:00
|
|
|
db.MustExec("DELETE FROM maker.flip_kick")
|
|
|
|
db.MustExec("DELETE FROM maker.flop_kick")
|
|
|
|
db.MustExec("DELETE FROM maker.frob")
|
2018-09-04 16:35:38 +00:00
|
|
|
db.MustExec("DELETE FROM maker.pit_file_debt_ceiling")
|
2018-09-05 14:24:28 +00:00
|
|
|
db.MustExec("DELETE FROM maker.pit_file_ilk")
|
|
|
|
db.MustExec("DELETE FROM maker.pit_file_stability_fee")
|
2018-09-10 21:57:17 +00:00
|
|
|
db.MustExec("DELETE FROM maker.price_feeds")
|
|
|
|
db.MustExec("DELETE FROM maker.tend")
|
2018-11-08 17:14:52 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_flux")
|
|
|
|
db.MustExec("DELETE FROM maker.vat_fold")
|
2018-10-08 21:39:57 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_grab")
|
2018-10-10 16:56:06 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_heal")
|
2018-09-10 21:57:17 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_init")
|
2018-10-12 14:13:13 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_move")
|
2018-10-15 20:04:17 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_slip")
|
2018-10-04 19:46:04 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_toll")
|
2018-10-04 21:49:09 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vat_tune")
|
2018-11-08 17:14:52 +00:00
|
|
|
db.MustExec("DELETE FROM maker.vow_flog")
|
2018-02-13 16:31:57 +00:00
|
|
|
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
|
|
|
}
|
2018-05-05 20:25:54 +00:00
|
|
|
|
2018-08-07 20:17:29 +00:00
|
|
|
func NewTestNode() core.Node {
|
|
|
|
return core.Node{
|
|
|
|
GenesisBlock: "GENESIS",
|
|
|
|
NetworkID: 1,
|
|
|
|
ID: "b6f90c0fdd8ec9607aed8ee45c69322e47b7063f0bfb7a29c8ecafab24d0a22d24dd2329b5ee6ed4125a03cb14e57fd584e67f9e53e6c631055cbbd82f080845",
|
|
|
|
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTestBlock(blockNumber int64, repository repositories.BlockRepository) (blockId int64) {
|
|
|
|
blockId, err := repository.CreateOrUpdateBlock(core.Block{Number: blockNumber})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
return blockId
|
2018-05-05 20:25:54 +00:00
|
|
|
}
|