refactor v1 pkg to work with new dep paths

This commit is contained in:
i-norden 2023-02-20 12:22:17 -06:00
parent 844cda1107
commit 5451c3c225
3 changed files with 10 additions and 21 deletions

View File

@ -20,6 +20,8 @@ import (
"math/big" "math/big"
"time" "time"
"github.com/cerc-io/ipfs-ethdb/v4/postgres/shared"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -27,7 +29,7 @@ import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
pgipfsethdb "github.com/cerc-io/ipfs-ethdb/v4/postgres" pgipfsethdb "github.com/cerc-io/ipfs-ethdb/v4/postgres/v1"
) )
var ( var (
@ -39,7 +41,7 @@ var (
var _ = Describe("Batch", func() { var _ = Describe("Batch", func() {
BeforeEach(func() { BeforeEach(func() {
db, err = pgipfsethdb.TestDB() db, err = shared.TestDB()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
cacheConfig := pgipfsethdb.CacheConfig{ cacheConfig := pgipfsethdb.CacheConfig{
@ -58,7 +60,7 @@ var _ = Describe("Batch", func() {
}) })
AfterEach(func() { AfterEach(func() {
groupcache.DeregisterGroup("db") groupcache.DeregisterGroup("db")
err = pgipfsethdb.ResetTestDB(db) err = shared.ResetTestDB(db)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}) })

View File

@ -20,6 +20,8 @@ import (
"math/big" "math/big"
"time" "time"
"github.com/cerc-io/ipfs-ethdb/v4/postgres/shared"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -28,7 +30,7 @@ import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
pgipfsethdb "github.com/cerc-io/ipfs-ethdb/v4/postgres" pgipfsethdb "github.com/cerc-io/ipfs-ethdb/v4/postgres/v1"
) )
var ( var (
@ -44,7 +46,7 @@ var (
var _ = Describe("Database", func() { var _ = Describe("Database", func() {
BeforeEach(func() { BeforeEach(func() {
db, err = pgipfsethdb.TestDB() db, err = shared.TestDB()
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
cacheConfig := pgipfsethdb.CacheConfig{ cacheConfig := pgipfsethdb.CacheConfig{
@ -61,7 +63,7 @@ var _ = Describe("Database", func() {
}) })
AfterEach(func() { AfterEach(func() {
groupcache.DeregisterGroup("db") groupcache.DeregisterGroup("db")
err = pgipfsethdb.ResetTestDB(db) err = shared.ResetTestDB(db)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}) })

View File

@ -19,7 +19,6 @@ package pgipfsethdb
import ( import (
blockstore "github.com/ipfs/go-ipfs-blockstore" blockstore "github.com/ipfs/go-ipfs-blockstore"
dshelp "github.com/ipfs/go-ipfs-ds-help" dshelp "github.com/ipfs/go-ipfs-ds-help"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq" //postgres driver _ "github.com/lib/pq" //postgres driver
"github.com/multiformats/go-multihash" "github.com/multiformats/go-multihash"
) )
@ -33,17 +32,3 @@ func MultihashKeyFromKeccak256(h []byte) (string, error) {
dbKey := dshelp.MultihashToDsKey(mh) dbKey := dshelp.MultihashToDsKey(mh)
return blockstore.BlockPrefix.String() + dbKey.String(), nil return blockstore.BlockPrefix.String() + dbKey.String(), nil
} }
// TestDB connect to the testing database
// it assumes the database has the IPFS public.blocks table present
// DO NOT use a production db for the test db, as it will remove all contents of the public.blocks table
func TestDB() (*sqlx.DB, error) {
connectStr := "postgresql://localhost:5432/vulcanize_testing?sslmode=disable"
return sqlx.Connect("postgres", connectStr)
}
// ResetTestDB drops all rows in the test db public.blocks table
func ResetTestDB(db *sqlx.DB) error {
_, err := db.Exec("TRUNCATE public.blocks CASCADE")
return err
}