mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 05:27:19 +00:00
11f4978ed4
Following our previous discussion on erigon's discord, this PR requests to upstream all Otterscan modifications to erigon's repo. That decision comes after getting feedback from lots of users at events this year, and although it may introduce some friction for development, it will make integrators life easier by having all our modifications available out of box, e.g., dappnode users will get our RPCs since their official packages are built from erigon repo. I'm submitting the source-code as-is, please let me know if you think there is a better code organization. The current set of modifications comprises only new RPCs. There are some proposals for extra-stages that would add new tables, but they are still WIP and will be submitted separately in future after more testing.
110 lines
4.3 KiB
Go
110 lines
4.3 KiB
Go
package commands
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestFromToBackwardBlockProviderWith1Chunk(t *testing.T) {
|
|
// Mocks 1 chunk
|
|
chunk1 := createBitmap(t, []uint64{1000, 1005, 1010})
|
|
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{chunk1})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 0)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 1010, true)
|
|
checkNext(t, blockProvider, 1005, true)
|
|
checkNext(t, blockProvider, 1000, false)
|
|
}
|
|
|
|
func TestFromToBackwardBlockProviderWith1ChunkMiddleBlock(t *testing.T) {
|
|
// Mocks 1 chunk
|
|
chunk1 := createBitmap(t, []uint64{1000, 1005, 1010})
|
|
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{chunk1})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 1005)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 1005, true)
|
|
checkNext(t, blockProvider, 1000, false)
|
|
}
|
|
|
|
func TestFromToBackwardBlockProviderWith1ChunkNotExactBlock(t *testing.T) {
|
|
// Mocks 1 chunk
|
|
chunk1 := createBitmap(t, []uint64{1000, 1005, 1010})
|
|
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{chunk1})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 1003)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 1000, false)
|
|
}
|
|
|
|
func TestFromToBackwardBlockProviderWith1ChunkLastBlock(t *testing.T) {
|
|
// Mocks 1 chunk
|
|
chunk1 := createBitmap(t, []uint64{1000, 1005, 1010})
|
|
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{chunk1})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 1000)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 1000, false)
|
|
}
|
|
|
|
func TestFromToBackwardBlockProviderWith1ChunkBlockNotFound(t *testing.T) {
|
|
// Mocks 1 chunk
|
|
chunk1 := createBitmap(t, []uint64{1000, 1005, 1010})
|
|
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{chunk1})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 900)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 0, false)
|
|
}
|
|
|
|
func TestFromToBackwardBlockProviderWithNoChunks(t *testing.T) {
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 0)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 0, false)
|
|
}
|
|
|
|
func TestFromToBackwardBlockProviderWithMultipleChunks(t *testing.T) {
|
|
// Mocks 2 chunks
|
|
chunk1 := createBitmap(t, []uint64{1000, 1005, 1010})
|
|
chunk2 := createBitmap(t, []uint64{1501, 1600})
|
|
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{chunk1, chunk2})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 0)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 1600, true)
|
|
checkNext(t, blockProvider, 1501, true)
|
|
checkNext(t, blockProvider, 1010, true)
|
|
checkNext(t, blockProvider, 1005, true)
|
|
checkNext(t, blockProvider, 1000, false)
|
|
}
|
|
|
|
func TestFromToBackwardBlockProviderWithMultipleChunksBlockBetweenChunks(t *testing.T) {
|
|
// Mocks 2 chunks
|
|
chunk1 := createBitmap(t, []uint64{1000, 1005, 1010})
|
|
chunk2 := createBitmap(t, []uint64{1501, 1600})
|
|
|
|
chunkLocator := newMockBackwardChunkLocator([][]byte{chunk1, chunk2})
|
|
fromBlockProvider := NewBackwardBlockProvider(chunkLocator, 1500)
|
|
toBlockProvider := NewBackwardBlockProvider(newMockBackwardChunkLocator([][]byte{}), 0)
|
|
blockProvider := newCallFromToBlockProvider(true, fromBlockProvider, toBlockProvider)
|
|
|
|
checkNext(t, blockProvider, 1010, true)
|
|
checkNext(t, blockProvider, 1005, true)
|
|
checkNext(t, blockProvider, 1000, false)
|
|
}
|