Address PR comments

This commit is contained in:
Rob Mulholand
2019-03-28 14:31:17 -05:00
parent 54d46638a8
commit 81dfd12665
8 changed files with 69 additions and 74 deletions
+3 -5
View File
@@ -32,11 +32,9 @@ func (syncer TransactionsSyncer) SyncTransactions(headerID int64, logs []types.L
if transactionErr != nil {
return transactionErr
}
for _, transaction := range transactions {
writeErr := syncer.Repository.CreateTransaction(headerID, transaction)
if writeErr != nil {
return writeErr
}
writeErr := syncer.Repository.CreateTransactions(headerID, transactions)
if writeErr != nil {
return writeErr
}
return nil
}
+14 -19
View File
@@ -11,11 +11,19 @@ import (
)
var _ = Describe("Transaction syncer", func() {
It("fetches transactions for logs", func() {
db := test_config.NewTestDB(test_config.NewTestNode())
blockChain := fakes.NewMockBlockChain()
syncer := transactions.NewTransactionsSyncer(db, blockChain)
var (
blockChain *fakes.MockBlockChain
syncer transactions.TransactionsSyncer
)
BeforeEach(func() {
db := test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db)
blockChain = fakes.NewMockBlockChain()
syncer = transactions.NewTransactionsSyncer(db, blockChain)
})
It("fetches transactions for logs", func() {
err := syncer.SyncTransactions(0, []types.Log{})
Expect(err).NotTo(HaveOccurred())
@@ -23,10 +31,6 @@ var _ = Describe("Transaction syncer", func() {
})
It("only fetches transactions with unique hashes", func() {
db := test_config.NewTestDB(test_config.NewTestNode())
blockChain := fakes.NewMockBlockChain()
syncer := transactions.NewTransactionsSyncer(db, blockChain)
err := syncer.SyncTransactions(0, []types.Log{{
TxHash: fakes.FakeHash,
}, {
@@ -38,10 +42,7 @@ var _ = Describe("Transaction syncer", func() {
})
It("returns error if fetching transactions fails", func() {
db := test_config.NewTestDB(test_config.NewTestNode())
blockChain := fakes.NewMockBlockChain()
blockChain.GetTransactionsError = fakes.FakeError
syncer := transactions.NewTransactionsSyncer(db, blockChain)
err := syncer.SyncTransactions(0, []types.Log{})
@@ -50,26 +51,20 @@ var _ = Describe("Transaction syncer", func() {
})
It("passes transactions to repository for persistence", func() {
db := test_config.NewTestDB(test_config.NewTestNode())
blockChain := fakes.NewMockBlockChain()
blockChain.Transactions = []core.TransactionModel{{}}
syncer := transactions.NewTransactionsSyncer(db, blockChain)
mockHeaderRepository := fakes.NewMockHeaderRepository()
syncer.Repository = mockHeaderRepository
err := syncer.SyncTransactions(0, []types.Log{})
Expect(err).NotTo(HaveOccurred())
Expect(mockHeaderRepository.CreateTransactionCalled).To(BeTrue())
Expect(mockHeaderRepository.CreateTransactionsCalled).To(BeTrue())
})
It("returns error if persisting transactions fails", func() {
db := test_config.NewTestDB(test_config.NewTestNode())
blockChain := fakes.NewMockBlockChain()
blockChain.Transactions = []core.TransactionModel{{}}
syncer := transactions.NewTransactionsSyncer(db, blockChain)
mockHeaderRepository := fakes.NewMockHeaderRepository()
mockHeaderRepository.CreateTransactionError = fakes.FakeError
mockHeaderRepository.CreateTransactionsError = fakes.FakeError
syncer.Repository = mockHeaderRepository
err := syncer.SyncTransactions(0, []types.Log{})