forked from cerc-io/ipld-eth-server
Finish watcher and watcher tests (+fmt)
This commit is contained in:
@@ -19,8 +19,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
)
|
||||
|
||||
// TODO Add unit tests for LogChunker
|
||||
|
||||
type LogChunker struct {
|
||||
AddressToNames map[string][]string
|
||||
NameToTopic0 map[string]common.Hash
|
||||
@@ -40,7 +38,7 @@ func NewLogChunker(transformerConfigs []TransformerConfig) LogChunker {
|
||||
|
||||
return LogChunker{
|
||||
AddressToNames: addressToNames,
|
||||
NameToTopic0: nameToTopic0,
|
||||
NameToTopic0: nameToTopic0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ var _ = Describe("Log chunker", func() {
|
||||
logs := []types.Log{log1, log2, log3, log4, log5}
|
||||
chunks := chunker.ChunkLogs(logs)
|
||||
|
||||
Expect(chunks["TransformerA"]).To(And(ContainElement(log1),ContainElement(log4)))
|
||||
Expect(chunks["TransformerA"]).To(And(ContainElement(log1), ContainElement(log4)))
|
||||
Expect(chunks["TransformerB"]).To(BeEmpty())
|
||||
Expect(chunks["TransformerC"]).To(ContainElement(log5))
|
||||
})
|
||||
@@ -119,4 +119,4 @@ var (
|
||||
common.HexToHash("0xLogTopic5"),
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -26,14 +26,7 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Fetcher", func() {
|
||||
Describe("Iinitialisation", func() {
|
||||
It("creates correct lookup maps", func() {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Describe("FetchLogs", func() {
|
||||
// TODO Add tests for aggregate fetching
|
||||
It("fetches logs based on the given query", func() {
|
||||
blockChain := fakes.NewMockBlockChain()
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
|
||||
@@ -27,12 +27,14 @@ type MockLogFetcher struct {
|
||||
fetcherError error
|
||||
FetchedLogs []types.Log
|
||||
SetBcCalled bool
|
||||
FetchLogsCalled bool
|
||||
}
|
||||
|
||||
func (mlf *MockLogFetcher) FetchLogs(contractAddresses []common.Address, topics []common.Hash, header core.Header) ([]types.Log, error) {
|
||||
mlf.FetchedContractAddresses = append(mlf.FetchedContractAddresses, contractAddresses)
|
||||
mlf.FetchedTopics = [][]common.Hash{topics}
|
||||
mlf.FetchedBlocks = append(mlf.FetchedBlocks, header.BlockNumber)
|
||||
mlf.FetchLogsCalled = true
|
||||
|
||||
return mlf.FetchedLogs, mlf.fetcherError
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
)
|
||||
|
||||
type MockWatcherRepository struct {
|
||||
ReturnCheckedColumnNames []string
|
||||
GetCheckedColumnNamesError error
|
||||
GetCheckedColumnNamesCalled bool
|
||||
|
||||
ReturnNotCheckedSQL string
|
||||
CreateNotCheckedSQLCalled bool
|
||||
|
||||
ReturnMissingHeaders []core.Header
|
||||
MissingHeadersError error
|
||||
MissingHeadersCalled bool
|
||||
}
|
||||
|
||||
func (repository *MockWatcherRepository) GetCheckedColumnNames(db *postgres.DB) ([]string, error) {
|
||||
repository.GetCheckedColumnNamesCalled = true
|
||||
if repository.GetCheckedColumnNamesError != nil {
|
||||
return []string{}, repository.GetCheckedColumnNamesError
|
||||
}
|
||||
|
||||
return repository.ReturnCheckedColumnNames, nil
|
||||
}
|
||||
|
||||
func (repository *MockWatcherRepository) SetCheckedColumnNames(checkedColumnNames []string) {
|
||||
repository.ReturnCheckedColumnNames = checkedColumnNames
|
||||
}
|
||||
|
||||
func (repository *MockWatcherRepository) CreateNotCheckedSQL(boolColumns []string) string {
|
||||
repository.CreateNotCheckedSQLCalled = true
|
||||
return repository.ReturnNotCheckedSQL
|
||||
}
|
||||
|
||||
func (repository *MockWatcherRepository) SetNotCheckedSQL(notCheckedSql string) {
|
||||
repository.ReturnNotCheckedSQL = notCheckedSql
|
||||
}
|
||||
|
||||
func (repository *MockWatcherRepository) MissingHeaders(startingBlockNumber int64, endingBlockNumber int64, db *postgres.DB, notCheckedSQL string) ([]core.Header, error) {
|
||||
if repository.MissingHeadersError != nil {
|
||||
return []core.Header{}, repository.MissingHeadersError
|
||||
}
|
||||
repository.MissingHeadersCalled = true
|
||||
return repository.ReturnMissingHeaders, nil
|
||||
}
|
||||
|
||||
func (repository *MockWatcherRepository) SetMissingHeaders(headers []core.Header) {
|
||||
repository.ReturnMissingHeaders = headers
|
||||
}
|
||||
Reference in New Issue
Block a user