2022-01-11 00:59:15 +00:00
|
|
|
package snapshot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ethNode "github.com/ethereum/go-ethereum/statediff/indexer/node"
|
|
|
|
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig(leveldbpath, ancientdbpath string) *Config {
|
2022-01-11 05:37:27 +00:00
|
|
|
dbParams := postgres.ConnectionParams{
|
|
|
|
Name: "snapshot_test",
|
|
|
|
Hostname: "localhost",
|
|
|
|
Port: 5432,
|
|
|
|
User: "tester",
|
|
|
|
Password: "test_pw",
|
|
|
|
}
|
2022-01-11 00:59:26 +00:00
|
|
|
connconfig := postgres.ConnectionConfig{
|
2022-01-11 00:59:15 +00:00
|
|
|
MaxIdle: 0,
|
|
|
|
MaxLifetime: 0,
|
|
|
|
MaxOpen: 4,
|
|
|
|
}
|
|
|
|
nodeinfo := ethNode.Info{
|
|
|
|
ID: "eth_node_id",
|
|
|
|
ClientName: "eth_client",
|
|
|
|
GenesisBlock: "X",
|
|
|
|
NetworkID: "eth_network",
|
|
|
|
ChainID: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Config{
|
2022-01-11 00:59:26 +00:00
|
|
|
DB: &DBConfig{
|
|
|
|
Node: nodeinfo,
|
2022-01-11 05:37:27 +00:00
|
|
|
URI: postgres.DbConnectionString(dbParams),
|
2022-01-11 00:59:26 +00:00
|
|
|
ConnConfig: connconfig,
|
|
|
|
},
|
|
|
|
Eth: &EthConfig{
|
|
|
|
LevelDBPath: leveldbpath,
|
|
|
|
AncientDBPath: ancientdbpath,
|
|
|
|
},
|
2022-01-11 00:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 00:59:26 +00:00
|
|
|
func NewMockPublisher() *Publisher {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-11 00:59:15 +00:00
|
|
|
func TestCreateSnapshot(t *testing.T) {
|
|
|
|
datadir := t.TempDir()
|
|
|
|
config := testConfig(
|
|
|
|
filepath.Join(datadir, "leveldb"),
|
|
|
|
filepath.Join(datadir, "ancient"),
|
|
|
|
)
|
|
|
|
|
2022-01-11 00:59:26 +00:00
|
|
|
pub := NewMockPublisher()
|
|
|
|
service, err := NewSnapshotService(config.Eth, pub)
|
2022-01-11 00:59:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
params := SnapshotParams{Height: 1}
|
|
|
|
err = service.CreateSnapshot(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// err = service.CreateLatestSnapshot(0)
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
|
|
|
}
|