2019-10-02 14:10:37 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2019 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-05-30 03:02:47 +00:00
|
|
|
package watcher_test
|
2019-10-02 14:10:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2020-05-30 03:02:47 +00:00
|
|
|
"github.com/vulcanize/ipfs-chain-watcher/pkg/eth"
|
|
|
|
"github.com/vulcanize/ipfs-chain-watcher/pkg/eth/mocks"
|
|
|
|
"github.com/vulcanize/ipfs-chain-watcher/pkg/shared"
|
|
|
|
mocks2 "github.com/vulcanize/ipfs-chain-watcher/pkg/shared/mocks"
|
|
|
|
"github.com/vulcanize/ipfs-chain-watcher/pkg/watcher"
|
2019-10-02 14:10:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("BackFiller", func() {
|
|
|
|
Describe("FillGaps", func() {
|
|
|
|
It("Periodically checks for and fills in gaps in the super node's data", func() {
|
2020-01-17 23:16:01 +00:00
|
|
|
mockCidRepo := &mocks.CIDIndexer{
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
|
|
|
mockPublisher := &mocks.IterativeIPLDPublisher{
|
2020-01-17 23:16:01 +00:00
|
|
|
ReturnCIDPayload: []*eth.CIDPayload{mocks.MockCIDPayload, mocks.MockCIDPayload},
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
|
|
|
mockConverter := &mocks.IterativePayloadConverter{
|
2020-02-20 22:12:52 +00:00
|
|
|
ReturnIPLDPayload: []eth.ConvertedPayload{mocks.MockConvertedPayload, mocks.MockConvertedPayload},
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
2020-02-20 22:12:52 +00:00
|
|
|
mockRetriever := &mocks2.CIDRetriever{
|
2020-05-12 01:49:42 +00:00
|
|
|
FirstBlockNumberToReturn: 0,
|
2020-01-17 23:16:01 +00:00
|
|
|
GapsToRetrieve: []shared.Gap{
|
2019-10-02 14:10:37 +00:00
|
|
|
{
|
2020-01-17 23:16:01 +00:00
|
|
|
Start: 100, Stop: 101,
|
2019-10-02 14:10:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-02-20 22:12:52 +00:00
|
|
|
mockFetcher := &mocks2.PayloadFetcher{
|
2020-01-31 18:03:37 +00:00
|
|
|
PayloadsToReturn: map[uint64]shared.RawChainData{
|
2019-10-14 14:41:29 +00:00
|
|
|
100: mocks.MockStateDiffPayload,
|
|
|
|
101: mocks.MockStateDiffPayload,
|
2019-10-02 14:10:37 +00:00
|
|
|
},
|
|
|
|
}
|
2020-02-13 22:50:56 +00:00
|
|
|
quitChan := make(chan bool, 1)
|
2020-05-30 03:02:47 +00:00
|
|
|
backfiller := &watcher.BackFillService{
|
2020-01-17 23:16:01 +00:00
|
|
|
Indexer: mockCidRepo,
|
2019-10-02 14:10:37 +00:00
|
|
|
Publisher: mockPublisher,
|
|
|
|
Converter: mockConverter,
|
2019-11-01 19:03:28 +00:00
|
|
|
Fetcher: mockFetcher,
|
2019-10-02 14:10:37 +00:00
|
|
|
Retriever: mockRetriever,
|
2019-10-14 14:41:29 +00:00
|
|
|
GapCheckFrequency: time.Second * 2,
|
2020-05-30 03:02:47 +00:00
|
|
|
BatchSize: watcher.DefaultMaxBatchSize,
|
|
|
|
BatchNumber: watcher.DefaultMaxBatchNumber,
|
2020-02-13 22:50:56 +00:00
|
|
|
QuitChan: quitChan,
|
2019-10-02 14:10:37 +00:00
|
|
|
}
|
|
|
|
wg := &sync.WaitGroup{}
|
2020-04-23 20:56:37 +00:00
|
|
|
backfiller.BackFill(wg)
|
2019-10-14 14:41:29 +00:00
|
|
|
time.Sleep(time.Second * 3)
|
2019-10-02 14:10:37 +00:00
|
|
|
quitChan <- true
|
|
|
|
Expect(len(mockCidRepo.PassedCIDPayload)).To(Equal(2))
|
|
|
|
Expect(mockCidRepo.PassedCIDPayload[0]).To(Equal(mocks.MockCIDPayload))
|
|
|
|
Expect(mockCidRepo.PassedCIDPayload[1]).To(Equal(mocks.MockCIDPayload))
|
|
|
|
Expect(len(mockPublisher.PassedIPLDPayload)).To(Equal(2))
|
2020-02-20 22:12:52 +00:00
|
|
|
Expect(mockPublisher.PassedIPLDPayload[0]).To(Equal(mocks.MockConvertedPayload))
|
|
|
|
Expect(mockPublisher.PassedIPLDPayload[1]).To(Equal(mocks.MockConvertedPayload))
|
2019-10-02 14:10:37 +00:00
|
|
|
Expect(len(mockConverter.PassedStatediffPayload)).To(Equal(2))
|
|
|
|
Expect(mockConverter.PassedStatediffPayload[0]).To(Equal(mocks.MockStateDiffPayload))
|
|
|
|
Expect(mockConverter.PassedStatediffPayload[1]).To(Equal(mocks.MockStateDiffPayload))
|
|
|
|
Expect(mockRetriever.CalledTimes).To(Equal(1))
|
|
|
|
Expect(len(mockFetcher.CalledAtBlockHeights)).To(Equal(1))
|
|
|
|
Expect(mockFetcher.CalledAtBlockHeights[0]).To(Equal([]uint64{100, 101}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Works for single block `ranges`", func() {
|
2020-01-17 23:16:01 +00:00
|
|
|
mockCidRepo := &mocks.CIDIndexer{
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
|
|
|
mockPublisher := &mocks.IterativeIPLDPublisher{
|
2020-01-17 23:16:01 +00:00
|
|
|
ReturnCIDPayload: []*eth.CIDPayload{mocks.MockCIDPayload},
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
|
|
|
mockConverter := &mocks.IterativePayloadConverter{
|
2020-02-20 22:12:52 +00:00
|
|
|
ReturnIPLDPayload: []eth.ConvertedPayload{mocks.MockConvertedPayload},
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
2020-02-20 22:12:52 +00:00
|
|
|
mockRetriever := &mocks2.CIDRetriever{
|
2020-05-12 01:49:42 +00:00
|
|
|
FirstBlockNumberToReturn: 0,
|
2020-01-17 23:16:01 +00:00
|
|
|
GapsToRetrieve: []shared.Gap{
|
2019-10-02 14:10:37 +00:00
|
|
|
{
|
2020-01-17 23:16:01 +00:00
|
|
|
Start: 100, Stop: 100,
|
2019-10-02 14:10:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-02-20 22:12:52 +00:00
|
|
|
mockFetcher := &mocks2.PayloadFetcher{
|
2020-01-31 18:03:37 +00:00
|
|
|
PayloadsToReturn: map[uint64]shared.RawChainData{
|
2019-10-14 14:41:29 +00:00
|
|
|
100: mocks.MockStateDiffPayload,
|
2019-10-02 14:10:37 +00:00
|
|
|
},
|
|
|
|
}
|
2020-02-13 22:50:56 +00:00
|
|
|
quitChan := make(chan bool, 1)
|
2020-05-30 03:02:47 +00:00
|
|
|
backfiller := &watcher.BackFillService{
|
2020-01-17 23:16:01 +00:00
|
|
|
Indexer: mockCidRepo,
|
2019-10-02 14:10:37 +00:00
|
|
|
Publisher: mockPublisher,
|
|
|
|
Converter: mockConverter,
|
2019-11-01 19:03:28 +00:00
|
|
|
Fetcher: mockFetcher,
|
2019-10-02 14:10:37 +00:00
|
|
|
Retriever: mockRetriever,
|
2019-10-14 14:41:29 +00:00
|
|
|
GapCheckFrequency: time.Second * 2,
|
2020-05-30 03:02:47 +00:00
|
|
|
BatchSize: watcher.DefaultMaxBatchSize,
|
|
|
|
BatchNumber: watcher.DefaultMaxBatchNumber,
|
2020-02-13 22:50:56 +00:00
|
|
|
QuitChan: quitChan,
|
2019-10-02 14:10:37 +00:00
|
|
|
}
|
|
|
|
wg := &sync.WaitGroup{}
|
2020-04-23 20:56:37 +00:00
|
|
|
backfiller.BackFill(wg)
|
2019-10-14 14:41:29 +00:00
|
|
|
time.Sleep(time.Second * 3)
|
2019-10-02 14:10:37 +00:00
|
|
|
quitChan <- true
|
|
|
|
Expect(len(mockCidRepo.PassedCIDPayload)).To(Equal(1))
|
|
|
|
Expect(mockCidRepo.PassedCIDPayload[0]).To(Equal(mocks.MockCIDPayload))
|
|
|
|
Expect(len(mockPublisher.PassedIPLDPayload)).To(Equal(1))
|
2020-02-20 22:12:52 +00:00
|
|
|
Expect(mockPublisher.PassedIPLDPayload[0]).To(Equal(mocks.MockConvertedPayload))
|
2019-10-02 14:10:37 +00:00
|
|
|
Expect(len(mockConverter.PassedStatediffPayload)).To(Equal(1))
|
|
|
|
Expect(mockConverter.PassedStatediffPayload[0]).To(Equal(mocks.MockStateDiffPayload))
|
|
|
|
Expect(mockRetriever.CalledTimes).To(Equal(1))
|
|
|
|
Expect(len(mockFetcher.CalledAtBlockHeights)).To(Equal(1))
|
|
|
|
Expect(mockFetcher.CalledAtBlockHeights[0]).To(Equal([]uint64{100}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Finds beginning gap", func() {
|
2020-01-17 23:16:01 +00:00
|
|
|
mockCidRepo := &mocks.CIDIndexer{
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
|
|
|
mockPublisher := &mocks.IterativeIPLDPublisher{
|
2020-01-17 23:16:01 +00:00
|
|
|
ReturnCIDPayload: []*eth.CIDPayload{mocks.MockCIDPayload, mocks.MockCIDPayload},
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
|
|
|
mockConverter := &mocks.IterativePayloadConverter{
|
2020-02-20 22:12:52 +00:00
|
|
|
ReturnIPLDPayload: []eth.ConvertedPayload{mocks.MockConvertedPayload, mocks.MockConvertedPayload},
|
2019-10-02 14:10:37 +00:00
|
|
|
ReturnErr: nil,
|
|
|
|
}
|
2020-02-20 22:12:52 +00:00
|
|
|
mockRetriever := &mocks2.CIDRetriever{
|
2019-10-02 14:10:37 +00:00
|
|
|
FirstBlockNumberToReturn: 3,
|
2020-05-12 19:53:50 +00:00
|
|
|
GapsToRetrieve: []shared.Gap{
|
|
|
|
{
|
|
|
|
Start: 0,
|
|
|
|
Stop: 2,
|
|
|
|
},
|
|
|
|
},
|
2019-10-02 14:10:37 +00:00
|
|
|
}
|
2020-02-20 22:12:52 +00:00
|
|
|
mockFetcher := &mocks2.PayloadFetcher{
|
2020-01-31 18:03:37 +00:00
|
|
|
PayloadsToReturn: map[uint64]shared.RawChainData{
|
2019-10-14 14:41:29 +00:00
|
|
|
1: mocks.MockStateDiffPayload,
|
|
|
|
2: mocks.MockStateDiffPayload,
|
2019-10-02 14:10:37 +00:00
|
|
|
},
|
|
|
|
}
|
2020-02-13 22:50:56 +00:00
|
|
|
quitChan := make(chan bool, 1)
|
2020-05-30 03:02:47 +00:00
|
|
|
backfiller := &watcher.BackFillService{
|
2020-01-17 23:16:01 +00:00
|
|
|
Indexer: mockCidRepo,
|
2019-10-02 14:10:37 +00:00
|
|
|
Publisher: mockPublisher,
|
|
|
|
Converter: mockConverter,
|
2019-11-01 19:03:28 +00:00
|
|
|
Fetcher: mockFetcher,
|
2019-10-02 14:10:37 +00:00
|
|
|
Retriever: mockRetriever,
|
2019-10-14 14:41:29 +00:00
|
|
|
GapCheckFrequency: time.Second * 2,
|
2020-05-30 03:02:47 +00:00
|
|
|
BatchSize: watcher.DefaultMaxBatchSize,
|
|
|
|
BatchNumber: watcher.DefaultMaxBatchNumber,
|
2020-02-13 22:50:56 +00:00
|
|
|
QuitChan: quitChan,
|
2019-10-02 14:10:37 +00:00
|
|
|
}
|
|
|
|
wg := &sync.WaitGroup{}
|
2020-04-23 20:56:37 +00:00
|
|
|
backfiller.BackFill(wg)
|
2019-10-14 14:41:29 +00:00
|
|
|
time.Sleep(time.Second * 3)
|
2019-10-02 14:10:37 +00:00
|
|
|
quitChan <- true
|
|
|
|
Expect(len(mockCidRepo.PassedCIDPayload)).To(Equal(2))
|
|
|
|
Expect(mockCidRepo.PassedCIDPayload[0]).To(Equal(mocks.MockCIDPayload))
|
|
|
|
Expect(mockCidRepo.PassedCIDPayload[1]).To(Equal(mocks.MockCIDPayload))
|
|
|
|
Expect(len(mockPublisher.PassedIPLDPayload)).To(Equal(2))
|
2020-02-20 22:12:52 +00:00
|
|
|
Expect(mockPublisher.PassedIPLDPayload[0]).To(Equal(mocks.MockConvertedPayload))
|
|
|
|
Expect(mockPublisher.PassedIPLDPayload[1]).To(Equal(mocks.MockConvertedPayload))
|
2019-10-02 14:10:37 +00:00
|
|
|
Expect(len(mockConverter.PassedStatediffPayload)).To(Equal(2))
|
|
|
|
Expect(mockConverter.PassedStatediffPayload[0]).To(Equal(mocks.MockStateDiffPayload))
|
|
|
|
Expect(mockConverter.PassedStatediffPayload[1]).To(Equal(mocks.MockStateDiffPayload))
|
|
|
|
Expect(mockRetriever.CalledTimes).To(Equal(1))
|
|
|
|
Expect(len(mockFetcher.CalledAtBlockHeights)).To(Equal(1))
|
2020-02-10 17:16:57 +00:00
|
|
|
Expect(mockFetcher.CalledAtBlockHeights[0]).To(Equal([]uint64{0, 1, 2}))
|
2019-10-02 14:10:37 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|