-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #544 from livepeer/et/unbonding-fix
Exit early when processing historic events
- Loading branch information
Showing
5 changed files
with
101 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package common | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func dbPath(t *testing.T) string { | ||
return fmt.Sprintf("file:%s?mode=memory&cache=shared&_foreign_keys=1", t.Name()) | ||
} | ||
|
||
func TempDB(t *testing.T) (*DB, *sql.DB, error) { | ||
dbpath := dbPath(t) | ||
dbh, err := InitDB(dbpath) | ||
if err != nil { | ||
t.Error("Unable to initialize DB ", err) | ||
return nil, nil, err | ||
} | ||
raw, err := sql.Open("sqlite3", dbpath) | ||
if err != nil { | ||
t.Error("Unable to open raw sqlite db ", err) | ||
return nil, nil, err | ||
} | ||
return dbh, raw, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package eventservices | ||
|
||
import ( | ||
"errors" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/livepeer/go-livepeer/common" | ||
"github.com/livepeer/go-livepeer/eth" | ||
) | ||
|
||
func TestProcessHistoricalEvents(t *testing.T) { | ||
dbh, dbraw, err := common.TempDB(t) | ||
if err != nil { | ||
return | ||
} | ||
defer dbh.Close() | ||
defer dbraw.Close() | ||
|
||
c := ð.StubClient{} | ||
//Set the eth client to be nil | ||
s := NewUnbondingService(c, dbh) | ||
|
||
//Test that we exit early because LastSeenBlock is 0 in this case | ||
dbh.SetLastSeenBlock(big.NewInt(0)) | ||
if err := s.processHistoricalEvents(); err != nil { | ||
t.Errorf("Error: %v", err) | ||
} | ||
|
||
//Set last seen block to be 10, this should result in an error because we don't exit early anymore and we set a stubbed error | ||
dbh.SetLastSeenBlock(big.NewInt(10)) | ||
c.ProcessHistoricalUnbondError = errors.New("StubError") | ||
if err := s.processHistoricalEvents(); err.Error() != "StubError" { | ||
t.Errorf("Expecting stub error, but got none") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters