From 802a5908df9f917cf08f5517f14732140476bec8 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Mon, 10 Jan 2022 18:59:15 -0600 Subject: [PATCH] set up test --- go.mod | 1 + pkg/snapshot/service_test.go | 63 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 pkg/snapshot/service_test.go diff --git a/go.mod b/go.mod index b8a12e4..11a05b4 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/smartystreets/assertions v1.0.0 // indirect github.com/spf13/cobra v1.0.0 github.com/spf13/viper v1.7.0 + github.com/vulcanize/go-eth-state-node-iterator v0.0.1-alpha go.uber.org/atomic v1.9.0 // indirect go.uber.org/goleak v1.1.11 // indirect go.uber.org/multierr v1.7.0 // indirect diff --git a/pkg/snapshot/service_test.go b/pkg/snapshot/service_test.go new file mode 100644 index 0000000..b3e339f --- /dev/null +++ b/pkg/snapshot/service_test.go @@ -0,0 +1,63 @@ +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 { + dbParams := postgres.ConnectionParams{} + dbParams.Name = "snapshot_test" + dbParams.Hostname = "localhost" + dbParams.Port = 5432 + dbParams.User = "tester" + dbParams.Password = "test_pw" + uri := postgres.DbConnectionString(dbParams) + dbconfig := postgres.ConnectionConfig{ + 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{ + LevelDBPath: leveldbpath, + AncientDBPath: ancientdbpath, + Node: nodeinfo, + connectionURI: uri, + DBConfig: dbconfig, + } +} + +func TestCreateSnapshot(t *testing.T) { + datadir := t.TempDir() + config := testConfig( + filepath.Join(datadir, "leveldb"), + filepath.Join(datadir, "ancient"), + ) + + service, err := NewSnapshotService(config) + 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) + // } +}