Refactoring
* Move flip kick files pkg/transformers/flip_kick * Consolidate test database setup * Pull ganache ipcPath from config * Update README to include info about using a Ganache chain
This commit is contained in:
parent
c617cd9c9d
commit
b37324bf3d
@ -18,7 +18,7 @@ before_install:
|
||||
before_script:
|
||||
- sudo -u postgres createdb vulcanize_private
|
||||
- make migrate NAME=vulcanize_private
|
||||
- bash ./libraries/maker/start_test_chain.sh
|
||||
- bash ./pkg/transformers/start_test_chain.sh
|
||||
|
||||
script:
|
||||
- make test
|
||||
@ -27,4 +27,4 @@ notifications:
|
||||
email: false
|
||||
|
||||
after_script:
|
||||
- bash ./libraries/maker/stop_test_chain.sh
|
||||
- bash ./pkg/transformers/stop_test_chain.sh
|
||||
|
@ -51,7 +51,8 @@ Vulcanize DB is a set of tools that make it easier for developers to write appli
|
||||
- Linux: `$HOME/.ethereum/geth/chaindata`
|
||||
- `levelDbPath` is irrelevant (and `coldImport` is currently unavailable) if only running parity.
|
||||
|
||||
- See `environments/infura.toml` to configure commands to run against infura, if a local node is unavailable
|
||||
- See `environments/infura.toml` to configure commands to run against infura, if a local node is unavailable.
|
||||
- Copy `environments/local.toml.example` to `environments/local.toml` to configure commands to run against a local node such as [Ganache](https://truffleframework.com/ganache) or [ganache-cli](https://github.com/trufflesuite/ganache-clihttps://github.com/trufflesuite/ganache-cli).
|
||||
|
||||
## Start syncing with postgres
|
||||
Syncs VulcanizeDB with the configured Ethereum node, populating blocks, transactions, receipts, and logs.
|
||||
|
@ -15,17 +15,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
|
||||
vRpc "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
||||
"log"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers"
|
||||
)
|
||||
|
||||
// backfillAuctionLogsCmd represents the backfillAuctionLogs command
|
||||
@ -67,7 +69,7 @@ func backfillAuctionLogs() {
|
||||
Blockchain: blockChain,
|
||||
}
|
||||
|
||||
watcher.AddTransformers(every_block.TransformerInitializers())
|
||||
watcher.AddTransformers(transformers.TransformerInitializers())
|
||||
watcher.Execute()
|
||||
}
|
||||
|
||||
|
@ -4,4 +4,4 @@ hostname = "localhost"
|
||||
port = 5432
|
||||
|
||||
[client]
|
||||
ipcPath = "http://127.0.0.1:7546"
|
||||
ipcPath = "http://127.0.0.1:7545"
|
||||
|
@ -4,4 +4,4 @@ hostname = "localhost"
|
||||
port = 5432
|
||||
|
||||
[client]
|
||||
ipcPath = "test_data_dir/geth.ipc"
|
||||
ipcPath = "http://127.0.0.1:7545"
|
@ -24,10 +24,10 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/test_helpers"
|
||||
"github.com/vulcanize/vulcanizedb/examples/erc20_test_helpers"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
)
|
||||
|
||||
func setLastBlockOnChain(blockChain *fakes.MockBlockChain, blockNumber int64) {
|
||||
@ -48,7 +48,9 @@ var _ = Describe("Everyblock transformers", func() {
|
||||
blockChain = fakes.NewMockBlockChain()
|
||||
blockNumber = erc20_watcher.DaiConfig.FirstBlock
|
||||
lastBlockNumber := blockNumber + 1
|
||||
db = test_helpers.CreateNewDatabase()
|
||||
node := test_config.NewTestNode()
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
setLastBlockOnChain(blockChain, lastBlockNumber)
|
||||
|
||||
blockRepository := repositories.NewBlockRepository(db)
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
"math/rand"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/test_helpers"
|
||||
"github.com/vulcanize/vulcanizedb/examples/erc20_test_helpers"
|
||||
)
|
||||
|
||||
@ -37,14 +36,13 @@ var _ = Describe("ERC20 Token Repository", func() {
|
||||
testAddress := "abc"
|
||||
|
||||
BeforeEach(func() {
|
||||
db = test_helpers.CreateNewDatabase()
|
||||
node := test_config.NewTestNode()
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repository = every_block.TokenSupplyRepository{DB: db}
|
||||
_, err := db.Query(`DELETE FROM token_supply`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
blockRepository = *repositories.NewBlockRepository(db)
|
||||
blockNumber = rand.Int63()
|
||||
blockId = test_helpers.CreateBlock(blockNumber, blockRepository)
|
||||
blockId = test_config.NewTestBlock(blockNumber, blockRepository)
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -103,7 +101,7 @@ var _ = Describe("ERC20 Token Repository", func() {
|
||||
|
||||
//create another block with the same number on node2
|
||||
node2BlockRepo = repositories.NewBlockRepository(node2DB)
|
||||
node2BlockId = test_helpers.CreateBlock(blockNumber, *node2BlockRepo)
|
||||
node2BlockId = test_config.NewTestBlock(blockNumber, *node2BlockRepo)
|
||||
|
||||
tokenSupply = supplyModel(blockNumber, "abc", "100")
|
||||
node2TokenSupplyRepo = every_block.TokenSupplyRepository{DB: node2DB}
|
||||
@ -140,7 +138,7 @@ var _ = Describe("ERC20 Token Repository", func() {
|
||||
createTokenSupplyFor(repository, blockNumber)
|
||||
|
||||
newBlockNumber := blockNumber + 1
|
||||
test_helpers.CreateBlock(newBlockNumber, blockRepository)
|
||||
test_config.NewTestBlock(newBlockNumber, blockRepository)
|
||||
blocks, err := repository.MissingBlocks(blockNumber, newBlockNumber)
|
||||
|
||||
Expect(blocks).To(ConsistOf(newBlockNumber))
|
||||
@ -149,7 +147,7 @@ var _ = Describe("ERC20 Token Repository", func() {
|
||||
|
||||
It("only returns blocks within the given range", func() {
|
||||
newBlockNumber := blockNumber + 1
|
||||
test_helpers.CreateBlock(newBlockNumber, blockRepository)
|
||||
test_config.NewTestBlock(newBlockNumber, blockRepository)
|
||||
blocks, err := repository.MissingBlocks(blockNumber, blockNumber)
|
||||
|
||||
Expect(blocks).NotTo(ConsistOf(newBlockNumber))
|
||||
@ -204,5 +202,5 @@ func createDbForAnotherNode() *postgres.DB {
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
|
||||
return test_config.NewTestDBWithoutDeletingRecords(anotherNode)
|
||||
return test_config.NewTestDB(anotherNode)
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
package every_block_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestEveryBlock(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "EveryBlock Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
})
|
@ -76,6 +76,7 @@ var _ = Describe("Postgres DB", func() {
|
||||
}
|
||||
node := core.Node{GenesisBlock: "GENESIS", NetworkID: 1, ID: "x123", ClientName: "geth"}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
blocksRepository := repositories.NewBlockRepository(db)
|
||||
|
||||
_, err1 := blocksRepository.CreateOrUpdateBlock(badBlock)
|
||||
|
@ -26,6 +26,7 @@ var _ = Describe("Saving blocks", func() {
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
blockRepository = repositories.NewBlockRepository(db)
|
||||
|
||||
})
|
||||
@ -42,6 +43,7 @@ var _ = Describe("Saving blocks", func() {
|
||||
ClientName: "Geth",
|
||||
}
|
||||
dbTwo := test_config.NewTestDB(nodeTwo)
|
||||
test_config.CleanTestDB(dbTwo)
|
||||
repositoryTwo := repositories.NewBlockRepository(dbTwo)
|
||||
|
||||
_, err := repositoryTwo.GetBlock(123)
|
||||
@ -168,6 +170,7 @@ var _ = Describe("Saving blocks", func() {
|
||||
NetworkID: 1,
|
||||
}
|
||||
dbTwo := test_config.NewTestDB(nodeTwo)
|
||||
test_config.CleanTestDB(dbTwo)
|
||||
repositoryTwo := repositories.NewBlockRepository(dbTwo)
|
||||
|
||||
blockRepository.CreateOrUpdateBlock(blockOne)
|
||||
|
@ -25,6 +25,7 @@ var _ = Describe("Creating contracts", func() {
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
contractRepository = repositories.ContractRepository{DB: db}
|
||||
})
|
||||
|
||||
|
@ -17,6 +17,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("adds a header", func() {
|
||||
node := core.Node{}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
header := core.Header{
|
||||
BlockNumber: 100,
|
||||
@ -38,6 +39,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("adds node data to header", func() {
|
||||
node := core.Node{ID: "EthNodeFingerprint"}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
header := core.Header{BlockNumber: 100}
|
||||
|
||||
@ -57,6 +59,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("does not duplicate headers", func() {
|
||||
node := core.Node{}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
header := core.Header{
|
||||
BlockNumber: 100,
|
||||
@ -79,6 +82,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("replaces header if hash is different", func() {
|
||||
node := core.Node{}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
header := core.Header{
|
||||
BlockNumber: 100,
|
||||
@ -106,6 +110,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("does not replace header if node fingerprint is different", func() {
|
||||
node := core.Node{ID: "Fingerprint"}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
header := core.Header{
|
||||
BlockNumber: 100,
|
||||
@ -176,6 +181,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("returns header if it exists", func() {
|
||||
node := core.Node{}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
header := core.Header{
|
||||
BlockNumber: 100,
|
||||
@ -194,6 +200,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("does not return header for a different node fingerprint", func() {
|
||||
node := core.Node{}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
header := core.Header{
|
||||
BlockNumber: 100,
|
||||
@ -218,6 +225,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("returns block numbers for headers not in the database", func() {
|
||||
node := core.Node{}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
repo.CreateOrUpdateHeader(core.Header{BlockNumber: 1})
|
||||
repo.CreateOrUpdateHeader(core.Header{BlockNumber: 3})
|
||||
@ -231,6 +239,7 @@ var _ = Describe("Block header repository", func() {
|
||||
It("does not count headers created by a different node fingerprint", func() {
|
||||
node := core.Node{ID: "NodeFingerprint"}
|
||||
db := test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
repo := repositories.NewHeaderRepository(db)
|
||||
repo.CreateOrUpdateHeader(core.Header{BlockNumber: 1})
|
||||
repo.CreateOrUpdateHeader(core.Header{BlockNumber: 3})
|
||||
|
@ -23,6 +23,7 @@ var _ = Describe("Log Filters Repository", func() {
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
filterRepository = repositories.FilterRepository{DB: db}
|
||||
})
|
||||
|
||||
|
@ -28,6 +28,7 @@ var _ = Describe("Logs Repository", func() {
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
blockRepository = repositories.NewBlockRepository(db)
|
||||
logsRepository = repositories.LogRepository{DB: db}
|
||||
receiptRepository = repositories.ReceiptRepository{DB: db}
|
||||
|
@ -24,6 +24,7 @@ var _ = Describe("Receipts Repository", func() {
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
blockRepository = repositories.NewBlockRepository(db)
|
||||
logRepository = repositories.LogRepository{DB: db}
|
||||
receiptRepository = repositories.ReceiptRepository{DB: db}
|
||||
|
@ -21,6 +21,7 @@ var _ = Describe("Watched Events Repository", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
db = test_config.NewTestDB(core.Node{})
|
||||
test_config.CleanTestDB(db)
|
||||
blocksRepository = repositories.NewBlockRepository(db)
|
||||
filterRepository = repositories.FilterRepository{DB: db}
|
||||
logRepository = repositories.LogRepository{DB: db}
|
||||
|
@ -1,46 +0,0 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package test_helpers
|
||||
|
||||
import (
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
)
|
||||
|
||||
func CreateNewDatabase() *postgres.DB {
|
||||
var node core.Node
|
||||
node = core.Node{
|
||||
GenesisBlock: "GENESIS",
|
||||
NetworkID: 1,
|
||||
ID: "b6f90c0fdd8ec9607aed8ee45c69322e47b7063f0bfb7a29c8ecafab24d0a22d24dd2329b5ee6ed4125a03cb14e57fd584e67f9e53e6c631055cbbd82f080845",
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
db := test_config.NewTestDB(node)
|
||||
|
||||
_, err := db.Exec(`DELETE FROM logs`)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
func CreateBlock(blockNumber int64, repository repositories.BlockRepository) (blockId int64) {
|
||||
blockId, err := repository.CreateOrUpdateBlock(core.Block{Number: blockNumber})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
return blockId
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block
|
||||
package flip_kick
|
||||
|
||||
type TransformerConfig struct {
|
||||
ContractAddress string
|
File diff suppressed because one or more lines are too long
@ -12,17 +12,19 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block
|
||||
package flip_kick
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"strings"
|
||||
"time"
|
||||
"math/big"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Converter interface {
|
||||
@ -69,7 +71,7 @@ func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error)
|
||||
end := time.Unix(endValue, 0)
|
||||
eraValue := convertNilToZeroTimeValue(flipKick.Era)
|
||||
era := time.Unix(eraValue, 0)
|
||||
lad := strings.ToLower(flipKick.Lad.String())
|
||||
lad := strings.ToLower(flipKick.Lad.String())
|
||||
tab := convertNilToEmptyString(flipKick.Tab.String())
|
||||
|
||||
return FlipKickModel{
|
@ -12,24 +12,25 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block_test
|
||||
package flip_kick_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/test_data"
|
||||
"time"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"math/big"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
)
|
||||
|
||||
var _ = Describe("FlipKickEntity Converter", func() {
|
||||
It("converts an Eth Log to and Entity", func() {
|
||||
converter := every_block.FlipKickConverter{}
|
||||
entity, err := converter.ToEntity(test_data.TemporaryFlipAddress, every_block.FlipperABI, test_data.EthFlipKickLog)
|
||||
converter := flip_kick.FlipKickConverter{}
|
||||
entity, err := converter.ToEntity(test_data.TemporaryFlipAddress, flip_kick.FlipperABI, test_data.EthFlipKickLog)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(entity.Id).To(Equal(test_data.FlipKickEntity.Id))
|
||||
@ -47,14 +48,14 @@ var _ = Describe("FlipKickEntity Converter", func() {
|
||||
})
|
||||
|
||||
It("returns an error if converting log to entity fails", func() {
|
||||
converter := every_block.FlipKickConverter{}
|
||||
converter := flip_kick.FlipKickConverter{}
|
||||
_, err := converter.ToEntity(test_data.TemporaryFlipAddress, "error abi", test_data.EthFlipKickLog)
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("converts and Entity to a Model", func() {
|
||||
converter := every_block.FlipKickConverter{}
|
||||
converter := flip_kick.FlipKickConverter{}
|
||||
model, err := converter.ToModel(test_data.FlipKickEntity)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(model).To(Equal(test_data.FlipKickModel))
|
||||
@ -65,8 +66,8 @@ var _ = Describe("FlipKickEntity Converter", func() {
|
||||
emptyByteArrayHex := "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
emptyString := ""
|
||||
emptyTime := time.Unix(0, 0)
|
||||
converter := every_block.FlipKickConverter{}
|
||||
emptyEntity := every_block.FlipKickEntity{
|
||||
converter := flip_kick.FlipKickConverter{}
|
||||
emptyEntity := flip_kick.FlipKickEntity{
|
||||
Id: big.NewInt(1),
|
||||
Mom: common.Address{},
|
||||
Vat: common.Address{},
|
||||
@ -99,8 +100,8 @@ var _ = Describe("FlipKickEntity Converter", func() {
|
||||
})
|
||||
|
||||
It("returns an error of the flip kick event id is nil", func() {
|
||||
converter := every_block.FlipKickConverter{}
|
||||
emptyEntity := every_block.FlipKickEntity{}
|
||||
converter := flip_kick.FlipKickConverter{}
|
||||
emptyEntity := flip_kick.FlipKickEntity{}
|
||||
_, err := converter.ToModel(emptyEntity)
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
@ -12,12 +12,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block
|
||||
package flip_kick
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type FlipKickEntity struct {
|
33
pkg/transformers/flip_kick/every_block_suite_test.go
Normal file
33
pkg/transformers/flip_kick/every_block_suite_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package flip_kick
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestEveryBlock(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "EveryBlock Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
})
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block
|
||||
package flip_kick
|
||||
|
||||
import (
|
||||
"math/big"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block_test
|
||||
package flip_kick_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
@ -22,18 +22,18 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
)
|
||||
|
||||
var _ = Describe("Fetcher", func() {
|
||||
Describe("FetchLogs", func() {
|
||||
var blockChain *fakes.MockBlockChain
|
||||
var fetcher every_block.Fetcher
|
||||
var fetcher flip_kick.Fetcher
|
||||
|
||||
BeforeEach(func() {
|
||||
blockChain = fakes.NewMockBlockChain()
|
||||
fetcher = every_block.Fetcher{Blockchain: blockChain}
|
||||
fetcher = flip_kick.Fetcher{Blockchain: blockChain}
|
||||
})
|
||||
|
||||
It("fetches logs based on the given query", func() {
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block_test
|
||||
package flip_kick_test
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
@ -21,19 +21,18 @@ import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
|
||||
rpc2 "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
)
|
||||
|
||||
var _ = Describe("Integration tests", func() {
|
||||
|
||||
It("Fetches FlipKickEntity event logs from a local test chain", func() {
|
||||
ipcPath := "http://127.0.0.1:7545"
|
||||
ipcPath := test_config.TestClient.IPCPath
|
||||
|
||||
rawRpcClient, err := rpc.Dial(ipcPath)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -44,8 +43,8 @@ var _ = Describe("Integration tests", func() {
|
||||
realNode := node.MakeNode(rpcClient)
|
||||
transactionConverter := rpc2.NewRpcTransactionConverter(ethClient)
|
||||
realBlockChain := geth.NewBlockChain(blockChainClient, realNode, transactionConverter)
|
||||
realFetcher := every_block.NewFetcher(realBlockChain)
|
||||
topic0 := common.HexToHash(every_block.FlipKickSignature)
|
||||
realFetcher := flip_kick.NewFetcher(realBlockChain)
|
||||
topic0 := common.HexToHash(flip_kick.FlipKickSignature)
|
||||
topics := [][]common.Hash{{topic0}}
|
||||
|
||||
result, err := realFetcher.FetchLogs(test_data.TemporaryFlipAddress, topics, int64(10))
|
||||
@ -62,11 +61,11 @@ var _ = Describe("Integration tests", func() {
|
||||
|
||||
It("unpacks an event log", func() {
|
||||
address := common.HexToAddress(test_data.TemporaryFlipAddress)
|
||||
abi, err := geth.ParseAbi(every_block.FlipperABI)
|
||||
abi, err := geth.ParseAbi(flip_kick.FlipperABI)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
contract := bind.NewBoundContract(address, abi, nil, nil, nil)
|
||||
entity := &every_block.FlipKickEntity{}
|
||||
entity := &flip_kick.FlipKickEntity{}
|
||||
|
||||
var eventLog = test_data.EthFlipKickLog
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block
|
||||
package flip_kick
|
||||
|
||||
import "time"
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block
|
||||
package flip_kick
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block_test
|
||||
package flip_kick_test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
@ -21,25 +21,26 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/test_helpers"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
)
|
||||
|
||||
var _ = Describe("FlipKick Repository", func() {
|
||||
var db *postgres.DB
|
||||
var flipKickRepository every_block.FlipKickRepository
|
||||
var flipKickRepository flip_kick.FlipKickRepository
|
||||
var headerId int64
|
||||
var blockNumber int64
|
||||
var flipKick = test_data.FlipKickModel
|
||||
|
||||
BeforeEach(func() {
|
||||
db = test_helpers.CreateNewDatabase()
|
||||
flipKickRepository = every_block.FlipKickRepository{DB: db}
|
||||
node := test_config.NewTestNode()
|
||||
db = test_config.NewTestDB(node)
|
||||
test_config.CleanTestDB(db)
|
||||
flipKickRepository = flip_kick.FlipKickRepository{DB: db}
|
||||
blockNumber = rand.Int63()
|
||||
headerId = createHeader(db, blockNumber)
|
||||
|
||||
@ -102,7 +103,7 @@ var _ = Describe("FlipKick Repository", func() {
|
||||
|
||||
Describe("When there are multiple nodes", func() {
|
||||
var db2 *postgres.DB
|
||||
var flipKickRepository2 every_block.FlipKickRepository
|
||||
var flipKickRepository2 flip_kick.FlipKickRepository
|
||||
var headerId2 int64
|
||||
|
||||
BeforeEach(func() {
|
||||
@ -113,8 +114,8 @@ var _ = Describe("FlipKick Repository", func() {
|
||||
ID: "node2",
|
||||
ClientName: "Geth/v1.7.2-stable-1db4ecdc/darwin-amd64/go1.9",
|
||||
}
|
||||
db2 = test_config.NewTestDBWithoutDeletingRecords(node2)
|
||||
flipKickRepository2 = every_block.FlipKickRepository{DB: db2}
|
||||
db2 = test_config.NewTestDB(node2)
|
||||
flipKickRepository2 = flip_kick.FlipKickRepository{DB: db2}
|
||||
headerId2 = createHeader(db2, blockNumber)
|
||||
|
||||
_, err := db2.Exec(`DELETE from maker.flip_kick;`)
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block
|
||||
package flip_kick
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -55,11 +55,11 @@ func (fkt *FlipKickTransformer) SetConfig(config TransformerConfig) {
|
||||
}
|
||||
|
||||
const (
|
||||
FetcherError = "Error fetching FlipKick log events for block number %d: %s"
|
||||
FetcherError = "Error fetching FlipKick log events for block number %d: %s"
|
||||
LogToEntityError = "Error converting eth log to FlipKick entity for block number %d: %s"
|
||||
EntityToModelError = "Error converting eth log to FlipKick entity for block number %d: %s"
|
||||
RepositoryError = "Error creating flip_kick record for block number %d: %s"
|
||||
TransformerError = "There has been %d error(s) transforming FlipKick event logs, see the logs for more details."
|
||||
EntityToModelError = "Error converting eth log to FlipKick entity for block number %d: %s"
|
||||
RepositoryError = "Error creating flip_kick record for block number %d: %s"
|
||||
TransformerError = "There has been %d error(s) transforming FlipKick event logs, see the logs for more details."
|
||||
)
|
||||
|
||||
type transformerError struct {
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package every_block_test
|
||||
package flip_kick_test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
@ -22,18 +22,18 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
)
|
||||
|
||||
var _ = Describe("FlipKick Transformer", func() {
|
||||
var transformer every_block.FlipKickTransformer
|
||||
var transformer flip_kick.FlipKickTransformer
|
||||
var fetcher test_data.MockLogFetcher
|
||||
var converter test_data.MockFlipKickConverter
|
||||
var repository test_data.MockFlipKickRepository
|
||||
var testConfig every_block.TransformerConfig
|
||||
var testConfig flip_kick.TransformerConfig
|
||||
var blockNumber int64
|
||||
var headerId int64
|
||||
var headers []core.Header
|
||||
@ -43,17 +43,17 @@ var _ = Describe("FlipKick Transformer", func() {
|
||||
fetcher = test_data.MockLogFetcher{}
|
||||
converter = test_data.MockFlipKickConverter{}
|
||||
repository = test_data.MockFlipKickRepository{}
|
||||
transformer = every_block.FlipKickTransformer{
|
||||
transformer = flip_kick.FlipKickTransformer{
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}
|
||||
|
||||
startingBlockNumber := rand.Int63()
|
||||
testConfig = every_block.TransformerConfig{
|
||||
testConfig = flip_kick.TransformerConfig{
|
||||
ContractAddress: "0x12345",
|
||||
ContractAbi: "test abi",
|
||||
Topics: []string{every_block.FlipKickSignature},
|
||||
Topics: []string{flip_kick.FlipKickSignature},
|
||||
StartingBlockNumber: startingBlockNumber,
|
||||
EndingBlockNumber: startingBlockNumber + 5,
|
||||
}
|
||||
@ -75,7 +75,7 @@ var _ = Describe("FlipKick Transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs with the configured contract and topic(s) for each block", func() {
|
||||
expectedTopics := [][]common.Hash{{common.HexToHash(every_block.FlipKickSignature)}}
|
||||
expectedTopics := [][]common.Hash{{common.HexToHash(flip_kick.FlipKickSignature)}}
|
||||
|
||||
err := transformer.Execute()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -100,7 +100,7 @@ var _ = Describe("FlipKick Transformer", func() {
|
||||
Expect(converter.ConverterContract).To(Equal(testConfig.ContractAddress))
|
||||
Expect(converter.ConverterAbi).To(Equal(testConfig.ContractAbi))
|
||||
Expect(converter.LogsToConvert).To(Equal(logs))
|
||||
Expect(converter.EntitiesToConvert).To(Equal([]every_block.FlipKickEntity{test_data.FlipKickEntity}))
|
||||
Expect(converter.EntitiesToConvert).To(Equal([]flip_kick.FlipKickEntity{test_data.FlipKickEntity}))
|
||||
})
|
||||
|
||||
It("returns an error if converting the geth log fails", func() {
|
||||
@ -115,7 +115,7 @@ var _ = Describe("FlipKick Transformer", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(repository.HeaderIds).To(Equal([]int64{headerId}))
|
||||
Expect(repository.FlipKicksCreated).To(Equal([]every_block.FlipKickModel{test_data.FlipKickModel}))
|
||||
Expect(repository.FlipKicksCreated).To(Equal([]flip_kick.FlipKickModel{test_data.FlipKickModel}))
|
||||
})
|
||||
|
||||
It("returns an error if persisting a record fails", func() {
|
@ -2,7 +2,7 @@
|
||||
|
||||
MNEMONIC_PHRASE="whisper ordinary mystery awesome wood fox auction february blind volcano spare soft"
|
||||
PORT=7545
|
||||
DATABASE_PATH=libraries/maker/test_data/test_chain/
|
||||
DATABASE_PATH=pkg/transformers/test_data/test_chain/
|
||||
echo Starting ganache chain on port $PORT...
|
||||
|
||||
ganache-cli --port $PORT \
|
@ -20,7 +20,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"math/big"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -51,7 +51,7 @@ var tab, _ = new(big.Int).SetString(tabString, 10)
|
||||
|
||||
var EthFlipKickLog = types.Log{
|
||||
Address: common.HexToAddress(TemporaryFlipAddress),
|
||||
Topics: []common.Hash{common.HexToHash(every_block.FlipKickSignature)},
|
||||
Topics: []common.Hash{common.HexToHash(flip_kick.FlipKickSignature)},
|
||||
Data: hexutil.MustDecode(TemporaryFlipKickData),
|
||||
BlockNumber: uint64(TempBlockNumber),
|
||||
TxHash: common.HexToHash(TemporaryFlipKickTransaction),
|
||||
@ -61,7 +61,7 @@ var EthFlipKickLog = types.Log{
|
||||
Removed: false,
|
||||
}
|
||||
|
||||
var FlipKickEntity = every_block.FlipKickEntity{
|
||||
var FlipKickEntity = flip_kick.FlipKickEntity{
|
||||
Id: id,
|
||||
Mom: common.HexToAddress(mom),
|
||||
Vat: common.HexToAddress(vat),
|
||||
@ -76,7 +76,7 @@ var FlipKickEntity = every_block.FlipKickEntity{
|
||||
Tab: tab,
|
||||
}
|
||||
|
||||
var FlipKickModel = every_block.FlipKickModel{
|
||||
var FlipKickModel = flip_kick.FlipKickModel{
|
||||
Id: idString,
|
||||
Mom: mom,
|
||||
Vat: vat,
|
||||
@ -94,5 +94,5 @@ var FlipKickModel = every_block.FlipKickModel{
|
||||
type FlipKickDBRow struct {
|
||||
DbID int64 `db:"db_id"`
|
||||
HeaderId int64 `db:"header_id"`
|
||||
every_block.FlipKickModel
|
||||
flip_kick.FlipKickModel
|
||||
}
|
@ -18,8 +18,8 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/libraries/maker/every_block"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
|
||||
)
|
||||
|
||||
type MockLogFetcher struct {
|
||||
@ -50,18 +50,18 @@ type MockFlipKickConverter struct {
|
||||
ConverterContract string
|
||||
ConverterAbi string
|
||||
LogsToConvert []types.Log
|
||||
EntitiesToConvert []every_block.FlipKickEntity
|
||||
EntitiesToConvert []flip_kick.FlipKickEntity
|
||||
ConverterError error
|
||||
}
|
||||
|
||||
func (mfkc *MockFlipKickConverter) ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (*every_block.FlipKickEntity, error) {
|
||||
func (mfkc *MockFlipKickConverter) ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (*flip_kick.FlipKickEntity, error) {
|
||||
mfkc.ConverterContract = contractAddress
|
||||
mfkc.ConverterAbi = contractAbi
|
||||
mfkc.LogsToConvert = append(mfkc.LogsToConvert, ethLog)
|
||||
return &FlipKickEntity, mfkc.ConverterError
|
||||
}
|
||||
|
||||
func (mfkc *MockFlipKickConverter) ToModel(flipKick every_block.FlipKickEntity) (every_block.FlipKickModel, error) {
|
||||
func (mfkc *MockFlipKickConverter) ToModel(flipKick flip_kick.FlipKickEntity) (flip_kick.FlipKickModel, error) {
|
||||
mfkc.EntitiesToConvert = append(mfkc.EntitiesToConvert, flipKick)
|
||||
return FlipKickModel, nil
|
||||
}
|
||||
@ -74,12 +74,12 @@ type MockFlipKickRepository struct {
|
||||
HeadersToReturn []core.Header
|
||||
StartingBlockNumber int64
|
||||
EndingBlockNumber int64
|
||||
FlipKicksCreated []every_block.FlipKickModel
|
||||
FlipKicksCreated []flip_kick.FlipKickModel
|
||||
CreateRecordError error
|
||||
MissingHeadersError error
|
||||
}
|
||||
|
||||
func (mfkr *MockFlipKickRepository) Create(headerId int64, flipKick every_block.FlipKickModel) error {
|
||||
func (mfkr *MockFlipKickRepository) Create(headerId int64, flipKick flip_kick.FlipKickModel) error {
|
||||
mfkr.HeaderIds = append(mfkr.HeaderIds, headerId)
|
||||
mfkr.FlipKicksCreated = append(mfkr.FlipKicksCreated, flipKick)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user