|
1 | 1 | package orchestrator |
2 | | - |
3 | | -import ( |
4 | | - "context" |
5 | | - "math/big" |
6 | | - "testing" |
7 | | - |
8 | | - "github.com/stretchr/testify/assert" |
9 | | - "github.com/stretchr/testify/mock" |
10 | | - "github.com/thirdweb-dev/indexer/internal/rpc" |
11 | | - "github.com/thirdweb-dev/indexer/internal/storage" |
12 | | - mocks "github.com/thirdweb-dev/indexer/test/mocks" |
13 | | -) |
14 | | - |
15 | | -func TestNewCommitter(t *testing.T) { |
16 | | - mockRPC := mocks.NewMockIRPCClient(t) |
17 | | - mockMainStorage := mocks.NewMockIMainStorage(t) |
18 | | - mockStagingStorage := mocks.NewMockIStagingStorage(t) |
19 | | - |
20 | | - mockStorage := storage.IStorage{ |
21 | | - MainStorage: mockMainStorage, |
22 | | - StagingStorage: mockStagingStorage, |
23 | | - } |
24 | | - |
25 | | - // Mock the GetBlocksPerRequest call that happens in NewWorker |
26 | | - mockRPC.EXPECT().GetBlocksPerRequest().Return(rpc.BlocksPerRequestConfig{Blocks: 100}) |
27 | | - |
28 | | - poller := &Poller{} |
29 | | - committer := NewCommitter(mockRPC, mockStorage, poller) |
30 | | - |
31 | | - assert.NotNil(t, committer) |
32 | | - assert.Equal(t, DEFAULT_COMMITTER_TRIGGER_INTERVAL, committer.triggerIntervalMs) |
33 | | - assert.Equal(t, DEFAULT_BLOCKS_PER_COMMIT, committer.blocksPerCommit) |
34 | | -} |
35 | | - |
36 | | -// Removed - test needs to be updated for new implementation |
37 | | - |
38 | | -// Removed - test needs to be updated for new implementation |
39 | | - |
40 | | -// Removed - test needs to be updated for new implementation |
41 | | - |
42 | | -// Removed - test needs to be updated for new implementation |
43 | | - |
44 | | -// Removed - test needs to be updated for new implementation |
45 | | - |
46 | | -// Removed - test needs to be updated for new implementation |
47 | | - |
48 | | -// Removed - test needs to be updated for new implementation |
49 | | - |
50 | | -// Removed - test needs to be updated for new implementation |
51 | | - |
52 | | -// Removed - test needs to be updated for new implementation |
53 | | - |
54 | | -// Removed - test needs to be updated for new implementation |
55 | | - |
56 | | -// Removed - test needs to be updated for new implementation |
57 | | - |
58 | | -// Removed - test needs to be updated for new implementation |
59 | | - |
60 | | -func TestCleanupProcessedStagingBlocks(t *testing.T) { |
61 | | - mockRPC := mocks.NewMockIRPCClient(t) |
62 | | - mockMainStorage := mocks.NewMockIMainStorage(t) |
63 | | - mockStagingStorage := mocks.NewMockIStagingStorage(t) |
64 | | - mockOrchestratorStorage := mocks.NewMockIOrchestratorStorage(t) |
65 | | - mockStorage := storage.IStorage{ |
66 | | - MainStorage: mockMainStorage, |
67 | | - StagingStorage: mockStagingStorage, |
68 | | - OrchestratorStorage: mockOrchestratorStorage, |
69 | | - } |
70 | | - |
71 | | - // Mock the GetBlocksPerRequest call that happens in NewWorker |
72 | | - mockRPC.EXPECT().GetBlocksPerRequest().Return(rpc.BlocksPerRequestConfig{Blocks: 100}) |
73 | | - |
74 | | - poller := &Poller{} |
75 | | - committer := NewCommitter(mockRPC, mockStorage, poller) |
76 | | - |
77 | | - chainID := big.NewInt(1) |
78 | | - committer.lastCommittedBlock.Store(100) |
79 | | - committer.lastPublishedBlock.Store(0) |
80 | | - |
81 | | - ctx := context.Background() |
82 | | - committer.cleanupProcessedStagingBlocks(ctx) |
83 | | - mockStagingStorage.AssertNotCalled(t, "DeleteStagingDataOlderThan", mock.Anything, mock.Anything) |
84 | | - |
85 | | - committer.lastPublishedBlock.Store(90) |
86 | | - mockRPC.EXPECT().GetChainID().Return(chainID) |
87 | | - mockStagingStorage.EXPECT().DeleteStagingDataOlderThan(chainID, big.NewInt(90)).Return(nil) |
88 | | - committer.cleanupProcessedStagingBlocks(ctx) |
89 | | -} |
90 | | - |
91 | | -func TestStartCommitter(t *testing.T) { |
92 | | -} |
0 commit comments