Skip to content

Commit

Permalink
Test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Sep 17, 2024
1 parent 4f9813c commit 9506551
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
10 changes: 6 additions & 4 deletions internal/eigenState/avsOperators/avsOperators.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,12 @@ func (a *AvsOperatorsModel) writeDeltaRecordsToDeltaTable(blockNumber uint64) er
return errors.New(msg)
}

res := a.DB.Model(&AvsOperatorStateChange{}).Clauses(clause.Returning{}).Create(&records)
if res.Error != nil {
a.logger.Sugar().Errorw("Failed to insert delta records", zap.Error(res.Error))
return res.Error
if len(records) > 0 {
res := a.DB.Model(&AvsOperatorStateChange{}).Clauses(clause.Returning{}).Create(&records)
if res.Error != nil {
a.logger.Sugar().Errorw("Failed to insert delta records", zap.Error(res.Error))
return res.Error
}
}
return nil
}
Expand Down
16 changes: 11 additions & 5 deletions internal/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ func bytesToHex(jsonByteArray string) (string, error) {
return hex.EncodeToString(jsonBytes), nil
}

var hasRegisteredExtensions = false

func NewSqlite(path string) gorm.Dialector {
sql.Register("sqlite3_with_extensions", &goSqlite.SQLiteDriver{
ConnectHook: func(conn *goSqlite.SQLiteConn) error {
return conn.RegisterFunc("bytes_to_hex", bytesToHex, true)
},
})
if !hasRegisteredExtensions {
sql.Register("sqlite3_with_extensions", &goSqlite.SQLiteDriver{
ConnectHook: func(conn *goSqlite.SQLiteConn) error {
return conn.RegisterFunc("bytes_to_hex", bytesToHex, true)
},
})
hasRegisteredExtensions = true
}

return &sqlite.Dialector{
DriverName: "sqlite3_with_extensions",
DSN: path,
Expand Down
20 changes: 15 additions & 5 deletions pkg/rewards/operatorAvsRegistrationWindows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"testing"
)

func setup() (
func setupOperatorAvsRegistrationSnapshot() (
*config.Config,
*gorm.DB,
*zap.Logger,
Expand All @@ -37,8 +37,16 @@ func setup() (
return cfg, db, l, err
}

func teardown() {

func teardownOperatorAvsRegistrationSnapshot(grm *gorm.DB) {
queries := []string{
`delete from avs_operator_state_changes`,
`delete from blocks`,
}
for _, query := range queries {
if res := grm.Exec(query); res.Error != nil {
fmt.Printf("Failed to run query: %v\n", res.Error)
}
}
}

func hydrateOperatorAvsStateChangesTable(grm *gorm.DB, l *zap.Logger) (int, error) {
Expand Down Expand Up @@ -81,7 +89,7 @@ func hydrateBlocksTable(grm *gorm.DB, l *zap.Logger) (int, error) {
}

func Test_OperatorAvsRegistrationWindows(t *testing.T) {
cfg, grm, l, err := setup()
cfg, grm, l, err := setupOperatorAvsRegistrationSnapshot()

if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -160,6 +168,8 @@ func Test_OperatorAvsRegistrationWindows(t *testing.T) {
fmt.Printf("%d - Window: %+v\n", i, window)
}
}

})
t.Cleanup(func() {
teardownOperatorAvsRegistrationSnapshot(grm)
})
}

0 comments on commit 9506551

Please sign in to comment.