review fixes

This commit is contained in:
Ian Norden
2019-12-02 11:26:44 -06:00
parent a834e55b9f
commit db0f024088
15 changed files with 313 additions and 204 deletions
+2 -3
View File
@@ -27,7 +27,6 @@ type BackFiller struct {
StorageDiffsToReturn []utils.StorageDiff
BackFillErrs []error
PassedEndingBlock uint64
StartingBlock uint64
}
// SetStorageDiffsToReturn for tests
@@ -36,8 +35,8 @@ func (backFiller *BackFiller) SetStorageDiffsToReturn(diffs []utils.StorageDiff)
}
// BackFill mock method
func (backFiller *BackFiller) BackFill(endingBlock uint64, backFill chan utils.StorageDiff, errChan chan error, done chan bool) error {
if endingBlock < backFiller.StartingBlock {
func (backFiller *BackFiller) BackFill(startingBlock, endingBlock uint64, backFill chan utils.StorageDiff, errChan chan error, done chan bool) error {
if endingBlock < startingBlock {
return errors.New("backfill: ending block number needs to be greater than starting block number")
}
backFiller.PassedEndingBlock = endingBlock
+12 -11
View File
@@ -24,36 +24,37 @@ import (
type MockStorageQueue struct {
AddCalled bool
AddError error
AddPassedDiffs []utils.StorageDiff
AddPassedDiffs map[int]utils.StorageDiff
DeleteErr error
DeletePassedIds []int
GetAllErr error
DiffsToReturn []utils.StorageDiff
DiffsToReturn map[int]utils.StorageDiff
GetAllCalled bool
}
// Add mock method
func (queue *MockStorageQueue) Add(diff utils.StorageDiff) error {
queue.AddCalled = true
queue.AddPassedDiffs = append(queue.AddPassedDiffs, diff)
if queue.AddPassedDiffs == nil {
queue.AddPassedDiffs = make(map[int]utils.StorageDiff)
}
queue.AddPassedDiffs[diff.Id] = diff
return queue.AddError
}
// Delete mock method
func (queue *MockStorageQueue) Delete(id int) error {
queue.DeletePassedIds = append(queue.DeletePassedIds, id)
diffsToReturn := make([]utils.StorageDiff, 0)
for _, diff := range queue.DiffsToReturn {
if diff.Id != id {
diffsToReturn = append(diffsToReturn, diff)
}
}
queue.DiffsToReturn = diffsToReturn
delete(queue.DiffsToReturn, id)
return queue.DeleteErr
}
// GetAll mock method
func (queue *MockStorageQueue) GetAll() ([]utils.StorageDiff, error) {
queue.GetAllCalled = true
return queue.DiffsToReturn, queue.GetAllErr
diffs := make([]utils.StorageDiff, 0)
for _, diff := range queue.DiffsToReturn {
diffs = append(diffs, diff)
}
return diffs, queue.GetAllErr
}
@@ -28,12 +28,15 @@ import (
type MockStorageTransformer struct {
KeccakOfAddress common.Hash
ExecuteErr error
PassedDiffs []utils.StorageDiff
PassedDiffs map[int]utils.StorageDiff
}
// Execute mock method
func (transformer *MockStorageTransformer) Execute(diff utils.StorageDiff) error {
transformer.PassedDiffs = append(transformer.PassedDiffs, diff)
if transformer.PassedDiffs == nil {
transformer.PassedDiffs = make(map[int]utils.StorageDiff)
}
transformer.PassedDiffs[diff.Id] = diff
return transformer.ExecuteErr
}