Backfill Frob log events

This commit is contained in:
Rob Mulholand
2018-08-14 10:47:43 -05:00
parent 55229cd2eb
commit ac63e43543
40 changed files with 1251 additions and 149 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ import (
)
var _ = Describe("FlipKickEntity Converter", func() {
It("converts an Eth Log to and Entity", func() {
It("converts an Eth Log to an Entity", func() {
converter := flip_kick.FlipKickConverter{}
entity, err := converter.ToEntity(test_data.TemporaryFlipAddress, flip_kick.FlipperABI, test_data.EthFlipKickLog)
-52
View File
@@ -1,52 +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 flip_kick
import (
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/core"
)
type LogFetcher interface {
FetchLogs(contractAddress string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error)
}
type Fetcher struct {
Blockchain core.BlockChain
}
func NewFetcher(blockchain core.BlockChain) Fetcher {
return Fetcher{
Blockchain: blockchain,
}
}
func (f Fetcher) FetchLogs(contractAddress string, topicZeros [][]common.Hash, blockNumber int64) ([]types.Log, error) {
block := big.NewInt(blockNumber)
address := common.HexToAddress(contractAddress)
query := ethereum.FilterQuery{
FromBlock: block,
ToBlock: block,
Addresses: []common.Address{address},
Topics: topicZeros,
}
return f.Blockchain.GetEthLogsWithCustomQuery(query)
}
@@ -1,62 +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 flip_kick_test
import (
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"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 flip_kick.Fetcher
BeforeEach(func() {
blockChain = fakes.NewMockBlockChain()
fetcher = flip_kick.Fetcher{Blockchain: blockChain}
})
It("fetches logs based on the given query", func() {
blockNumber := int64(3)
address := "0x4D2"
topicZeros := [][]common.Hash{{common.HexToHash("0x")}}
query := ethereum.FilterQuery{
FromBlock: big.NewInt(blockNumber),
ToBlock: big.NewInt(blockNumber),
Addresses: []common.Address{common.HexToAddress(address)},
Topics: topicZeros,
}
fetcher.FetchLogs(address, topicZeros, blockNumber)
blockChain.AssertGetEthLogsWithCustomQueryCalledWith(query)
})
It("returns an error if fetching the logs fails", func() {
blockChain.SetGetLogsErr(fakes.FakeError)
_, err := fetcher.FetchLogs("", [][]common.Hash{}, int64(1))
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
})
})
})
@@ -23,9 +23,9 @@ import (
. "github.com/onsi/gomega"
)
func TestEveryBlock(t *testing.T) {
func TestFlipKick(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "EveryBlock Suite")
RunSpecs(t, "FlipKick Suite")
}
var _ = BeforeSuite(func() {
@@ -26,6 +26,7 @@ import (
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/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/test_config"
)
@@ -43,7 +44,7 @@ var _ = Describe("Integration tests", func() {
realNode := node.MakeNode(rpcClient)
transactionConverter := rpc2.NewRpcTransactionConverter(ethClient)
realBlockChain := geth.NewBlockChain(blockChainClient, realNode, transactionConverter)
realFetcher := flip_kick.NewFetcher(realBlockChain)
realFetcher := shared.NewFetcher(realBlockChain)
topic0 := common.HexToHash(flip_kick.FlipKickSignature)
topics := [][]common.Hash{{topic0}}
+3 -3
View File
@@ -21,13 +21,13 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/vulcanize/vulcanizedb/libraries/shared"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
)
type FlipKickTransformer struct {
Fetcher LogFetcher
Fetcher shared.LogFetcher
Converter Converter
Repository Repository
Config TransformerConfig
@@ -38,7 +38,7 @@ type FlipKickTransformerInitializer struct {
}
func (i FlipKickTransformerInitializer) NewFlipKickTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer {
fetcher := NewFetcher(blockChain)
fetcher := shared.NewFetcher(blockChain)
repository := NewFlipKickRepository(db)
transformer := FlipKickTransformer{
Fetcher: fetcher,
@@ -26,13 +26,15 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
flip_kick_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/flip_kick"
)
var _ = Describe("FlipKick Transformer", func() {
var transformer flip_kick.FlipKickTransformer
var fetcher test_data.MockLogFetcher
var converter test_data.MockFlipKickConverter
var repository test_data.MockFlipKickRepository
var fetcher mocks.MockLogFetcher
var converter flip_kick_mocks.MockFlipKickConverter
var repository flip_kick_mocks.MockFlipKickRepository
var testConfig flip_kick.TransformerConfig
var blockNumber int64
var headerId int64
@@ -40,9 +42,9 @@ var _ = Describe("FlipKick Transformer", func() {
var logs []types.Log
BeforeEach(func() {
fetcher = test_data.MockLogFetcher{}
converter = test_data.MockFlipKickConverter{}
repository = test_data.MockFlipKickRepository{}
fetcher = mocks.MockLogFetcher{}
converter = flip_kick_mocks.MockFlipKickConverter{}
repository = flip_kick_mocks.MockFlipKickRepository{}
transformer = flip_kick.FlipKickTransformer{
Fetcher: &fetcher,
Converter: &converter,