update tests

This commit is contained in:
Roy Crihfield 2024-04-23 18:25:17 +08:00
parent 191cd5d136
commit 9593c7bde0
4 changed files with 24 additions and 12 deletions

View File

@ -7,7 +7,6 @@ import (
"testing" "testing"
helpers "github.com/cerc-io/plugeth-statediff/test_helpers" helpers "github.com/cerc-io/plugeth-statediff/test_helpers"
"github.com/cerc-io/plugeth-statediff/test_helpers/chaingen"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
@ -16,6 +15,7 @@ import (
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/cerc-io/ipld-eth-db-validator/v5/internal/chaingen"
"github.com/cerc-io/ipld-eth-db-validator/v5/pkg/validator" "github.com/cerc-io/ipld-eth-db-validator/v5/pkg/validator"
) )
@ -55,7 +55,7 @@ var _ = Describe("referential integrity", Ordered, func() {
}) })
blocks, receipts, chain = gen.MakeChain(5) blocks, receipts, chain = gen.MakeChain(5)
indexer, err := helpers.TestStateDiffIndexer(context.Background(), chainConfig, gen.Genesis.Hash()) indexer, err := helpers.NewIndexer(context.Background(), chainConfig, gen.Genesis.Hash(), TestDBConfig)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
helpers.IndexChain(indexer, helpers.IndexChainParams{ helpers.IndexChain(indexer, helpers.IndexChainParams{
StateCache: chain.StateCache(), StateCache: chain.StateCache(),
@ -65,9 +65,9 @@ var _ = Describe("referential integrity", Ordered, func() {
}) })
checkedBlock = blocks[5] checkedBlock = blocks[5]
db = helpers.SetupDB() db = SetupDB()
}) })
AfterAll(func() { helpers.TearDownDB(db) }) AfterAll(func() { helpers.ClearDB(db) })
BeforeEach(func() { tx = db.MustBegin() }) BeforeEach(func() { tx = db.MustBegin() })
AfterEach(func() { AfterEach(func() {

View File

@ -1,9 +1,12 @@
package validator_test package validator_test
import ( import (
"context"
"math/big" "math/big"
"github.com/cerc-io/plugeth-statediff/indexer/database/sql/postgres"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/jmoiron/sqlx"
) )
var TestChainConfig = &params.ChainConfig{ var TestChainConfig = &params.ChainConfig{
@ -23,3 +26,13 @@ var TestChainConfig = &params.ChainConfig{
GrayGlacierBlock: big.NewInt(0), GrayGlacierBlock: big.NewInt(0),
Ethash: new(params.EthashConfig), Ethash: new(params.EthashConfig),
} }
var TestDBConfig, _ = postgres.TestConfig.WithEnv()
func SetupDB() *sqlx.DB {
db, err := postgres.ConnectSQLX(context.Background(), TestDBConfig)
if err != nil {
panic(err)
}
return db
}

View File

@ -7,7 +7,6 @@ import (
"github.com/cerc-io/plugeth-statediff/indexer/ipld" "github.com/cerc-io/plugeth-statediff/indexer/ipld"
helpers "github.com/cerc-io/plugeth-statediff/test_helpers" helpers "github.com/cerc-io/plugeth-statediff/test_helpers"
"github.com/cerc-io/plugeth-statediff/test_helpers/chaingen"
sdtypes "github.com/cerc-io/plugeth-statediff/types" sdtypes "github.com/cerc-io/plugeth-statediff/types"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -16,6 +15,7 @@ import (
// import server helpers for non-canonical chain data // import server helpers for non-canonical chain data
server_mocks "github.com/cerc-io/ipld-eth-server/v5/pkg/eth/test_helpers" server_mocks "github.com/cerc-io/ipld-eth-server/v5/pkg/eth/test_helpers"
"github.com/cerc-io/ipld-eth-db-validator/v5/internal/chaingen"
"github.com/cerc-io/ipld-eth-db-validator/v5/pkg/validator" "github.com/cerc-io/ipld-eth-db-validator/v5/pkg/validator"
) )
@ -32,7 +32,7 @@ var (
func init() { func init() {
// The geth sync logs are noisy, silence them // The geth sync logs are noisy, silence them
log.Root().SetHandler(log.DiscardHandler()) log.SetDefault(log.NewLogger(log.DiscardHandler()))
} }
func setupStateValidator(t *testing.T) *sqlx.DB { func setupStateValidator(t *testing.T) *sqlx.DB {
@ -44,7 +44,7 @@ func setupStateValidator(t *testing.T) *sqlx.DB {
chain.Stop() chain.Stop()
}) })
indexer, err := helpers.TestStateDiffIndexer(context.Background(), chainConfig, gen.Genesis.Hash()) indexer, err := helpers.NewIndexer(context.Background(), chainConfig, gen.Genesis.Hash(), TestDBConfig)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -96,10 +96,9 @@ func setupStateValidator(t *testing.T) *sqlx.DB {
t.Fatal(err) t.Fatal(err)
} }
db := helpers.SetupDB() db := SetupDB()
t.Cleanup(func() { t.Cleanup(func() {
helpers.TearDownDB(db) helpers.ClearDB(db)
}) })
return db return db
} }
@ -119,7 +118,7 @@ func TestStateValidation(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if blockToBeValidated == nil { if blockToBeValidated == nil {
t.Fatal("blockToBeValidated is nil") t.Fatal("block was not found")
} }
err = validator.ValidateBlock(blockToBeValidated, api.B, i) err = validator.ValidateBlock(blockToBeValidated, api.B, i)

View File

@ -5,7 +5,7 @@ services:
restart: on-failure restart: on-failure
depends_on: depends_on:
- ipld-eth-db - ipld-eth-db
image: git.vdb.to/cerc-io/ipld-eth-db/ipld-eth-db:v5.0.5-alpha image: git.vdb.to/cerc-io/ipld-eth-db/ipld-eth-db:v5.2.1-alpha
environment: environment:
DATABASE_USER: "vdbm" DATABASE_USER: "vdbm"
DATABASE_NAME: "cerc_testing" DATABASE_NAME: "cerc_testing"