use stock v1.11.5 geth; use new cerc test db info
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
connectStr := "postgresql://localhost:5432/vulcanize_testing?sslmode=disable"
|
||||
connectStr := "postgresql://vdbm:password@localhost:8077/cerc_testing?sslmode=disable"
|
||||
db, _ := sqlx.Connect("postgres", connectStr)
|
||||
|
||||
kvs := pgipfsethdb.NewKeyValueStore(db)
|
||||
|
||||
+13
-5
@@ -18,16 +18,24 @@ package shared
|
||||
|
||||
import "github.com/jmoiron/sqlx"
|
||||
|
||||
/*
|
||||
Hostname: "localhost",
|
||||
Port: 8077,
|
||||
DatabaseName: "cerc_testing",
|
||||
Username: "vdbm",
|
||||
Password: "password",
|
||||
*/
|
||||
|
||||
// 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
|
||||
// it assumes the database has the IPFS ipld.blocks table present
|
||||
// DO NOT use a production db for the test db, as it will remove all contents of the ipld.blocks table
|
||||
func TestDB() (*sqlx.DB, error) {
|
||||
connectStr := "postgresql://localhost:5432/vulcanize_testing?sslmode=disable"
|
||||
connectStr := "postgresql://vdbm:password@localhost:8077/cerc_testing?sslmode=disable"
|
||||
return sqlx.Connect("postgres", connectStr)
|
||||
}
|
||||
|
||||
// ResetTestDB drops all rows in the test db public.blocks table
|
||||
// ResetTestDB drops all rows in the test db ipld.blocks table
|
||||
func ResetTestDB(db *sqlx.DB) error {
|
||||
_, err := db.Exec("TRUNCATE public.blocks CASCADE")
|
||||
_, err := db.Exec("TRUNCATE ipld.blocks CASCADE")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func NewBatch(db *sqlx.DB, tx *sqlx.Tx, blockNumber *big.Int) ethdb.Batch {
|
||||
// Put satisfies the ethdb.Batch interface
|
||||
// Put inserts the given value into the key-value data store
|
||||
// Key is expected to be a fully formulated cid key
|
||||
// TODO: note, now that we expected a cid we could route to the "cids" tables based on prefix instead of to public.blocks
|
||||
// TODO: note, now that we expected a cid we could route to the "cids" tables based on prefix instead of to ipld.blocks
|
||||
// but is it better to handle this routing here, or use a completely different interface since we already have to refactor
|
||||
// at levels above this package in order to pass in cids instead of raw keccak256 hashes
|
||||
func (b *Batch) Put(cidBytes []byte, value []byte) (err error) {
|
||||
|
||||
@@ -37,10 +37,10 @@ import (
|
||||
var errNotSupported = errors.New("this operation is not supported")
|
||||
|
||||
var (
|
||||
hasPgStr = "SELECT exists(select 1 from public.blocks WHERE key = $1 LIMIT 1)"
|
||||
getPgStr = "SELECT data FROM public.blocks WHERE key = $1 LIMIT 1"
|
||||
putPgStr = "INSERT INTO public.blocks (key, data, block_number) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
||||
deletePgStr = "DELETE FROM public.blocks WHERE key = $1"
|
||||
hasPgStr = "SELECT exists(select 1 from ipld.blocks WHERE key = $1 LIMIT 1)"
|
||||
getPgStr = "SELECT data FROM ipld.blocks WHERE key = $1 LIMIT 1"
|
||||
putPgStr = "INSERT INTO ipld.blocks (key, data, block_number) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
||||
deletePgStr = "DELETE FROM ipld.blocks WHERE key = $1"
|
||||
dbSizePgStr = "SELECT pg_database_size(current_database())"
|
||||
)
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ var _ = Describe("Database", func() {
|
||||
groupcache.DeregisterGroup("db")
|
||||
err = shared.ResetTestDB(db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = db.Close()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Describe("Has", func() {
|
||||
@@ -76,7 +78,7 @@ var _ = Describe("Database", func() {
|
||||
Expect(has).ToNot(BeTrue())
|
||||
})
|
||||
It("returns true if a key-pair exists in the db", func() {
|
||||
_, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, $3)", testCID.String(), testValue, testBlockNumber.Uint64())
|
||||
_, err = db.Exec("INSERT into ipld.blocks (key, data, block_number) VALUES ($1, $2, $3)", testCID.String(), testValue, testBlockNumber.Uint64())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
has, err := database.Has(testCID.Bytes())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -91,7 +93,7 @@ var _ = Describe("Database", func() {
|
||||
Expect(err.Error()).To(ContainSubstring("sql: no rows in result set"))
|
||||
})
|
||||
It("returns the value associated with the key, if the pair exists", func() {
|
||||
_, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, $3)", testCID.String(), testValue, testBlockNumber.Uint64())
|
||||
_, err = db.Exec("INSERT into ipld.blocks (key, data, block_number) VALUES ($1, $2, $3)", testCID.String(), testValue, testBlockNumber.Uint64())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
val, err := database.Get(testCID.Bytes())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -35,10 +35,10 @@ import (
|
||||
var errNotSupported = errors.New("this operation is not supported")
|
||||
|
||||
var (
|
||||
hasPgStr = "SELECT exists(select 1 from public.blocks WHERE key = $1 LIMIT 1)"
|
||||
getPgStr = "SELECT data FROM public.blocks WHERE key = $1 LIMIT 1"
|
||||
putPgStr = "INSERT INTO public.blocks (key, data, block_number) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
||||
deletePgStr = "DELETE FROM public.blocks WHERE key = $1"
|
||||
hasPgStr = "SELECT exists(select 1 from ipld.blocks WHERE key = $1 LIMIT 1)"
|
||||
getPgStr = "SELECT data FROM ipld.blocks WHERE key = $1 LIMIT 1"
|
||||
putPgStr = "INSERT INTO ipld.blocks (key, data, block_number) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
||||
deletePgStr = "DELETE FROM ipld.blocks WHERE key = $1"
|
||||
dbSizePgStr = "SELECT pg_database_size(current_database())"
|
||||
)
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ var _ = Describe("Database", func() {
|
||||
groupcache.DeregisterGroup("db")
|
||||
err = shared.ResetTestDB(db)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = db.Close()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Describe("Has", func() {
|
||||
@@ -74,7 +76,7 @@ var _ = Describe("Database", func() {
|
||||
Expect(has).ToNot(BeTrue())
|
||||
})
|
||||
It("returns true if a key-pair exists in the db", func() {
|
||||
_, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, $3)", testMhKey, testValue, testBlockNumber.Uint64())
|
||||
_, err = db.Exec("INSERT into ipld.blocks (key, data, block_number) VALUES ($1, $2, $3)", testMhKey, testValue, testBlockNumber.Uint64())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
has, err := database.Has(testEthKey)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -89,7 +91,7 @@ var _ = Describe("Database", func() {
|
||||
Expect(err.Error()).To(ContainSubstring("sql: no rows in result set"))
|
||||
})
|
||||
It("returns the value associated with the key, if the pair exists", func() {
|
||||
_, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, $3)", testMhKey, testValue, testBlockNumber.Uint64())
|
||||
_, err = db.Exec("INSERT into ipld.blocks (key, data, block_number) VALUES ($1, $2, $3)", testMhKey, testValue, testBlockNumber.Uint64())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
val, err := database.Get(testEthKey)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Reference in New Issue
Block a user