From 234fff83c52cfedd8d23d4d633c5b359a0263f04 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Thu, 31 Oct 2019 11:19:34 -0500 Subject: [PATCH] Use testing.toml and vulcanize_testing in tests - remove legacy references to infura.toml and vulcanize_private --- .travis.yml | 3 --- README.md | 6 ++--- environments/testing.toml | 2 +- integration_test/block_rewards_test.go | 8 +++--- integration_test/contract_test.go | 12 ++++----- integration_test/geth_blockchain_test.go | 4 +-- .../shared/getter/getter_test.go | 8 +++--- .../shared/helpers/test_helpers/database.go | 14 +++++----- test_config/test_config.go | 27 ------------------- 9 files changed, 27 insertions(+), 57 deletions(-) diff --git a/.travis.yml b/.travis.yml index d3b34c88..9c4c6b5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,6 @@ before_install: - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - sudo apt-get update && sudo apt-get install yarn -before_script: - - sudo -u postgres createdb vulcanize_private - - make migrate NAME=vulcanize_private script: - env GO111MODULE=on make test - env GO111MODULE=on make integrationtest diff --git a/README.md b/README.md index c9aad7fc..e7f62b4b 100644 --- a/README.md +++ b/README.md @@ -135,12 +135,12 @@ build and run custom transformers as Go plugins can be found ### Tests -- Replace the empty `ipcPath` in the `environments/infura.toml` with a path to a full node's eth_jsonrpc endpoint (e.g. local geth node ipc path or infura url) +- Replace the empty `ipcPath` in the `environments/testing.toml` with a path to a full node's eth_jsonrpc endpoint (e.g. local geth node ipc path or infura url) + - Note: must be mainnet - Note: integration tests require configuration with an archival node -- `createdb vulcanize_private` will create the test db -- `make migrate NAME=vulcanize_private` will run the db migrations - `make test` will run the unit tests and skip the integration tests - `make integrationtest` will run just the integration tests +- `make test` and `make integrationtest` setup a clean `vulcanize_testing` db ## Contributing diff --git a/environments/testing.toml b/environments/testing.toml index 64f9a642..891c1b8d 100644 --- a/environments/testing.toml +++ b/environments/testing.toml @@ -1,5 +1,5 @@ [database] - name = "vulcanize_private" + name = "vulcanize_testing" hostname = "localhost" port = 5432 diff --git a/integration_test/block_rewards_test.go b/integration_test/block_rewards_test.go index c2ef087b..80334546 100644 --- a/integration_test/block_rewards_test.go +++ b/integration_test/block_rewards_test.go @@ -32,9 +32,9 @@ import ( var _ = Describe("Rewards calculations", func() { It("calculates a block reward for a real block", func() { - rawRpcClient, err := rpc.Dial(test_config.InfuraClient.IPCPath) + rawRpcClient, err := rpc.Dial(test_config.TestClient.IPCPath) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, test_config.InfuraClient.IPCPath) + rpcClient := client.NewRpcClient(rawRpcClient, test_config.TestClient.IPCPath) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) node := node.MakeNode(rpcClient) @@ -46,9 +46,9 @@ var _ = Describe("Rewards calculations", func() { }) It("calculates an uncle reward for a real block", func() { - rawRpcClient, err := rpc.Dial(test_config.InfuraClient.IPCPath) + rawRpcClient, err := rpc.Dial(test_config.TestClient.IPCPath) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, test_config.InfuraClient.IPCPath) + rpcClient := client.NewRpcClient(rawRpcClient, test_config.TestClient.IPCPath) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) node := node.MakeNode(rpcClient) diff --git a/integration_test/contract_test.go b/integration_test/contract_test.go index 9abc1f6e..cc55606b 100644 --- a/integration_test/contract_test.go +++ b/integration_test/contract_test.go @@ -49,9 +49,9 @@ var _ = Describe("Reading contracts", func() { }, Index: 19, Data: "0x0000000000000000000000000000000000000000000000000c7d713b49da0000"} - rawRpcClient, err := rpc.Dial(test_config.InfuraClient.IPCPath) + rawRpcClient, err := rpc.Dial(test_config.TestClient.IPCPath) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, test_config.InfuraClient.IPCPath) + rpcClient := client.NewRpcClient(rawRpcClient, test_config.TestClient.IPCPath) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) node := node.MakeNode(rpcClient) @@ -67,9 +67,9 @@ var _ = Describe("Reading contracts", func() { }) It("returns and empty log array when no events for a given block / contract combo", func() { - rawRpcClient, err := rpc.Dial(test_config.InfuraClient.IPCPath) + rawRpcClient, err := rpc.Dial(test_config.TestClient.IPCPath) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, test_config.InfuraClient.IPCPath) + rpcClient := client.NewRpcClient(rawRpcClient, test_config.TestClient.IPCPath) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) node := node.MakeNode(rpcClient) @@ -85,9 +85,9 @@ var _ = Describe("Reading contracts", func() { Describe("Fetching Contract data", func() { It("returns the correct attribute for a real contract", func() { - rawRpcClient, err := rpc.Dial(test_config.InfuraClient.IPCPath) + rawRpcClient, err := rpc.Dial(test_config.TestClient.IPCPath) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, test_config.InfuraClient.IPCPath) + rpcClient := client.NewRpcClient(rawRpcClient, test_config.TestClient.IPCPath) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) node := node.MakeNode(rpcClient) diff --git a/integration_test/geth_blockchain_test.go b/integration_test/geth_blockchain_test.go index 27f7476f..dbb3bc53 100644 --- a/integration_test/geth_blockchain_test.go +++ b/integration_test/geth_blockchain_test.go @@ -37,9 +37,9 @@ var _ = Describe("Reading from the Geth blockchain", func() { var blockChain *eth.BlockChain BeforeEach(func() { - rawRpcClient, err := rpc.Dial(test_config.InfuraClient.IPCPath) + rawRpcClient, err := rpc.Dial(test_config.TestClient.IPCPath) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, test_config.InfuraClient.IPCPath) + rpcClient := client.NewRpcClient(rawRpcClient, test_config.TestClient.IPCPath) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) node := node.MakeNode(rpcClient) diff --git a/pkg/contract_watcher/shared/getter/getter_test.go b/pkg/contract_watcher/shared/getter/getter_test.go index e4e58c64..4af9a863 100644 --- a/pkg/contract_watcher/shared/getter/getter_test.go +++ b/pkg/contract_watcher/shared/getter/getter_test.go @@ -35,12 +35,12 @@ var _ = Describe("Interface Getter", func() { Describe("GetAbi", func() { It("Constructs and returns a custom abi based on results from supportsInterface calls", func() { expectedABI := `[` + constants.AddrChangeInterface + `,` + constants.NameChangeInterface + `,` + constants.ContentChangeInterface + `,` + constants.AbiChangeInterface + `,` + constants.PubkeyChangeInterface + `]` - con := test_config.InfuraClient - infuraIPC := con.IPCPath + con := test_config.TestClient + testIPC := con.IPCPath blockNumber := int64(6885696) - rawRpcClient, err := rpc.Dial(infuraIPC) + rawRpcClient, err := rpc.Dial(testIPC) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, infuraIPC) + rpcClient := client.NewRpcClient(rawRpcClient, testIPC) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) node := node.MakeNode(rpcClient) diff --git a/pkg/contract_watcher/shared/helpers/test_helpers/database.go b/pkg/contract_watcher/shared/helpers/test_helpers/database.go index 1988060e..37cb0af1 100644 --- a/pkg/contract_watcher/shared/helpers/test_helpers/database.go +++ b/pkg/contract_watcher/shared/helpers/test_helpers/database.go @@ -108,11 +108,11 @@ type Owner struct { } func SetupDBandBC() (*postgres.DB, core.BlockChain) { - con := test_config.InfuraClient - infuraIPC := con.IPCPath - rawRpcClient, err := rpc.Dial(infuraIPC) + con := test_config.TestClient + testIPC := con.IPCPath + rawRpcClient, err := rpc.Dial(testIPC) Expect(err).NotTo(HaveOccurred()) - rpcClient := client.NewRpcClient(rawRpcClient, infuraIPC) + rpcClient := client.NewRpcClient(rawRpcClient, testIPC) ethClient := ethclient.NewClient(rawRpcClient) blockChainClient := client.NewEthClient(ethClient) madeNode := node.MakeNode(rpcClient) @@ -121,7 +121,7 @@ func SetupDBandBC() (*postgres.DB, core.BlockChain) { db, err := postgres.NewDB(config.Database{ Hostname: "localhost", - Name: "vulcanize_private", + Name: "vulcanize_testing", Port: 5432, }, blockChain.Node()) Expect(err).NotTo(HaveOccurred()) @@ -132,7 +132,7 @@ func SetupDBandBC() (*postgres.DB, core.BlockChain) { func SetupTusdRepo(vulcanizeLogId *int64, wantedEvents, wantedMethods []string) (*postgres.DB, *contract.Contract) { db, err := postgres.NewDB(config.Database{ Hostname: "localhost", - Name: "vulcanize_private", + Name: "vulcanize_testing", Port: 5432, }, core.Node{}) Expect(err).NotTo(HaveOccurred()) @@ -178,7 +178,7 @@ func SetupTusdContract(wantedEvents, wantedMethods []string) *contract.Contract func SetupENSRepo(vulcanizeLogId *int64, wantedEvents, wantedMethods []string) (*postgres.DB, *contract.Contract) { db, err := postgres.NewDB(config.Database{ Hostname: "localhost", - Name: "vulcanize_private", + Name: "vulcanize_testing", Port: 5432, }, core.Node{}) Expect(err).NotTo(HaveOccurred()) diff --git a/test_config/test_config.go b/test_config/test_config.go index a9383bec..135df08c 100644 --- a/test_config/test_config.go +++ b/test_config/test_config.go @@ -32,13 +32,10 @@ import ( var TestConfig *viper.Viper var DBConfig config.Database var TestClient config.Client -var Infura *viper.Viper -var InfuraClient config.Client var ABIFilePath string func init() { setTestConfig() - setInfuraConfig() setABIPath() } @@ -75,30 +72,6 @@ func setTestConfig() { } } -func setInfuraConfig() { - Infura = viper.New() - Infura.SetConfigName("infura") - Infura.AddConfigPath("$GOPATH/src/github.com/vulcanize/vulcanizedb/environments/") - err := Infura.ReadInConfig() - if err != nil { - logrus.Fatal(err) - } - ipc := Infura.GetString("client.ipcpath") - - // If we don't have an ipc path in the config file, check the env variable - if ipc == "" { - Infura.BindEnv("url", "INFURA_URL") - ipc = Infura.GetString("url") - } - if ipc == "" { - logrus.Fatal(errors.New("infura.toml IPC path or $INFURA_URL env variable need to be set")) - } - - InfuraClient = config.Client{ - IPCPath: ipc, - } -} - func setABIPath() { gp := os.Getenv("GOPATH") ABIFilePath = gp + "/src/github.com/vulcanize/vulcanizedb/pkg/eth/testing/"