Commit 166ba06b authored by Ethen Pociask's avatar Ethen Pociask

[indexer.l1height-param] Updated mocks

parent 7eb17ec9
...@@ -15,11 +15,11 @@ import ( ...@@ -15,11 +15,11 @@ import (
// Config represents the `indexer.toml` file used to configure the indexer // Config represents the `indexer.toml` file used to configure the indexer
type Config struct { type Config struct {
Chain ChainConfig Chain ChainConfig `toml:"chain"`
RPCs RPCsConfig `toml:"rpcs"` RPCs RPCsConfig `toml:"rpcs"`
DB DBConfig DB DBConfig `toml:"db"`
API APIConfig API APIConfig `toml:"api"`
Metrics MetricsConfig Metrics MetricsConfig `toml:"metrics"`
} }
// fetch this via onchain config from RPCsConfig and remove from config in future // fetch this via onchain config from RPCsConfig and remove from config in future
...@@ -78,23 +78,23 @@ type RPCsConfig struct { ...@@ -78,23 +78,23 @@ type RPCsConfig struct {
// DBConfig configures the postgres database // DBConfig configures the postgres database
type DBConfig struct { type DBConfig struct {
Host string Host string `toml:"host"`
Port int Port int `toml:"port"`
Name string Name string `toml:"name"`
User string User string `toml:"user"`
Password string Password string `toml:"password"`
} }
// APIConfig configures the API server // APIConfig configures the API server
type APIConfig struct { type APIConfig struct {
Host string Host string `toml:"host"`
Port int Port int `toml:"port"`
} }
// MetricsConfig configures the metrics server // MetricsConfig configures the metrics server
type MetricsConfig struct { type MetricsConfig struct {
Host string Host string `toml:"host"`
Port int Port int `toml:"port"`
} }
// LoadConfig loads the `indexer.toml` config file from a given path // LoadConfig loads the `indexer.toml` config file from a given path
......
...@@ -67,8 +67,6 @@ func (m *MockBlocksView) LatestEpoch() (*Epoch, error) { ...@@ -67,8 +67,6 @@ func (m *MockBlocksView) LatestEpoch() (*Epoch, error) {
return args.Get(0).(*Epoch), args.Error(1) return args.Get(0).(*Epoch), args.Error(1)
} }
var _ BlocksDB = (*MockBlocksDB)(nil)
type MockBlocksDB struct { type MockBlocksDB struct {
MockBlocksView MockBlocksView
} }
...@@ -92,8 +90,8 @@ func (m *MockBlocksDB) StoreOutputProposals(headers []OutputProposal) error { ...@@ -92,8 +90,8 @@ func (m *MockBlocksDB) StoreOutputProposals(headers []OutputProposal) error {
return args.Error(1) return args.Error(1)
} }
// MockDB is a mock database that can be used for testing
type MockDB struct { type MockDB struct {
MockBlockView *MockBlocksView
MockBlocks *MockBlocksDB MockBlocks *MockBlocksDB
DB *DB DB *DB
} }
...@@ -105,6 +103,5 @@ func NewMockDB() *MockDB { ...@@ -105,6 +103,5 @@ func NewMockDB() *MockDB {
mockBlocks := new(MockBlocksDB) mockBlocks := new(MockBlocksDB)
db := &DB{Blocks: mockBlocks} db := &DB{Blocks: mockBlocks}
return &MockDB{MockBlocks: mockBlocks, DB: db, return &MockDB{MockBlocks: mockBlocks, DB: db}
MockBlockView: new(MockBlocksView)}
} }
...@@ -14,6 +14,9 @@ import ( ...@@ -14,6 +14,9 @@ import (
) )
const ( const (
// NOTE - These values can be made configurable to allow for more fine grained control
// Additionally a default interval of 5 seconds may be too slow for reading L2 blocks provided
// the current rate of L2 block production on OP Stack chains (2 seconds per block)
defaultLoopInterval = 5 * time.Second defaultLoopInterval = 5 * time.Second
defaultHeaderBufferSize = 500 defaultHeaderBufferSize = 500
) )
...@@ -90,7 +93,7 @@ func (etl *ETL) Start(ctx context.Context) error { ...@@ -90,7 +93,7 @@ func (etl *ETL) Start(ctx context.Context) error {
for i := range logs { for i := range logs {
if _, ok := headerMap[logs[i].BlockHash]; !ok { if _, ok := headerMap[logs[i].BlockHash]; !ok {
// NOTE. Definitely an error state if the none of the headers were re-orged out in between // NOTE. Definitely an error state if the none of the headers were re-orged out in between
// the blocks and logs retreival operations. However, we need to gracefully handle reorgs // the blocks and logs retrieval operations. However, we need to gracefully handle reorgs
batchLog.Error("log found with block hash not in the batch", "block_hash", logs[i].BlockHash, "log_index", logs[i].Index) batchLog.Error("log found with block hash not in the batch", "block_hash", logs[i].BlockHash, "log_index", logs[i].Index)
return errors.New("parsed log with a block hash not in the fetched batch") return errors.New("parsed log with a block hash not in the fetched batch")
} }
......
...@@ -16,23 +16,22 @@ import ( ...@@ -16,23 +16,22 @@ import (
"testing" "testing"
) )
// test suite func Test_L1ETL_Construction(t *testing.T) {
type l1EtlTs struct { type testSuite struct {
db *database.MockDB db *database.MockDB
client *node.MockEthClient client *node.MockEthClient
start *big.Int start *big.Int
contracts config.L1Contracts contracts config.L1Contracts
} }
func Test_L1ETL_Construction(t *testing.T) {
var tests = []struct { var tests = []struct {
name string name string
construction func() *l1EtlTs construction func() *testSuite
assertion func(*L1ETL, error) assertion func(*L1ETL, error)
}{ }{
{ {
name: "Start from L1 config height", name: "Start from L1 config height",
construction: func() *l1EtlTs { construction: func() *testSuite {
client := new(node.MockEthClient) client := new(node.MockEthClient)
db := database.NewMockDB() db := database.NewMockDB()
...@@ -48,7 +47,7 @@ func Test_L1ETL_Construction(t *testing.T) { ...@@ -48,7 +47,7 @@ func Test_L1ETL_Construction(t *testing.T) {
client.On("GethEthClient").Return(nil) client.On("GethEthClient").Return(nil)
return &l1EtlTs{ return &testSuite{
db: db, db: db,
client: client, client: client,
start: testStart, start: testStart,
...@@ -62,7 +61,7 @@ func Test_L1ETL_Construction(t *testing.T) { ...@@ -62,7 +61,7 @@ func Test_L1ETL_Construction(t *testing.T) {
}, },
{ {
name: "Start from recent height stored in DB", name: "Start from recent height stored in DB",
construction: func() *l1EtlTs { construction: func() *testSuite {
client := new(node.MockEthClient) client := new(node.MockEthClient)
db := database.NewMockDB() db := database.NewMockDB()
...@@ -78,7 +77,7 @@ func Test_L1ETL_Construction(t *testing.T) { ...@@ -78,7 +77,7 @@ func Test_L1ETL_Construction(t *testing.T) {
client.On("GethEthClient").Return(nil) client.On("GethEthClient").Return(nil)
return &l1EtlTs{ return &testSuite{
db: db, db: db,
client: client, client: client,
start: testStart, start: testStart,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment