diff --git a/.gitignore b/.gitignore index 1be57ae4..0288013e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ Gododir/godobin-* test_data_dir/ vendor/ -config/environments/*.toml +pkg/config/environments/*.toml diff --git a/.travis.yml b/.travis.yml index 2f1c125b..8d2c4a07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,6 @@ before_script: - createdb vulcanize_private - psql vulcanize_private < migrations/schema.sql script: - - go test -v ./blockchain_listener ./core ./geth ./observers + - go test -v ./pkg/... notifications: email: false diff --git a/Gododir/main.go b/Gododir/main.go index caffb7d3..b0f80047 100644 --- a/Gododir/main.go +++ b/Gododir/main.go @@ -5,7 +5,7 @@ import ( "fmt" - "github.com/8thlight/vulcanizedb/config" + "github.com/8thlight/vulcanizedb/pkg/config" do "gopkg.in/godo.v2" ) diff --git a/README.md b/README.md index 4a0e22de..c346f756 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ The default location for Ethereum is: You can create configuration files for additional environments. * Among other things, it will require the IPC file path - * See `config/environments/private.toml` for an example + * See `pkg/config/environments/private.toml` for an example * You will need to do this if you want to run a node connecting to the public blockchain ## Running the Tests @@ -81,8 +81,8 @@ You can create configuration files for additional environments. In order to run the integration tests, you will need to run them against a real blockchain. 1. Run `./scripts/start_private_blockchain` as a separate process. -2. `go test ./...` +2. `go test ./...` to run all tests. ### Unit Tests -1. `go test ./core` +1. `go test ./pkg/...` diff --git a/cmd/run/main.go b/cmd/run/main.go index 57e3159e..489107d7 100644 --- a/cmd/run/main.go +++ b/cmd/run/main.go @@ -6,12 +6,12 @@ import ( "flag" - "github.com/8thlight/vulcanizedb/blockchain_listener" - "github.com/8thlight/vulcanizedb/config" - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/geth" - "github.com/8thlight/vulcanizedb/observers" - "github.com/8thlight/vulcanizedb/repositories" + "github.com/8thlight/vulcanizedb/pkg/blockchain_listener" + "github.com/8thlight/vulcanizedb/pkg/config" + "github.com/8thlight/vulcanizedb/pkg/core" + "github.com/8thlight/vulcanizedb/pkg/geth" + "github.com/8thlight/vulcanizedb/pkg/observers" + "github.com/8thlight/vulcanizedb/pkg/repositories" "github.com/jmoiron/sqlx" ) diff --git a/integration_test/geth_blockchain_test.go b/integration_test/geth_blockchain_test.go index 116527e4..a360bbeb 100644 --- a/integration_test/geth_blockchain_test.go +++ b/integration_test/geth_blockchain_test.go @@ -1,25 +1,15 @@ package integration_test import ( - "path" - "runtime" - - "github.com/8thlight/vulcanizedb/blockchain_listener" - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/fakes" - "github.com/8thlight/vulcanizedb/geth" + "github.com/8thlight/vulcanizedb/pkg/blockchain_listener" + "github.com/8thlight/vulcanizedb/pkg/config" + "github.com/8thlight/vulcanizedb/pkg/core" + "github.com/8thlight/vulcanizedb/pkg/fakes" + "github.com/8thlight/vulcanizedb/pkg/geth" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) -var ( - _, filename, _, _ = runtime.Caller(0) -) - -func RunTimePath() string { - return path.Join(path.Dir(filename), "../") -} - var _ = Describe("Reading from the Geth blockchain", func() { var listener blockchain_listener.BlockchainListener @@ -27,7 +17,8 @@ var _ = Describe("Reading from the Geth blockchain", func() { BeforeEach(func() { observer = fakes.NewFakeBlockchainObserver() - blockchain := geth.NewGethBlockchain(RunTimePath() + "/test_data_dir/geth.ipc") + cfg := config.NewConfig("private") + blockchain := geth.NewGethBlockchain(cfg.Client.IPCPath) observers := []core.BlockchainObserver{observer} listener = blockchain_listener.NewBlockchainListener(blockchain, observers) }) diff --git a/blockchain_listener/blockchain_listener.go b/pkg/blockchain_listener/blockchain_listener.go similarity index 94% rename from blockchain_listener/blockchain_listener.go rename to pkg/blockchain_listener/blockchain_listener.go index 73e505b8..cdd45b85 100644 --- a/blockchain_listener/blockchain_listener.go +++ b/pkg/blockchain_listener/blockchain_listener.go @@ -1,6 +1,6 @@ package blockchain_listener -import "github.com/8thlight/vulcanizedb/core" +import "github.com/8thlight/vulcanizedb/pkg/core" type BlockchainListener struct { inputBlocks chan core.Block diff --git a/blockchain_listener/listener_suite_test.go b/pkg/blockchain_listener/blockchain_listener_suite_test.go similarity index 100% rename from blockchain_listener/listener_suite_test.go rename to pkg/blockchain_listener/blockchain_listener_suite_test.go diff --git a/blockchain_listener/blockchain_listener_test.go b/pkg/blockchain_listener/blockchain_listener_test.go similarity index 93% rename from blockchain_listener/blockchain_listener_test.go rename to pkg/blockchain_listener/blockchain_listener_test.go index 9f55db94..0462518c 100644 --- a/blockchain_listener/blockchain_listener_test.go +++ b/pkg/blockchain_listener/blockchain_listener_test.go @@ -1,9 +1,9 @@ package blockchain_listener_test import ( - "github.com/8thlight/vulcanizedb/blockchain_listener" - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/fakes" + "github.com/8thlight/vulcanizedb/pkg/blockchain_listener" + "github.com/8thlight/vulcanizedb/pkg/core" + "github.com/8thlight/vulcanizedb/pkg/fakes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/config/client.go b/pkg/config/client.go similarity index 100% rename from config/client.go rename to pkg/config/client.go diff --git a/config/config.go b/pkg/config/config.go similarity index 83% rename from config/config.go rename to pkg/config/config.go index 0dc5b34e..74932df4 100644 --- a/config/config.go +++ b/pkg/config/config.go @@ -21,7 +21,7 @@ type Config struct { func NewConfig(environment string) Config { filenameWithExtension := fmt.Sprintf("%s.toml", environment) - absolutePath := filepath.Join(ProjectRoot(), "config", "environments", filenameWithExtension) + absolutePath := filepath.Join(ProjectRoot(), "pkg", "config", "environments", filenameWithExtension) config := parseConfigFile(absolutePath) config.Client.IPCPath = filepath.Join(ProjectRoot(), config.Client.IPCPath) return config @@ -29,7 +29,7 @@ func NewConfig(environment string) Config { func ProjectRoot() string { var _, filename, _, _ = runtime.Caller(0) - return path.Join(path.Dir(filename), "../") + return path.Join(path.Dir(filename), "..", "..") } func parseConfigFile(configfile string) Config { diff --git a/config/config_suite_test.go b/pkg/config/config_suite_test.go similarity index 100% rename from config/config_suite_test.go rename to pkg/config/config_suite_test.go diff --git a/config/config_test.go b/pkg/config/config_test.go similarity index 92% rename from config/config_test.go rename to pkg/config/config_test.go index c42d2bfa..c6236937 100644 --- a/config/config_test.go +++ b/pkg/config/config_test.go @@ -3,7 +3,7 @@ package config_test import ( "path/filepath" - "github.com/8thlight/vulcanizedb/config" + "github.com/8thlight/vulcanizedb/pkg/config" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/config/database.go b/pkg/config/database.go similarity index 100% rename from config/database.go rename to pkg/config/database.go diff --git a/config/environments/private.toml b/pkg/config/environments/private.toml similarity index 100% rename from config/environments/private.toml rename to pkg/config/environments/private.toml diff --git a/core/block.go b/pkg/core/block.go similarity index 100% rename from core/block.go rename to pkg/core/block.go diff --git a/core/blockchain.go b/pkg/core/blockchain.go similarity index 100% rename from core/blockchain.go rename to pkg/core/blockchain.go diff --git a/core/blockchain_observer.go b/pkg/core/blockchain_observer.go similarity index 100% rename from core/blockchain_observer.go rename to pkg/core/blockchain_observer.go diff --git a/core/core_suite_test.go b/pkg/core/core_suite_test.go similarity index 100% rename from core/core_suite_test.go rename to pkg/core/core_suite_test.go diff --git a/core/transaction.go b/pkg/core/transaction.go similarity index 100% rename from core/transaction.go rename to pkg/core/transaction.go diff --git a/fakes/blockchain.go b/pkg/fakes/blockchain.go similarity index 89% rename from fakes/blockchain.go rename to pkg/fakes/blockchain.go index bb1cddde..4e04aa53 100644 --- a/fakes/blockchain.go +++ b/pkg/fakes/blockchain.go @@ -1,6 +1,6 @@ package fakes -import "github.com/8thlight/vulcanizedb/core" +import "github.com/8thlight/vulcanizedb/pkg/core" type Blockchain struct { outputBlocks chan core.Block diff --git a/fakes/blockchain_observer.go b/pkg/fakes/blockchain_observer.go similarity index 91% rename from fakes/blockchain_observer.go rename to pkg/fakes/blockchain_observer.go index 8dd444c0..39353db6 100644 --- a/fakes/blockchain_observer.go +++ b/pkg/fakes/blockchain_observer.go @@ -1,6 +1,6 @@ package fakes -import "github.com/8thlight/vulcanizedb/core" +import "github.com/8thlight/vulcanizedb/pkg/core" type BlockchainObserver struct { CurrentBlocks []core.Block diff --git a/geth/geth_block_to_core_block.go b/pkg/geth/geth_block_to_core_block.go similarity index 97% rename from geth/geth_block_to_core_block.go rename to pkg/geth/geth_block_to_core_block.go index 58166075..7544e2bc 100644 --- a/geth/geth_block_to_core_block.go +++ b/pkg/geth/geth_block_to_core_block.go @@ -1,7 +1,7 @@ package geth import ( - "github.com/8thlight/vulcanizedb/core" + "github.com/8thlight/vulcanizedb/pkg/core" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" diff --git a/geth/geth_block_to_core_block_test.go b/pkg/geth/geth_block_to_core_block_test.go similarity index 98% rename from geth/geth_block_to_core_block_test.go rename to pkg/geth/geth_block_to_core_block_test.go index 444f03e6..1b4adf73 100644 --- a/geth/geth_block_to_core_block_test.go +++ b/pkg/geth/geth_block_to_core_block_test.go @@ -3,7 +3,7 @@ package geth_test import ( "math/big" - "github.com/8thlight/vulcanizedb/geth" + "github.com/8thlight/vulcanizedb/pkg/geth" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" diff --git a/geth/geth_blockchain.go b/pkg/geth/geth_blockchain.go similarity index 96% rename from geth/geth_blockchain.go rename to pkg/geth/geth_blockchain.go index 9323d2f7..95e72c82 100644 --- a/geth/geth_blockchain.go +++ b/pkg/geth/geth_blockchain.go @@ -3,7 +3,7 @@ package geth import ( "fmt" - "github.com/8thlight/vulcanizedb/core" + "github.com/8thlight/vulcanizedb/pkg/core" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" diff --git a/geth/geth_suite_test.go b/pkg/geth/geth_suite_test.go similarity index 100% rename from geth/geth_suite_test.go rename to pkg/geth/geth_suite_test.go diff --git a/observers/blockchain_db_observer.go b/pkg/observers/blockchain_db_observer.go similarity index 79% rename from observers/blockchain_db_observer.go rename to pkg/observers/blockchain_db_observer.go index 504a0367..727f26d4 100644 --- a/observers/blockchain_db_observer.go +++ b/pkg/observers/blockchain_db_observer.go @@ -1,8 +1,8 @@ package observers import ( - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/repositories" + "github.com/8thlight/vulcanizedb/pkg/core" + "github.com/8thlight/vulcanizedb/pkg/repositories" ) type BlockchainDbObserver struct { diff --git a/observers/blockchain_db_observer_test.go b/pkg/observers/blockchain_db_observer_test.go similarity index 84% rename from observers/blockchain_db_observer_test.go rename to pkg/observers/blockchain_db_observer_test.go index 0f636a15..0f510095 100644 --- a/observers/blockchain_db_observer_test.go +++ b/pkg/observers/blockchain_db_observer_test.go @@ -1,9 +1,9 @@ package observers_test import ( - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/observers" - "github.com/8thlight/vulcanizedb/repositories" + "github.com/8thlight/vulcanizedb/pkg/core" + "github.com/8thlight/vulcanizedb/pkg/observers" + "github.com/8thlight/vulcanizedb/pkg/repositories" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) diff --git a/observers/blockchain_logging_observer.go b/pkg/observers/blockchain_logging_observer.go similarity index 90% rename from observers/blockchain_logging_observer.go rename to pkg/observers/blockchain_logging_observer.go index 15397caa..529b8069 100644 --- a/observers/blockchain_logging_observer.go +++ b/pkg/observers/blockchain_logging_observer.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/8thlight/vulcanizedb/core" + "github.com/8thlight/vulcanizedb/pkg/core" ) type BlockchainLoggingObserver struct{} diff --git a/observers/observers_suite_test.go b/pkg/observers/observers_suite_test.go similarity index 100% rename from observers/observers_suite_test.go rename to pkg/observers/observers_suite_test.go diff --git a/repositories/in_memory.go b/pkg/repositories/in_memory.go similarity index 91% rename from repositories/in_memory.go rename to pkg/repositories/in_memory.go index a28ead8b..15fdaf4d 100644 --- a/repositories/in_memory.go +++ b/pkg/repositories/in_memory.go @@ -1,7 +1,7 @@ package repositories import ( - "github.com/8thlight/vulcanizedb/core" + "github.com/8thlight/vulcanizedb/pkg/core" ) type InMemory struct { diff --git a/repositories/in_memory_test.go b/pkg/repositories/in_memory_test.go similarity index 97% rename from repositories/in_memory_test.go rename to pkg/repositories/in_memory_test.go index 7d4bcb96..f07c8c82 100644 --- a/repositories/in_memory_test.go +++ b/pkg/repositories/in_memory_test.go @@ -1,8 +1,8 @@ package repositories_test import ( - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/repositories" + "github.com/8thlight/vulcanizedb/pkg/core" + "github.com/8thlight/vulcanizedb/pkg/repositories" _ "github.com/lib/pq" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" diff --git a/repositories/postgres.go b/pkg/repositories/postgres.go similarity index 98% rename from repositories/postgres.go rename to pkg/repositories/postgres.go index d976f452..fc3cbde9 100644 --- a/repositories/postgres.go +++ b/pkg/repositories/postgres.go @@ -3,7 +3,7 @@ package repositories import ( "database/sql" - "github.com/8thlight/vulcanizedb/core" + "github.com/8thlight/vulcanizedb/pkg/core" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" ) diff --git a/repositories/postgres_test.go b/pkg/repositories/postgres_test.go similarity index 96% rename from repositories/postgres_test.go rename to pkg/repositories/postgres_test.go index 7449e767..de7ab9a6 100644 --- a/repositories/postgres_test.go +++ b/pkg/repositories/postgres_test.go @@ -1,9 +1,9 @@ package repositories_test import ( - "github.com/8thlight/vulcanizedb/config" - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/repositories" + "github.com/8thlight/vulcanizedb/pkg/config" + "github.com/8thlight/vulcanizedb/pkg/core" + "github.com/8thlight/vulcanizedb/pkg/repositories" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" . "github.com/onsi/ginkgo" diff --git a/repositories/repositories_suite_test.go b/pkg/repositories/repositories_suite_test.go similarity index 100% rename from repositories/repositories_suite_test.go rename to pkg/repositories/repositories_suite_test.go diff --git a/repositories/repository.go b/pkg/repositories/repository.go similarity index 62% rename from repositories/repository.go rename to pkg/repositories/repository.go index 16aa4055..15fd0a32 100644 --- a/repositories/repository.go +++ b/pkg/repositories/repository.go @@ -1,6 +1,6 @@ package repositories -import "github.com/8thlight/vulcanizedb/core" +import "github.com/8thlight/vulcanizedb/pkg/core" type Repository interface { CreateBlock(block core.Block)