erigon-pulse/migrations/receipts_test.go
Alex Sharov 44bbe97a1f
Migration idempotency: handle corner-cases of CriticalCollector (#1257)
* save progress of db migration

* save progress of db migration

* delete

* delete

* delete

* delete

* delete

* print full key if it has 8 leading zeroes

* print full key if it has 8 leading zeroes

* print full key if it has 8 leading zeroes
2020-10-19 20:20:18 +01:00

36 lines
949 B
Go

package migrations
import (
"context"
"errors"
"testing"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/stretchr/testify/require"
)
func TestReceiptCbor(t *testing.T) {
require, db := require.New(t), ethdb.NewMemDatabase()
err := db.KV().Update(context.Background(), func(tx ethdb.Tx) error {
return tx.(ethdb.BucketMigrator).CreateBucket(dbutils.BlockReceiptsPrefix)
})
require.NoError(err)
migrator := NewMigrator()
migrator.Migrations = []Migration{receiptsCborEncode}
err = migrator.Apply(db, "")
require.NoError(err)
err = receiptsCborEncode.Up(db, "tmp-test-dir", nil, func(db ethdb.Putter, key []byte, isDone bool) error {
return nil
})
require.NoError(err)
err = receiptsCborEncode.Up(db, "tmp-test-dir", []byte("load"), func(db ethdb.Putter, key []byte, isDone bool) error {
return nil
})
require.True(errors.Is(err, ErrMigrationETLFilesDeleted))
}