Skip to content

Commit

Permalink
Merkle db fix new return type (#1898)
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Laine <[email protected]>
  • Loading branch information
dboehm-avalabs and Dan Laine authored Aug 23, 2023
1 parent cf6eedc commit a37bb0a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion x/merkledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (db *merkleDB) rebuild(ctx context.Context) error {
}

// New returns a new merkle database.
func New(ctx context.Context, db database.Database, config Config) (*merkleDB, error) {
func New(ctx context.Context, db database.Database, config Config) (MerkleDB, error) {
metrics, err := newMetrics("merkleDB", config.Reg)
if err != nil {
return nil, err
Expand Down
11 changes: 10 additions & 1 deletion x/merkledb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ import (

const defaultHistoryLength = 300

// newDB returns a new merkle database with the underlying type so that tests can access unexported fields
func newDB(ctx context.Context, db database.Database, config Config) (*merkleDB, error) {
db, err := New(ctx, db, config)
if err != nil {
return nil, err
}
return db.(*merkleDB), nil
}

func newNoopTracer() trace.Tracer {
tracer, _ := trace.New(trace.Config{Enabled: false})
return tracer
Expand Down Expand Up @@ -148,7 +157,7 @@ func Test_MerkleDB_DB_Rebuild(t *testing.T) {
config := newDefaultConfig()
config.NodeCacheSize = initialSize

db, err := New(
db, err := newDB(
context.Background(),
rdb,
config,
Expand Down
22 changes: 11 additions & 11 deletions x/merkledb/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func Test_History_Simple(t *testing.T) {
require := require.New(t)

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
newDefaultConfig(),
Expand Down Expand Up @@ -148,7 +148,7 @@ func Test_History_Bad_GetValueChanges_Input(t *testing.T) {
config := newDefaultConfig()
config.HistoryLength = 5

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
config,
Expand Down Expand Up @@ -215,7 +215,7 @@ func Test_History_Trigger_History_Queue_Looping(t *testing.T) {
config := newDefaultConfig()
config.HistoryLength = 2

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
config,
Expand Down Expand Up @@ -269,7 +269,7 @@ func Test_History_Values_Lookup_Over_Queue_Break(t *testing.T) {

config := newDefaultConfig()
config.HistoryLength = 4
db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
config,
Expand Down Expand Up @@ -317,7 +317,7 @@ func Test_History_Values_Lookup_Over_Queue_Break(t *testing.T) {
func Test_History_RepeatedRoot(t *testing.T) {
require := require.New(t)

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
newDefaultConfig(),
Expand Down Expand Up @@ -361,7 +361,7 @@ func Test_History_RepeatedRoot(t *testing.T) {
func Test_History_ExcessDeletes(t *testing.T) {
require := require.New(t)

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
newDefaultConfig(),
Expand Down Expand Up @@ -393,7 +393,7 @@ func Test_History_ExcessDeletes(t *testing.T) {
func Test_History_DontIncludeAllNodes(t *testing.T) {
require := require.New(t)

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
newDefaultConfig(),
Expand Down Expand Up @@ -421,7 +421,7 @@ func Test_History_DontIncludeAllNodes(t *testing.T) {
func Test_History_Branching2Nodes(t *testing.T) {
require := require.New(t)

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
newDefaultConfig(),
Expand Down Expand Up @@ -449,7 +449,7 @@ func Test_History_Branching2Nodes(t *testing.T) {
func Test_History_Branching3Nodes(t *testing.T) {
require := require.New(t)

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
newDefaultConfig(),
Expand Down Expand Up @@ -479,7 +479,7 @@ func Test_History_MaxLength(t *testing.T) {

config := newDefaultConfig()
config.HistoryLength = 2
db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
config,
Expand Down Expand Up @@ -509,7 +509,7 @@ func Test_History_MaxLength(t *testing.T) {
func Test_Change_List(t *testing.T) {
require := require.New(t)

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
newDefaultConfig(),
Expand Down
2 changes: 1 addition & 1 deletion x/merkledb/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Test_Metrics_Basic_Usage(t *testing.T) {
// merkledb.
config.Reg = nil

db, err := New(
db, err := newDB(
context.Background(),
memdb.New(),
config,
Expand Down

0 comments on commit a37bb0a

Please sign in to comment.