Merge pull request #156 from vulcanize/contract-watcher-init

Enable contractWatcher without prior headerSync
This commit is contained in:
Rob Mulholand 2019-10-10 08:37:48 +09:00 committed by GitHub
commit 7be070fcea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -78,11 +78,10 @@ var _ = Describe("contractWatcher headerSync transformer", func() {
Expect(c.Address).To(Equal(tusdAddr)) Expect(c.Address).To(Equal(tusdAddr))
}) })
It("Fails to initialize if first and block cannot be fetched from vDB headers table", func() { It("initializes when no headers available in db", func() {
t := transformer.NewTransformer(test_helpers.TusdConfig, blockChain, db) t := transformer.NewTransformer(test_helpers.TusdConfig, blockChain, db)
err = t.Init() err = t.Init()
Expect(err).To(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("no rows in result set"))
}) })
It("Does nothing if nothing if no addresses are configured", func() { It("Does nothing if nothing if no addresses are configured", func() {

View File

@ -17,6 +17,7 @@
package transformer package transformer
import ( import (
"database/sql"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
@ -124,7 +125,11 @@ func (tr *Transformer) Init() error {
// Get first block and most recent block number in the header repo // Get first block and most recent block number in the header repo
firstBlock, retrieveErr := tr.Retriever.RetrieveFirstBlock() firstBlock, retrieveErr := tr.Retriever.RetrieveFirstBlock()
if retrieveErr != nil { if retrieveErr != nil {
return fmt.Errorf("error retrieving first block: %s", retrieveErr.Error()) if retrieveErr == sql.ErrNoRows {
firstBlock = 0
} else {
return fmt.Errorf("error retrieving first block: %s", retrieveErr.Error())
}
} }
// Set to specified range if it falls within the bounds // Set to specified range if it falls within the bounds

View File

@ -17,6 +17,7 @@
package transformer_test package transformer_test
import ( import (
"database/sql"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@ -101,7 +102,17 @@ var _ = Describe("Transformer", func() {
Expect(c.Address).To(Equal(fakeAddress)) Expect(c.Address).To(Equal(fakeAddress))
}) })
It("Fails to initialize if first block cannot be fetched from vDB headers table", func() { It("uses first block from config if vDB headers table has no rows", func() {
blockRetriever := &fakes.MockHeaderSyncBlockRetriever{}
blockRetriever.FirstBlockErr = sql.ErrNoRows
t := getFakeTransformer(blockRetriever, &fakes.MockParser{}, &fakes.MockPoller{})
err := t.Init()
Expect(err).ToNot(HaveOccurred())
})
It("returns error if fetching first block fails for other reason", func() {
blockRetriever := &fakes.MockHeaderSyncBlockRetriever{} blockRetriever := &fakes.MockHeaderSyncBlockRetriever{}
blockRetriever.FirstBlockErr = fakes.FakeError blockRetriever.FirstBlockErr = fakes.FakeError
t := getFakeTransformer(blockRetriever, &fakes.MockParser{}, &fakes.MockPoller{}) t := getFakeTransformer(blockRetriever, &fakes.MockParser{}, &fakes.MockPoller{})