You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1002 B

  1. package test
  2. import (
  3. "testing"
  4. dbUtils "github.com/hermeznetwork/hermez-node/db"
  5. "github.com/jmoiron/sqlx"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. // AssertUSD asserts pointers to float64, and checks that they are equal
  9. // with a tolerance of 0.01%. After that, the actual value is setted to the expected value
  10. // in order to be able to perform further assertions using the standar assert functions.
  11. func AssertUSD(t *testing.T, expected, actual *float64) {
  12. if actual == nil {
  13. assert.Equal(t, expected, actual)
  14. return
  15. }
  16. if *expected < *actual {
  17. assert.InEpsilon(t, *actual, *expected, 0.0001)
  18. } else if *expected > *actual {
  19. assert.InEpsilon(t, *expected, *actual, 0.0001)
  20. }
  21. *expected = *actual
  22. }
  23. // WipeDB redo all the migrations of the SQL DB (HistoryDB and L2DB),
  24. // efectively recreating the original state
  25. func WipeDB(db *sqlx.DB) {
  26. if err := dbUtils.MigrationsDown(db.DB); err != nil {
  27. panic(err)
  28. }
  29. if err := dbUtils.MigrationsUp(db.DB); err != nil {
  30. panic(err)
  31. }
  32. }