2022-02-09 15:19:10 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2022-02-18 11:12:53 +00:00
|
|
|
"bytes"
|
2022-02-09 15:19:10 +00:00
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
|
|
|
|
ethnode "github.com/ethereum/go-ethereum/statediff/indexer/node"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultNodeInfo = ethnode.Info{
|
|
|
|
ID: "test_nodeid",
|
|
|
|
ClientName: "test_client",
|
|
|
|
GenesisBlock: "TEST_GENESIS",
|
|
|
|
NetworkID: "test_network",
|
|
|
|
ChainID: 0,
|
|
|
|
}
|
|
|
|
DefaultPgConfig = postgres.Config{
|
|
|
|
Hostname: "localhost",
|
2022-06-15 07:21:26 +00:00
|
|
|
Port: 8077,
|
2023-05-12 15:07:12 +00:00
|
|
|
DatabaseName: "cerc_testing",
|
2022-06-15 07:21:26 +00:00
|
|
|
Username: "vdbm",
|
|
|
|
Password: "password",
|
2022-02-09 15:19:10 +00:00
|
|
|
|
|
|
|
MaxIdle: 0,
|
|
|
|
MaxConnLifetime: 0,
|
|
|
|
MaxConns: 4,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func NeedsDB(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
if os.Getenv("TEST_WITH_DB") == "" {
|
|
|
|
t.Skip("set TEST_WITH_DB to enable test")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NoError(t *testing.T, err error) {
|
|
|
|
t.Helper()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExpectEqual asserts the provided interfaces are deep equal
|
2022-02-18 11:12:53 +00:00
|
|
|
func ExpectEqual(t *testing.T, want, got interface{}) {
|
2022-02-09 15:19:10 +00:00
|
|
|
if !reflect.DeepEqual(want, got) {
|
2023-05-12 15:07:12 +00:00
|
|
|
t.Fatalf("Values not equal:\nExpected:\t%+v\nActual:\t\t%+v", want, got)
|
2022-02-18 11:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExpectEqualBytes(t *testing.T, want, got []byte) {
|
|
|
|
if !bytes.Equal(want, got) {
|
|
|
|
t.Fatalf("Bytes not equal:\nExpected:\t%v\nActual:\t\t%v", want, got)
|
2022-02-09 15:19:10 +00:00
|
|
|
}
|
|
|
|
}
|