mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 17:44:29 +00:00
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
|
package migrations
|
||
|
|
||
|
import (
|
||
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
||
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestApplyWithInit(t *testing.T) {
|
||
|
db := ethdb.NewMemDatabase()
|
||
|
migrations = []Migration{
|
||
|
{
|
||
|
"one",
|
||
|
func(db ethdb.Database, history, receipts, txIndex, preImages, thinHistory bool) error {
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
"two",
|
||
|
func(db ethdb.Database, history, receipts, txIndex, preImages, thinHistory bool) error {
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
migrator := NewMigrator()
|
||
|
migrator.Migrations = migrations
|
||
|
err := migrator.Apply(db, false, false, false, false, false)
|
||
|
if err != nil {
|
||
|
t.Fatal()
|
||
|
}
|
||
|
v, err := db.Get(dbutils.DatabaseInfoBucket, dbutils.LastAppliedMigration)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if string(v) != migrations[1].Name {
|
||
|
t.Fatal()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestApplyWithoutInit(t *testing.T) {
|
||
|
db := ethdb.NewMemDatabase()
|
||
|
migrations = []Migration{
|
||
|
{
|
||
|
"one",
|
||
|
func(db ethdb.Database, history, receipts, txIndex, preImages, thinHistory bool) error {
|
||
|
t.Fatal("shouldn't been executed")
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
"two",
|
||
|
func(db ethdb.Database, history, receipts, txIndex, preImages, thinHistory bool) error {
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
err := db.Put(dbutils.DatabaseInfoBucket, dbutils.LastAppliedMigration, []byte(migrations[0].Name))
|
||
|
if err != nil {
|
||
|
t.Fatal()
|
||
|
}
|
||
|
|
||
|
migrator := NewMigrator()
|
||
|
migrator.Migrations = migrations
|
||
|
err = migrator.Apply(db, false, false, false, false, false)
|
||
|
if err != nil {
|
||
|
t.Fatal()
|
||
|
}
|
||
|
v, err := db.Get(dbutils.DatabaseInfoBucket, dbutils.LastAppliedMigration)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if string(v) != migrations[1].Name {
|
||
|
t.Fatal()
|
||
|
}
|
||
|
}
|