Files
hermez-node/test/dbUtils.go
Eduard S e5fc403451 Add cli command to wipe the SQL DB
- Refactor the migrations code so that packr is only called (via an init
  function in `db/utils.go`).
- When loading the migrations, make sure there is at least one migration,
  otherwise panic (this would happen if the node is built incorrectly)
2020-12-31 10:34:32 +01:00

37 lines
1002 B
Go

package test
import (
"testing"
dbUtils "github.com/hermeznetwork/hermez-node/db"
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert"
)
// AssertUSD asserts pointers to float64, and checks that they are equal
// with a tolerance of 0.01%. After that, the actual value is setted to the expected value
// in order to be able to perform further assertions using the standar assert functions.
func AssertUSD(t *testing.T, expected, actual *float64) {
if actual == nil {
assert.Equal(t, expected, actual)
return
}
if *expected < *actual {
assert.InEpsilon(t, *actual, *expected, 0.0001)
} else if *expected > *actual {
assert.InEpsilon(t, *expected, *actual, 0.0001)
}
*expected = *actual
}
// WipeDB redo all the migrations of the SQL DB (HistoryDB and L2DB),
// efectively recreating the original state
func WipeDB(db *sqlx.DB) {
if err := dbUtils.MigrationsDown(db.DB); err != nil {
panic(err)
}
if err := dbUtils.MigrationsUp(db.DB); err != nil {
panic(err)
}
}