Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merkle db fix new return type #1898

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading