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

[indexer.l1height-param] Updated mocks

parent 7eb17ec9
......@@ -15,11 +15,11 @@ import (
// Config represents the `indexer.toml` file used to configure the indexer
type Config struct {
Chain ChainConfig
RPCs RPCsConfig `toml:"rpcs"`
DB DBConfig
API APIConfig
Metrics MetricsConfig
Chain ChainConfig `toml:"chain"`
RPCs RPCsConfig `toml:"rpcs"`
DB DBConfig `toml:"db"`
API APIConfig `toml:"api"`
Metrics MetricsConfig `toml:"metrics"`
}
// fetch this via onchain config from RPCsConfig and remove from config in future
......@@ -78,23 +78,23 @@ type RPCsConfig struct {
// DBConfig configures the postgres database
type DBConfig struct {
Host string
Port int
Name string
User string
Password string
Host string `toml:"host"`
Port int `toml:"port"`
Name string `toml:"name"`
User string `toml:"user"`
Password string `toml:"password"`
}
// APIConfig configures the API server
type APIConfig struct {
Host string
Port int
Host string `toml:"host"`
Port int `toml:"port"`
}
// MetricsConfig configures the metrics server
type MetricsConfig struct {
Host string
Port int
Host string `toml:"host"`
Port int `toml:"port"`
}
// LoadConfig loads the `indexer.toml` config file from a given path
......
......@@ -67,8 +67,6 @@ func (m *MockBlocksView) LatestEpoch() (*Epoch, error) {
return args.Get(0).(*Epoch), args.Error(1)
}
var _ BlocksDB = (*MockBlocksDB)(nil)
type MockBlocksDB struct {
MockBlocksView
}
......@@ -92,10 +90,10 @@ func (m *MockBlocksDB) StoreOutputProposals(headers []OutputProposal) error {
return args.Error(1)
}
// MockDB is a mock database that can be used for testing
type MockDB struct {
MockBlockView *MockBlocksView
MockBlocks *MockBlocksDB
DB *DB
MockBlocks *MockBlocksDB
DB *DB
}
func NewMockDB() *MockDB {
......@@ -105,6 +103,5 @@ func NewMockDB() *MockDB {
mockBlocks := new(MockBlocksDB)
db := &DB{Blocks: mockBlocks}
return &MockDB{MockBlocks: mockBlocks, DB: db,
MockBlockView: new(MockBlocksView)}
return &MockDB{MockBlocks: mockBlocks, DB: db}
}
......@@ -14,6 +14,9 @@ import (
)
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
defaultHeaderBufferSize = 500
)
......@@ -90,7 +93,7 @@ func (etl *ETL) Start(ctx context.Context) error {
for i := range logs {
if _, ok := headerMap[logs[i].BlockHash]; !ok {
// 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)
return errors.New("parsed log with a block hash not in the fetched batch")
}
......
......@@ -16,23 +16,22 @@ import (
"testing"
)
// test suite
type l1EtlTs struct {
db *database.MockDB
client *node.MockEthClient
start *big.Int
contracts config.L1Contracts
}
func Test_L1ETL_Construction(t *testing.T) {
type testSuite struct {
db *database.MockDB
client *node.MockEthClient
start *big.Int
contracts config.L1Contracts
}
var tests = []struct {
name string
construction func() *l1EtlTs
construction func() *testSuite
assertion func(*L1ETL, error)
}{
{
name: "Start from L1 config height",
construction: func() *l1EtlTs {
construction: func() *testSuite {
client := new(node.MockEthClient)
db := database.NewMockDB()
......@@ -48,7 +47,7 @@ func Test_L1ETL_Construction(t *testing.T) {
client.On("GethEthClient").Return(nil)
return &l1EtlTs{
return &testSuite{
db: db,
client: client,
start: testStart,
......@@ -62,7 +61,7 @@ func Test_L1ETL_Construction(t *testing.T) {
},
{
name: "Start from recent height stored in DB",
construction: func() *l1EtlTs {
construction: func() *testSuite {
client := new(node.MockEthClient)
db := database.NewMockDB()
......@@ -78,7 +77,7 @@ func Test_L1ETL_Construction(t *testing.T) {
client.On("GethEthClient").Return(nil)
return &l1EtlTs{
return &testSuite{
db: db,
client: client,
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